answersLogoWhite

0

#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

11y ago

What else can I help you with?

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

What is the function of the LCD polarizer in electronic devices?

The function of the LCD polarizer in electronic devices is to control the direction of light passing through the liquid crystal display (LCD) screen, allowing for the display of images and information in a clear and visible manner.


How do you change my multi function display for Fahrenheit to Celsius for temp?

To switch the temperature unit on your multi function display from Fahrenheit to Celsius, consult your vehicle's user manual for specific instructions. Typically, you would navigate through the settings menu on the display panel using the buttons or touchscreen to find the temperature unit setting and select Celsius.


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


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.


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.


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.