Design Patterns Homework 1 Solved

●     (10 points) Enter, compile, and execute the following C++ program.
 #include <iostream
using namespace std;
int main( int argc, char *argv[] )
    cout << "Hello World!\n";

●     (40 points) Write a class, called  Stack, in a file called Stack.h, that implements a stack of up to 1000 characters. You should include the following member functions in your class.
   #define STACK_CAPACITY 1000
  class Stack
    Stack(); // constructor for a stack
    void push( char c ); // adds c to the top of the stack
    void pop(); // removes top element
    char top(); // returns the top element
    bool isEmpty(); // returns true iff the stack is empty
    ~Stack(); // destructor for a stack

●     (30 points) Write a main procedure, in a file called main.cpp, that repeatedly reads a character string from  cin into a string variable and outputs the reverse by pushing the characters onto an instance of your stack class, then printing them as they are removed from the stack.

●     (20 points) Modify your program to exit on end of file (when the user types a ^D, on unix, or ^Z, on the Windows).

Powered by