Question

In: Computer Science

Write a short C++ program that takes all the lines input to standard input and writes...

Write a short C++ program that takes all the lines input to standard input and writes them to standard output in reverse order. That is, each line is output in the correct order, but the ordering of the lines is reversed.

Please use vector datatype standaard library #include <vector>

Thanks

Solutions

Expert Solution

Note :

Check is this is the exact requirement do you want?If you want me to do any changes I will do it.Thank You.

______________________
#include <iostream>
#include <vector>
using namespace std;

int main()
{
   //Derclaring variable
   string line;
  
   //Declaring vector
vector<string> vec;
  
/* This loop continues to execute
* until the user enters -1 as input
*/
while(true)
{
//Getting the setence entered by the user
cout<<"Enter a Sentence :";
std::getline(std::cin, line);
  
//Checking whether the sentence is valid or not
if(line!="-1")
{
//Inserting sentence into vector.
vec.push_back(line);

continue;
}
else
break;
}

cout<<"\nThe elements in the vector are :\n";
  
//This for loop will display the elements inside the vector
for(int i=0;i<vec.size();i++)
{
cout<<vec[i]<<endl;
}
  
//Displaying the elements in the vector
cout<<"\n\nThe elements in the vector in reverse order are :\n";
  
//This for loop will display the elements inside the vector
for(int i=vec.size()-1;i>=0;i--)
{
cout<<vec[i]<<endl;
}
  

return 0;
}

__________________________

output:

________Thank You


Related Solutions

"This C Programming " Write a program that accepts four (4) lines of input: • The...
"This C Programming " Write a program that accepts four (4) lines of input: • The first line contains a float value in 4.2f format • The second line contains a char value • The third line contains a 4-digit int value • The fourth line contains a char value and then displays all of the input on a single line Write a program that accepts a phone number of the form +1(xxx)-xxx-xxxx where x is a digit, and displays...
C++ Write a program that takes a string and integer as input, and outputs a sentence...
C++ Write a program that takes a string and integer as input, and outputs a sentence using those items as below. The program repeats until the input string is "quit". If the input is: apples 5 shoes 2 quit 0 the output is: Eating 5 apples a day keeps your doctor away. Eating 2 shoes a day keeps your doctor away.
Write a C++ program that takes input from the keyboard of the 3 dimensions of a...
Write a C++ program that takes input from the keyboard of the 3 dimensions of a room (W,L,H in feet) and calculates the area (square footage) needed to paint the walls only. Use function overloading in your program to pass variables of type int and double. You should have two functions: one that accepts int datatypes and one that accepts double datatypes. Also assume a default value of 8 if the height parameter is omitted when calling the functions.
Use C language Write a program that reads in a series of lines of input character...
Use C language Write a program that reads in a series of lines of input character by character (using getchar()). The first line of the input contains an integer which specifies the number of remaining lines of input, each of which contains a floating point number. The integer value on the first line can be read with scanf(), but all of the following lines can only be read with getchar(). Each line after the first contains a single floating point...
Write a program that takes, as input, five numbers and outputs the mean (average) and standard...
Write a program that takes, as input, five numbers and outputs the mean (average) and standard deviation of the numbers. If the numbers are x₁, x₂, x₃, x₄, and x₅, then the mean is: x = (x₁+ x₂+ x₃+ x₄+x₅)/5 and the standard deviation is: s = √(((x₁-x)²+(x₂-x)²+(x₃-x)²+(x₄-x)²+(x₅-x)²)/5) Your program must contain at least the following functions: a function that calculates and returns the mean and a function that calculates the standard deviation. Format your output with setprecision(2) to ensure...
Write a complete C++ program that prompts the user for and takes as input, numbers until...
Write a complete C++ program that prompts the user for and takes as input, numbers until the user types in a negative number. the program should add all of the numbers together. Then if the result is less than 20 the program should multiply the result by 3, otherwise subtract 2 from the result. Finally, the program should printout the result.
Write a C++ program that takes two sets ’A’ and ’B’ as input read from the...
Write a C++ program that takes two sets ’A’ and ’B’ as input read from the file prog1 input.txt. The first line of the file corresponds to the set ’A’ and the second line is the set ’B’. Every element of each set is a character, and the characters are separated by space. Implement algorithms for the following operations on the sets. Each of these algorithms must be in separate methods or subroutines. The output should be written in the...
Write a program in C that takes as input an 8-bit binary number and prints the...
Write a program in C that takes as input an 8-bit binary number and prints the next 10 binary numbers. Define a binary number as int binNum[8]; Use binNum[0] to store the most significant (i.e., leftmost) bit and binNum[7] to store the least significant bit. Ask the user to input the first binary number with each bit separated by at least one space.
Write a program in C that takes as input a four-digit hexadecimal number and prints the...
Write a program in C that takes as input a four-digit hexadecimal number and prints the next 10 hexadecimal numbers. Define a hexadecimal number as int hexNum[4] Allow upper- or lowercase letters for input and use uppercase letters for the hexadecimal output. For example, 3C6f should be valid input and should produce output 3C6F, 3C70, 3C71, . . . .
Write a C++ program that takes two sets ’A’ and ’B’ as input read from the...
Write a C++ program that takes two sets ’A’ and ’B’ as input read from the file prog1 input.txt. The first line of the file corresponds to the set ’A’ and the second line is the set ’B’. Every element of each set is a character, and the characters are separated by space. Implement algorithms for the following operations on the sets. Each of these algorithms must be in separate methods or subroutines. The output should be written in the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT