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...

A sheet is the intersection of a row and a column

Indicate whether the statement is true or false

Computer Science & Information Technology

Attempting to access a private member of a class outside that class ________.

a) is a run-time error b) is a syntax error c) is a logic error d) can be accomplished using IntelliSense e) None of the above.

Computer Science & Information Technology