Question: Backward String: The purpose of this program is to ask the user to input a string into a C-string (i.e. a character array) using the

Backward String:

The purpose of this program is to ask the user to input a string into a C-string (i.e. a character array) using the cin.getline function (see section 10.3 of Chapter 10, this will allow you to also include spaces in the input stream). Then, a function reverseStr will accept the character array as an argument, and return the content backwards in the same array (remember arrays are passed by reference in C++). Do NOT use pointers to solve this problem.

So for example, if the user input Hello World!, the program should call the function reverseStr as below:

const int SIZE = 81;

char inputLine [SIZE];

cin.getline (inputLine, SIZE); // User input Hello World!

reverseStr (inputLine); // The inputLine is now !dlroW olleH

The input character string should be no more than 81 characters (see above) to allow the user to input a long input string (e.g. Hello, my name is Ben Franklin.).

The main function code must use the following:

// Global Constants

const int MAX_STRINGLEN = 81;

// Function prototypes

void printProgramPurpose ();

void reverseStr (char inputString []);

void printProgrammerName ();

int main()

{

char inputString[MAX_STRINGLEN]; // To hold the C-string

// Print the welcome message for the user

printProgramPurpose ();

// Get a string from the user.

cout << "Enter a string of " << MAX_STRINGLEN;

cout << " or fewer characters: ";

cin.getline(inputString, MAX_STRINGLEN);

// Reverse the string

reverseStr(inputString);

cout << " Reversed: " << inputString << endl;

cout << endl << endl;

// Print Programmer Name

printProgrammerName ();

return 0;

}

Your job is to complete the program and write the functions listed in the function prototype list:

// Function prototypes

void printProgramPurpose ();

void reverseStr (char inputString []);

void printProgrammerName ();

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!