153k views
4 votes
Write the definition of a function named rcopy that reads all the strings remaining to be read in standard input and displays them, one on a line with no other spacing, onto standard output IN REVERSE ORDER. So if the input was: here comes the sun the output would be sun the comes here The function must not use a loop of any kind (for, while, do-while) to accomplish its job.

User Netic
by
4.7k points

1 Answer

4 votes

Answer:

//Include this header file if program is executing on //visual studio.

#include "stdafx.h";

//Include the required header file.

#include <iostream>

#include <string>

//Use the standard namespace.

using namespace std;

//Define the function rcopy.

void rcopy()

{

//Declare a string variable to store the string.

string s;

//Prompt the user to input the string.

cin >> s;

//Check if the string entered by the user reach to

//the next line character.

if (cin.get() == '\\')

{

//Display the last word in the string.

cout << s << " ";

//Return from the if statement.

return;

}

//Make a recursive call to the function rcopy.

rcopy();

//Display the remaining words in the string in

//the reverse order.

cout << s << " ";

}

//Start the execution of the main method.

int main()

{

//Call the function rcopy.

rcopy();

//Use this system command to hold the console screen //in visual studio.

system("pause");

//Return an integer value to the main function.

return 0;

}

Step-by-step explanation:

See attached images for the code and output

Write the definition of a function named rcopy that reads all the strings remaining-example-1
Write the definition of a function named rcopy that reads all the strings remaining-example-2
Write the definition of a function named rcopy that reads all the strings remaining-example-3
User Enfinet
by
5.3k points