New version page

Clemson CPSC 870 - Lab Assignment #1

Documents in this Course
Load more
Upgrade to remove ads
Upgrade to remove ads
Unformatted text preview:

CpSc 870 Fall 2005Lab Assignment #1:The Cactus StackSeptember 15, 20051 OverviewThe purpose of this assignment is two-fold. First, you will gain some experience developingclasses in C++, and will sharpen your understanding of constructors, destructors, over-loaded operators, and dynamic memory allocation. Second, you will gain some experienceworking with file I/O in C++. There are two parts to this assignment; they are describedin the sections that follow.2 Part 1: The Cactus StackFor the first part of the assignment, you will implement a C++ class that represe nts astandard stack abstraction. Your stack will be used to store strings. (You may use eitherstandard C strings or the String class that we developed together.) This type of abstrac-tion might be used, for example, to control the behavior of the “back” button in a webbrowser. Your class should be named StackImpl1, and must implement the “cactus stack”representation that we will discuss in class. At a minimum, your class should have thefollowing features:• Your class should provide a default constructor, a copy constructor, and a destructor.They should provide the behaviors that one would expect. Both of your construc-tors must execute in constant time.• Your class should provide the following methods: push(), pop(), getTop(), getLength(),and clear(). These methods should exhibit the behaviors that one would normallyexpect of a stack. With the exception of clear(), these methods must executein constant time.• Your class should override the + and += operators to provide a more convenient wayto push an element onto the stack. Both of these operators must execute inconstant time.• Your class should override the = and == operators to provide the behaviors that onewould reasonably expect. The = operator must execute in constant time.• Your class should override the << operator to print the contents of your stack tostdout.1CpSc 870 Fall 2005• Your class implementation should follow the principal of least privilege.• Your class implementation should use as little memory as possible.3 Part 2: Testing the Cactus StackFor the second part of the assignment, you will implement a C++ clas s that assists inautomating the execution of test cases. Your class will read com mands from a testingscript, and interpret those commands to execute the appropriate methods on instances ofStackImpl1. Your class should have the following features:• Your class should store 10 instances of StackImpl1 in an array, with each instanceinitialized as empty. The instance identifier of each instance corresponds to its indexin the array.• Your class should provide the bool openScript(const char* const fileName) methodfor opening the test script specified as argument. The return value of this methodshould indicate whether the script was opened successfully.• Your c lass should provide the bool moreCommands() method to determine whetherthe current script contains additional commands that may be executed.• Your class should provide the void closeScript() method to close the current script.• Your class should provide the void executeCommand() method to execute the nextcommand contained in the script. Each script command will specify a method to beinvoked on a particular stack instance, and will spe cify any required arguments. TheexecuteCommand() me thod will first print the pre-conditional value of the appropriatestack, as well as any arguments passed to the stack method. Next, it will execute thespecified stack method. Finally, it will print the p os t-conditional value of the stackinstance, the post-conditional values of any arguments, and any value returned by thestack method.Each script command will be separated by a newline character. The format of eachcommand will be as follows:<command> ::= <method id> <stack instance id> [<string argument>]<method id> ::= push | pop | getTop | getLength | clear<stack instance> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9<string argument> ::= ... an arbitrary string with no delimiters ...Please note that white space characters are insignificant in this grammar. There might,for example, be ten white space characters between the method identifier and the stackinstance identifier.4 Hand-In InstructionsYou are required to submit a zip file containing all of the source code for this assignmentbefore class on October 4th, and to provide me with hard copies of your source listings atthe start of class on that day.2CpSc 870 Fall 20055 Final NotesPlease start early. The lab as signments are designed to help you become an expert in C++.I expect them to be time-consuming.You are expected to work on this assignment individually. Please do not consult anyoneother than me on any aspect of this

View Full Document
Download Lab Assignment #1
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...

Join to view Lab Assignment #1 and access 3M+ class-specific study document.

We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lab Assignment #1 2 2 and access 3M+ class-specific study document.


By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?