$35
Lab 07: The Cow Strikes Back
Overview
This lab’s purpose is to provide students with experience in inheritance of classes and working with multiple classes. It is recommended that students use command line tools and editors for this lab (though it is not strictly speaking required). This lab will require students to build on their previous lab experience, in which a version of the cowsay utility was created; however, this lab will be written in C++. Note that you will need to set the language version to C++17 in your CMakeLists.txt file for this project.
Specification
Executable Specification
Your program must accept command line arguments as follows:
cowsay ‐l Lists the available cows
cowsay MESSAGE Prints out the MESSAGE using the default cow cowsay ‐n COW MESSAGE Prints out the MESSAGE using the specified COW
In addition, this version of the utility handles a special set of Cow-derived Dragon classes (and its subclasses). Whenever a dragon-type cow is selected, the display of the message must be followed by a line stating whether or not the dragon is fire-breathing:
finn@BMO:~$ ./cowsay ‐n dragon Fiery RAWR
Fiery RAWR
|___/| / //|\
/0 0 __ / // |
/ / /_ / // |
_^_'/ /_ // |
//_^_/ /_ // |
( //) | // |
( / /) _|_ / ) // | _
( // /) '/,_ _ _/ ( ; ‐. | _ _.‐~ .‐~~~^‐.
(( / / )) ,‐{ _ `.|.‐~‐. .~ `.
(( // / )) '/ / ~‐. _.‐~ .‐~^‐.
(( /// )) `. { } /
(( / )) .‐‐‐‐~‐. ‐' .~ `. __
///.‐‐‐‐..> _ ‐~ `. ^‐` ///‐._ _ _ _ _ _ _}^ ‐ ‐ ‐ ‐ ~ `‐‐‐‐‐'
This dragon can breathe fire. finn@BMO:~$ cowsay ‐n ice‐dragon Ice‐cold RAWR
Ice‐cold RAWR
|___/| / //|\
/0 0 __ / // |
/ / /_ / // |
_^_'/ /_ // |
//_^_/ /_ // |
( //) | // |
( / /) _|_ / ) // | _ ( // /) '/,_ _ _/ ( ; ‐. | _ _.‐~ (( / / )) ,‐{ _ `.|.‐~‐. (( // / )) '/ / ~‐. _.‐~ (( /// )) `. { } (( / )) .‐‐‐‐~‐. ‐' ///.‐‐‐‐..> _ ///‐._ _ _ _ _ _ _}^ ‐ ‐ ‐ ‐ ~
This dragon cannot breathe fire.
Cow Class
public Cow(const string& _name) // Constructor public string& getName() // Returns name of this cow object public string& getImage() // Return image for this cow object public virtual void setImage(const string& _image) // Sets image for this cow object
Dragon Class
public Dragon(const string& _name, const string& _image)
Constructor; creates new Dragon object with given name and image. This must be its only public constructor!
public bool canBreatheFire()
This method should exist in every Dragon class. For the default Dragon type, it should always return true.
IceDragon Class
The IceDragon class must be derived from the Dragon class and must make all its methods available:
public IceDragon(const string& _name, const string& _image)
Constructor; creates a new IceDragon object with the given name and image. This should be the only public constructor for the IceDragon class!
public bool canBreatheFire()
For the IceDragon type, this method should always return false.
HeiferGenerator Class (Provided)
public static vector<Cow*>& getCows()
Returns a reference to a vector of cow object pointers from built-in data set. This will call the Cow constructor and setImage() methods of the cow class if needed to initialize new cow objects uniquely for each data set.
public static Dragon* getDragonPointer(Cow* candidate)
If object pointed to by candidate is a Dragon (including an IceDragon), returns a Dragon pointer to the object. Otherwise, returns nullptr.
Submissions
NOTE: Your output must match the example output *exactly*. If it does not, you will not receive full credit for your submission! (Note that matching sample output is necessary, but not sufficient, for full credit.)
Files: cowsay.cpp, Cow.cpp, Cow.h, Dragon.cpp, Dragon.h, IceDragon.cpp, IceDragon.h, CMakeLists.txt Method: Submit on Canvas
Sample Output
finn@BMO:~$ ./cowsay
finn@BMO:~$ ./cowsay Hello World!
Hello World!
^__^
(oo)_______
(__) )/
||‐‐‐‐w |
|| ||
finn@BMO:~$ ./cowsay ‐n kitteh Meow‐Meow!
Meow‐Meow!
("`‐' '‐/") .___..‐‐' ' "`‐._
` *_ * ) `‐. ( ) .`‐.__. `)
(_Y_.) ' ._ ) `._` ; `` ‐. .‐'
_.. `‐‐'_..‐_/ /‐‐' _ .' ,4
( i l ),‐'' ( l i),' ( ( ! .‐'
finn@BMO:~$ ./cowsay ‐n ninja Hello world!
Could not find ninja cow!
finn@BMO:~$ ./cowsay ‐l
Cows available: heifer kitteh dragon ice‐dragon
finn@BMO:~$ ./cowsay ‐n dragon Firey RAWR
Fiery RAWR
|___/| / //|\
/0 0 __ / // |
/ / /_ / // |
_^_'/ /_ // |
//_^_/ /_ // |
( //) | // |
( / /) _|_ / ) // | _
( // /) '/,_ _ _/ ( ; ‐. | _ _.‐~ .‐~~~^‐.
(( / / )) ,‐{ _ `.|.‐~‐. .~ `.
(( // / )) '/ / ~‐. _.‐~ .‐~^‐.
(( /// )) `. { } /
(( / )) .‐‐‐‐~‐. ‐' .~ `. __
///.‐‐‐‐..> _ ‐~ `. ^‐` ///‐._ _ _ _ _ _ _}^ ‐ ‐ ‐ ‐ ~ `‐‐‐‐‐'
This dragon can breathe fire.
finn@BMO:~$ ./cowsay ‐n ice‐dragon Ice‐cold RAWR
Ice‐cold RAWR
|___/| / //|\
/0 0 __ / // |
/ / /_ / // |
_^_'/ /_ // |
//_^_/ /_ // |
( //) | // |
( / /) _|_ / ) // | _
( // /) '/,_ _ _/ ( ; ‐. | _ _.‐~ .‐~~~^‐.
(( / / )) ,‐{ _ `.|.‐~‐. .~ `.
(( // / )) '/ / ~‐. _.‐~ .‐~^‐.
(( /// )) `. { } /
(( / )) .‐‐‐‐~‐. ‐' .~ `. __
///.‐‐‐‐..> _ ‐~ `. ^‐` ///‐._ _ _ _ _ _ _}^ ‐ ‐ ‐ ‐ ~ `‐‐‐‐‐'
This dragon cannot breathe fire.