answersLogoWhite

0


Best Answer

#include<iostream>

#include<sstream>

unsigned input_num (std::string prompt, unsigned min, unsigned max)

{

unsigned num = 0;

while (1)

{

std::cout << prompt << " (range " << min << " - " << max << "): ";

std::string input = "";

std::getline (std::cin, input);

std::stringstream ss (input);

if (ss >> num)

{

if (num >= min && num <= max)

break;

else if (num<min)

std::cout << "Index must be greater than or equal to " << min << std::endl;

else

std::cout << "Index must be less than or equal to " << max << std::endl;

}

else

std::cout << "Invalid input." << std::endl;

}

return (num);

}

void print_substring (std::string input, unsigned left, unsigned right)

{

std::cout << input.substr (left, right - left + 1) << std::endl;

}

int main()

{

std::cout << "Input string:\t";

std::string input = "";

std::getline (std::cin, input);

unsigned left = input_num ("Enter the start index of the substring", 0, input.size()-1);

unsigned right = input_num ("Enter the end index of the substring", left+1, input.size()-1);

print_substring (input, left, right);

}

User Avatar

Wiki User

9y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program in c plus plus to accept the string and then take the starting and ending point from the user and display the sub string through function?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Four step that are necessary to an a program an a completely dedicated machine?

i. Reserve Machine Time; ii. Manually Load the program into the memory. iii. Load the starting address and begin execution. iv. Monitor and control execution through the use of Console.


Write a C program to find out whether character passes through keybroad is a digit or not?

hey..it s simple..make use of built-in function isdigit(character)..it s in stdlib.h...


What is the Use of main function in c language?

Any program source has to identify a memory location as the start of the program. The OS transfers control to this point of the program or module. In case of C programs, the starting module is NOT your program, but another initialisation routine, which has name lis c0s.obj, c0l.obj etc. This routine after doing initial housekeeping work, like storing program name, arguments, environment variables etc. in the stack, calls a routine by name main. How else are we going to tell the OS where to start ? At the end of executing the main() function, the control goes back to the routine from which the main was called and then to OS, which terminates the program.


What is the difference between local variable and global variable in Embedded C?

It's simple. A global variable has a scope through out out the C program. It can be accessed anywhere from any function or etc. A local variable on the other hand, is local to it's container only and can not be accessed outside of it's container. For example a function has variable sum then sum is only accessible within the function and not anywhere else.


An instruction book or program that takes users through a prescribed series of steps to learn a complex program is called a?

An instruction book or program that takes users through a prescribed series of steps to learn a complex program is called a tutorial.

Related questions

Can you browse through the Help Table of Contents to display information about a particular topic or to familiarize yourself with an Office program.?

no


How can you find a program in Windows 7 without browsing through the program list in the Start Menu?

Use the 'search' function in the Start menu.


Why c program starts from main?

The c program starts with 'main' function because it's compiler is designed that way. so during the compile time, the compiler looks for main function and through that it binds all the other user defined functions.


How do you write a function in Turbo C that can run the program without rerunning the whole program?

The execution path of a program can only be affected by the program input. That is, if you change the input, you can alter the way the program behaves (just as changing the arguments to a function can alter the behaviour of the function). Typically you will alter the input via the command line, but you can also alter the input at any time during program execution. Redirecting input via the command line can be achieved by extracting the input from a file (via std::cin) or by implementing command line switches in your main function, or through a combination of the two.


What type of economic function is it when the federal government provides medical assistance to retired citizens through the medicare program?

equity :D


What type of economic function fits this description The federal government provides medical assistance to retired citizens through the Medicare Program.?

equity


How do you change the date and time on Peugeot 406 Estate LX?

Hold down the LEFT button next to the multi-function display for a couple of seconds. The display should now start flashing. Press the Left button briefly to scroll through the display options and the RIGHT button to change the currently flashing item.


Where can one find more information about starting strength?

Starting Strength is a training program which includes such exercises as squats and bench presses. Further information can be found on the programs available through the Starting Strength Wikia website.


Function of a visual display unit?

LCD are the commanly use in small system such as calculator and portable laptop computer.these non as emmisive deviceproduce picture,by passing polorise light from the sourding or form internal light sousce then it is pass through a liqued cristal material that can be aline do either block or transmit the light.


What is meant by extension?

extensible means to enhance the program with new capabilities. In c++, extensibility can be achieved by using virtual function. now first we discuss what is virtual function in c++. " C++ virtual function is a member function of a class, whose functionality can be over-ridden in its derived classes. The whole function body can be replaced with a new set of implementation in the derived class." Through this u can be able to promote extensibility in your program by using Virtual function. Very simple concept.


Comparison with procedural and structured programming?

In procedural programming languages, such as BASIC and COBOL, program flow generally goes straight through the code, perhaps jumping around now and then through gotos. Individual pieces of code are usually used only once. In structured programming languages, such as Java and C++, blocks of code called functions are 'called' by other functions. For example, the main() function of most c++ programs does not consist of the entire program, but instead of function calls to the various parts of the program. Operations that are performed often in a program can be turned into a function, which can be called repeatedly instead of having to write out the entire operation each time.


How can I render and send a screen buffer through a VGA cable?

The type of cable has nothing to do with the issue. You need a program (there are many) that captures the screen buffer into a file with a defined type like bit map or JPEG. You then need a communications protocol between computer and display device. The transmission can be through whatever means is available to connect the display or printer to the computer.