Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lab2 C++ Warmup: Pet Applicatioin Cop 4331 and EEL4884 © Dr. David A. Workman School of EE and Computer Science University of Central Florida February.

Similar presentations


Presentation on theme: "Lab2 C++ Warmup: Pet Applicatioin Cop 4331 and EEL4884 © Dr. David A. Workman School of EE and Computer Science University of Central Florida February."— Presentation transcript:

1 Lab2 C++ Warmup: Pet Applicatioin Cop 4331 and EEL4884 © Dr. David A. Workman School of EE and Computer Science University of Central Florida February 12, 2010 Revised: February 15, 2010

2 February 15, 2010(c) Dr. David A. Workman2 Problem Statement Write a C++ application for modeling "pets" – those furry animals called "cats" and "dogs." The application shall read instances of pets commands from an external ASCII file, call methods appropriate to the command and type of pet (cat or dog) to simulate its behavior. In addition, the command and the pet's response shall be written to an ASCII output stream. Detailed functional and non-functional requirements will be given for each class in this application.

3 February 15, 2010(c) Dr. David A. Workman3 Input Requirements Sample Input Command{ action: name? pet1: Pet{ name: Thing dna: pet sex: female }Pet }Command Command{ action: speak! pet1: Dog{ name: Fido dna: dog sex: male }Dog }Command Command{ pet1: Dog{ name: Fido dna: dog sex: male }Dog action: mate! pet2: Dog{ name: Suade dna: dog sex: female }Dog }Command Command{ action: color? pet1: Cat{ name: Calvin dna: cat sex: male color: white }Cat }Command END Requirements: 1.The OO data format shall be used for Command, Pet and each subclass of Pet. 2.The set of legal action verbs is specific to the pet class. 3.An END token terminates the input stream.

4 February 15, 2010(c) Dr. David A. Workman4 Output Requirements Sample Output Requirements: 1.The OO data format shall be used for Command, Pet and each subclass of Pet. 2.The set of legal action verbs is specific to the pet class. 3.A blank line shall separate the group of lines defined by a Command and its output. Command{ action: name? pet1: Pet{ name: Thing dna: pet sex: female }Pet }Command My name is: Thing Command{ action: speak! pet1: Dog{ name: Fido dna: dog sex: male }Dog }Command My bark is: Woof Command{ pet1: Dog{ name: Fido dna: dog sex: male }Dog action: mate! pet2: Dog{ name: Suade dna: dog sex: female }Dog }Command The offspring is: Dog{ name: Fido+Suade dna: dog sex: male }Dog Command{ action: color? pet1: Cat{ name: Calvin dna: cat sex: male color: white }Cat }Command My color is: white

5 February 15, 2010(c) Dr. David A. Workman5 Other Application Requirements 1.The application shall use the facilities of IOMgmt for managing the input and output streams; specifically, InMgr, OutMgr and TokenError. 2.Each Command shall be echoed to the output stream (if valid) followed by the command output on a separate line. 3.All string manipulation shall involve operations on instances of C++ class string (no features of C).

6 February 15, 2010(c) Dr. David A. Workman6 The Command Class Command // TBD - developer’s discretion +Command() +Command( ifstream& ) +Execute( ostream& ) // AppError exception +Extract( ifstream& ) // TokenError exception +Insert( ostream& ) friend operator>> //TokenError exception friend operator<< #Get( ifstream& ) // TokenError exception #Put( ostream& ) The Command class defines instances in one of two forms: (a) Command{ action: unaryOp pet1: pet-instance-1 }Command (b) Command{ pet1: pet-instance-1 action: binaryOp pet2: pet-instance-2 }Command Where unaryOp is a string that defines a unary operation on a single instance of the Pet class (or subclass), and where binaryOp is a string that defines a binary operation on two instances of the Pet class (or subclass). Both unaryOp and binaryOp must be validated by the class to which the operation applies. This shall be done By calling the appropriate Perform() method of the given class. The Execute() method executes a valid command and produces its resulting output on the output stream passes as a reference parameter. Execute() may propagate an AppError exception thrown by Perform().

7 February 15, 2010(c) Dr. David A. Workman7 The Pet Class Pet name: string // default = Apet dna: string // default = Pet sex: string //(male | female) +Pet() +Pet( string, string, string ) +Perform( string ) // AppError exception +MyNameIs(): string +MySpeciesIs(): string +MySexIs(): string +Extract( ifstream& ) // TokenError exception +Insert( ostream& ) friend operator>> //TokenError exception friend operator<< #Get( ifstream& ) // TokenError exception #Put( ostream& ) Unary Ops Response Name? Species? Sex? My name is: MyNameIs() My species is: MySpeciesIs() My sex is: MySexIs() void Perform( string cmd, ostream& fout ) throw (AppError); This method validates the (cmd) parameter and throws an appropriate AppError exception if it not a valid command verb. If the verb is valid, this method produces the appropriate response on the output stream (fout).

