This website is preserved for historical and scholarly reference and is no longer actively maintained.
                         CpSc 241, Section 1
                             Assignment 4
                           9 February 2000


Due: Wednesday, February 16 at midnight

Late penalties: 20 points per partial day late.  That is, programs
	turned in after midnight Wednesday and before midnight Thursday
	will have 20 points deducted for late, programs turned in after
	midnight Thursday and before midnight Friday will have a total
	of 40 points deducted for late, etc.

Total point value of assignment:  100 points

Late submissions not accepted after: Sunday, February 20 at midnight

This assignment is to be done INDIVIDUALLY.


Create a directory, A4, which will contain all parts of this assignment.
You will need class ListNode, class ListItr, and class List from the text. 
You will also need

	class Stack (description below) and
	a4.cpp (your main program)  

The objectives of this program are to give you some more experience 
using code "off the shelf" or designed by others and reinforce
construction of a stack using only the methods of singly linked list.
You are to use the classes ListNode, ListItr, and List from the text 
without making any changes to these classes. 

The methods to be implemented for a Stack are found in the interface
given in Figure 3.41 on page 94, but do not include the struct ListNode.
Place the interface in a file Stack.h, such as


	// File name:  Stack.h

	#ifndef _Stack_H_
	#define _Stack_H_

	#include "ListNode.h"
	#include "ListItr.h"
	#include "List.h"

	template 
	class Stack
	{	
	   public:
	      Stack( )  { };
	      Stack ( const Stack & rhs ) : L ( rhs.L )  {  };
	      ~Stack ( );

	      bool isEmpty ( ) const;
	      bool isFull ( ) const;
	      const Object & top ( ) const;

	      void makeEmpty ( );
	      void pop ( );
	      void push ( const Object & x );
	      Object topAndPop ( );

	      const Stack & operator= ( const Stack & rhs );

	   private:
	      List  L;  // List used to implement Stack
 
	};

	#include "Stack.cpp"
	#endif


The implementation is to be placed in a file Stack.cpp.  Do not use
the implementation given in the text.  Instead, call List and/or
ListItr methods to accomplish every operation.  For example, my
code for isEmpty looks like
 

	template 
	bool Stack::isEmpty ( ) const
	{
	   return L.isEmpty( );
	}


The main() will be called a4.cc or a4.cpp, whichever you choose.  Submit
all files in directory A4 using handin.

Input:

	Request the user to enter commands push, pop, top, topAndPop,
	makeEmpty, and print (which prints the stack).  Your main
	program may use either strings or ints on the stack.  The
	Stack should, of course, store Objects.

	If the command needs a parameter, request the parameter.
	Allow the user to continue entering commands until the word
	end is entered instead of a command.

	Use a throw/catch if the user enters any word other than the
	five commands and "end".  The catch should print that the
	command was not one of the allowable words and ask if the
	user wishes to continue.

Output:

	Before reading the input, print your name, the assignment number,
	and a short description of the assignment to the screen.


Other requirements:

	Follow the style standards to be found from your instructor's
	web page for CPSC 241.


Grading rubric:

	In the opinion of the instructor the program is an honest attempt
		to complete the assignment as described  10 pts.

	If the above requirement is met:

		Required documentation 10 pts.
		Style standards 20 pts.
		Program compiles without errors.  10 pts.

	If the the program does not compile without error, no further points
		will be awarded.

	Correct operation of Stack methods.  All Stack methods given in the
	interface Stack.h must be implemented. 40 pts.

	Correct use of throw/catch.  10 pts.