Write a program that inputs a line of text and uses a stack object to print the line reversed.

What will be an ideal response?


```
#include
using namespace std;

#include "Stack.h"

int main()
{
Stack< char > charStack; // a stack of char
char c; // represent a character from the input stream

cout << "Enter a sentence:\n";

// push onto stack until a null terminator is reached
while ( ( c = static_cast< char >( cin.get() ) ) != '\n' )
charStack.push( c );

cout << "\nThe sentence in reverse is:\n";

while ( !charStack.isStackEmpty() )
{
charStack.pop( c );
cout << c << ' ';
} // end while

cout << '\n';
return 0; // indicates successful termination
} // end main
```
Enter a sentence:
Hello World!
The sentence in reverse is:
! d l r o W o l l e H
All nodes destroyed

Computer Science & Information Technology

You might also like to view...

Which operator concatenates two strings?

A. = B. =+ C. + D. ==

Computer Science & Information Technology

The Caption property is used to give a name to fields used on forms and reports

Indicate whether the statement is true or false

Computer Science & Information Technology

How many outline levels can be animated in PowerPoint 2013?

A) Eight B) Six C) Five D) Four

Computer Science & Information Technology

Laptop computers use the same DDR3 memory modules as desktop computers

Indicate whether the statement is true or false

Computer Science & Information Technology