[SOLVED] Design Patterns Homework 1 Solved  

25.00 $

Programming resource
Digital learning resource
Category:
✓ Practical programming resource
✓ Suitable for guided study and reference
✓ Tutor guidance available when needed

Description

5/5 - (1 vote)
●     (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
{
public:
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).

Resource details

Understand the Task Before You Use the Resource

Review the requirements, identify the programming concepts involved, study the implementation and test your understanding with your own examples and modifications.