8 February 15, 2010(c) Dr. David A. Workman8 Dog Class Interface Dog // value of dna must == "dog" +Dog() +Dog( string, string, string ) //MyNameIs() is inherited from Pet //MySpeciesIs() is inherited from Pet //MySexIs() is inherited from Pet +Perform( string, ostream&) //Overrides Pet +Perform( string, ostream&, Dog&) +Extract( ifstream& ) //Overrides Pet +Insert( ostream& ) //Overrides Pet +Bark(): string +Mate( Dog ) : Dog //parameter == B #Get( ifstream& ) #Put( ostream& ) Command Verb Response Name? Species? Sex? Speak! Mate! My name is: MyNameIs() My species is: MySpeciesIs() My sex is: MySexIs() My bark is: Bark() The offspring is: A.Breed(B) string Bark() Returns "Woof" (male) or "Woof Woof" (female) Dog Mate ( Dog B) throw(AppError) Given A, B are instances of Dog and the call is made: A.Mate(B). This results from A.Perform( cmd, fout, B) This method throws an AppError exception if A and B are of the same sex, or either of them is not of the "dog" species. If both instances are well-defined, the resulting offspring shall have a name formed by concatenating A.MyNameIs() with B.MyNameIs(). The sex of the offspring shall always be A.MySexIs().

9 February 15, 2010(c) Dr. David A. Workman9 Dog Class Requirements 1.Every Dog shall provide the same behavior common to all pets. 2.The image of a Dog instance shall have the following format: Dog{ name: dna: dog sex: }Dog 3.Dogs will bark when asked. A male Dog will bark "Woof", a female Dog will bark "Woof Woof". 4.Dogs shall mate, provided they are of the opposite sex. A Dog can only mate with a member of the same species. The name of the offspring shall be constructed from the names of the parents to the breed operation. The sex of the offspring shall be the same as the Dog to which the breed operation is applied; e.g., A.Mate(B) => C, where C has name "nameof(A)+nameof(B)" and the same sex as A. 5.An AppError exception shall be thrown by the breed operation if there is a species violation or a sex violation. The exception message shall indicate which violation occurred.

10 February 15, 2010(c) Dr. David A. Workman10 Cat Class Interface Cat color: string +Cat() +Cat( string, string, string, string ) //MyNameIs() is inherited from Pet //MySpeciesIs() is inherited from Pet //MySexIs() is inherited +Perform( string, ostream& ) //overrides Pet +MyColorIs(): string +Cry(): string +Extract( ifstream& ) //Overrides Pet +Insert( ostream& ) //Overrides Pet #Get( ifstream& ) #Put( ostream& ) Note1: Extract() and Get throw a TokenError exception if there are syntax violations. Command Verb Response Name? Species? Sex? Speak! My name is: MyNameIs() My species is: MySpeciesIs() My sex is: MySexIs() My cry is: Cry() string Cry() Returns "Meow"

11 February 15, 2010(c) Dr. David A. Workman11 Cat Class Requirements 1.Every Cat shall provide the same behavior common to all pets. 2.The image of a Cat instance shall have the following format: Cat{ name: dna: cat sex: color: }Cat 3.Cats will cry when asked. A Cat's cry is "Meow" (male and female).

12 February 15, 2010(c) Dr. David A. Workman12 Pet Application Design Model IOMgmt InMgrOutMgr TokenErrorIOError AppError StringTokenizerTokenizer PetApp Pet Cat Dog (main) Command 1..2 The main() function of PetApp shall open the input stream and create the output stream using classes InMgr and OutMgr. It shall process the input stream by extracting and executing commands until the “END” token in encountered. After processing the input stream, both input and output streams shall be closed by main(). Appropriate catch-blocks shall be provided to handle exceptions. Exceptions shall be handled by outputting Them to the user terminal.

13 February 15, 2010(c) Dr. David A. Workman13 Lab2 Deliverables 1.Source files for the Pet Application ( PetApp.cpp, Pet.h, Pet.cpp, Cat.h, Cat.cpp, Dog.h, Dog.cpp, Command.h, Command.cpp ) 2.Test data input and output files. 3.UNIX Makefile for the Pet Application. 4.Personal Evaluation forms. 5.A Word document (professional style) that describes how your team would modify the design of PetApp to add the capability, for example, of saving the result of a “mate” operation on class Dog so that it could be used in a subsequent “mate” command? More generally, suppose we want the capability of saving the result of any operation that produces an instance of the class to which the operation applies for later reference in a subsequent command. This capability amounts to designing and implementing a “Pet Programming Language”. Your design shall deviate as little as possible from the present design. That is, the existing classes should still be valid with perhaps minor modifications. You may add additional modules to the design as you see fit. (Hint: consider an addressable memory). Your design document (in Word) should describe the changes necessary to each existing module of the PetApp and any new modules you add to the design. The goal here is enhance the application with least effort spent on rework and testing. 6. All deliverables shall be submitted via email to the instructor (workman@cs.ucf.edu) in the form of a single (.zip) file (perhaps with a disguised extension) as you did for Lab1.workman@cs.ucf.edu

14 Team Guidelines The primary learning objectives are the following: –For each student to develop and test C++ code in the context of a team project; team leads shall make this a priority. I suggest having those members that are least experienced with C++ write the code, while those with the most C++ experience independently test the code. This is the “paired programming” concept used in industry. –For each student to become familiar with the OO Data Format and Design protocol and how it exploits runtime binding in C++. –For each student to know how to write a simple Makefile and use it to compile and run the pet application in both a UNIX and a Windows environment. –Finally, for all members to become more experienced in developing OO design exploiting information hiding, data encapsulation and separation of concerns. I strongly encourage leads to employ design reviews and code walkthroughs as part of the software quality assurance process for your team. February 15, 2010(c) Dr. David A. Workman14


Download ppt "Lab2 C++ Warmup: Pet Applicatioin Cop 4331 and EEL4884 © Dr. David A. Workman School of EE and Computer Science University of Central Florida February."

Similar presentations


Ads by Google