Sale!

CSc 300 – Assignment #2 solution

$24.99 $14.99

Original Work ?

Download Details:

  • Name: stack_Implementation.zip
  • Type: zip
  • Size: 97.72 KB

Category: You will Instantly receive a download link upon Payment||Click Original Work Button for Custom work

Description

5/5 - (4 votes)

Create a user-defined Abstract Data Type (ADT) that implements a stack using a C++ class named StackType and an appropriate set of C++ header/implementation files as discussed in class. • The StackType ADT must be implemented using a linked list. • Each element stored in the StackType ADT is of type ElementType. o ElementType is an exportable primitive char data type. § Usage not restricted to the StackType class alone.
The StackType ADT must define and implement the following data types and operations. • Do not add any additional data types or operations. • Do not modify any of the defined data types or operations.
Exportable Operations: (declared .h file and defined .cpp file) StackType default constructor function – creates an initialized empty stack StackType copy constructor – creates a duplicate copy of an existing stack (*) ~StackType destructor function – removes all elements from the stack stack instance state before going out of scope – initialized empty stack push inserts a new element to the top of the stack pop removes an existing element from the top of the stack peek accesses the top element on the stack (*) does not permanently alter the stack view displays the contents of the stack from the top to the bottom (*) non-destructive implementation
(*) Before an element can be accessed and processed it must first be removed from the top of the stack.
User-Defined Data Types: ElementType, NodeType, PointerType
StackType Output Examples: (view) // Required Output Format The Top – The Bottom The Top – S – D – S – U – The Bottom
Make sure that you completely document the header/implementation files. • The header (.h) file tells the user exactly how to use your ADT o General descriptions only – do not include implementation details • The implementation file (.cpp) tells the implementer/programmer exactly how the ADT works o Detailed descriptions – include implementation details Zip together and e-mail your header/implementation files using the following naming convention. • Do not e-mail your main/driver program o I will create my own main/driver program to test your ADT username2.h for the header file // I would use gamradtk2.h username2.cpp for the implementation file // I would use gamradtk2.cpp username2.zip // I would use gamradtk2.zip
List the class number, your username, and assignment number as the e-mail message SUBJECT: csc300 – gamradtk – a2. // This is what I would use
Required header file (.h). // only partially specified
// General description of the ADT and supported operations – exportable operations only // Do not include any implementation details
class StackType { public: // exportable // General description of each of the ADT operations/functions – exportable operations only StackType(); StackType( StackType & ); ~StackType(); void push( const ElementType ); void pop( ElementType & ); void peek( ElementType & ); void view(); private: // non-exportable struct NodeType; typedef NodeType * PointerType; struct NodeType { ElementType element; PointerType next; }; PointerType theTop; };
Define a macro to prevent multiple inclusion of the header file. • I would use _GAMRADTK2_H for a header file with the filename gamradtk2.h.
I will write a test program that will include your ADT so all header/implementation files tested must use common names. So you MUST use: • the EXACT same names for each data type and function in the header/implementation files. • the EXACT same function argument sequence in the header/implementation files. Remember that a stack uses the basic operations of push and pop to support all other operations. • Apply function Reuse wherever possible. o E.g., copy constructor, destructor, peek, view, … Throughout the textbook examples are shown using Templates. • Do not use Templates unless you are explicitly told to do so.
Compiling C++ programs with external modules from the command line:
g++ driver2.cpp gamradtk2.cpp // list all .cpp files // executable file named a.out if successful
g++ -o gamradtk2 driver.cpp gamradtk2.cpp // list all .cpp files // executable file named gamradtk2 if successful
Replace my Linux username with your Linux username