$35
Lab 08: Return of the Cow
Overview
This lab’s purpose is to provide students with experience in file I/O and C++ exceptions. 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. Students will need to look up the constructors for some C++ standard objects, such as exceptions, in the C++ documentation to complete this lab. Note that you will need to set the language version to C++17 in your CMakeLists.txt file for this project.
Specification
Cowsay Class (Program Driver)
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 built-in COW
cowsay -f COW MESSAGE Prints out the MESSAGE using the specified file COW
Note that this version of the utility handles a special set of Cow-derived FileCow objects. The HeiferGenerator will automatically create FileCow objects (using the FileCow constructor) from files in the “cows” directory.
>cowsay -l
Regular cows available: heifer kitteh dragon ice-dragon File cows available: moose turkey turtle tux
Previous Work
The following classes, developed previously, are required for this lab to function.
Cow
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 (extends Cow)
public Dragon(const string& _name, const string& _image) // Constructor
public bool canBreatheFire() // Defaults to true
IceDragon (extends Dragon)
public Dragon(const string& _name, const string& _image) // Constructor
public bool canBreatheFire() // Returns false
FileCow Class
The FileCow class must be derived from the Cow class. In addition, FileCow must add the following behavior:
public FileCow(const string& _name, const string& filename)
Constructor; creates a new FileCow object with the given name and an image loaded from filename. If the file cannot be loaded, it should throw a new std::ifstream::failure exception object with the message "MOOOOO!!!!!!". This should be the only public constructor for the FileCow class!
public void setImage()
Should throw a new std::runtime_error exception object with message "Cannot reset FileCow Image".
Submissions
NOTE: Your output must match the example output *exactly*. If it does not, you will not receive full credit for your submission!
Files: rotc.zip
Method: Submit on Canvas
Compressed Archive (rotc.zip)
Your compressed file should have the following directory/file structure:
rotc.zip rotc (directory)
CMakeLists.txt
Cow.h
Dragon.h
FileCow.h
IceDragon.h
(Other sources / folders)
Sample Output
>javac Cowsay.java
>java Cowsay Hello World!
Hello World!
^__^
(oo)_______
(__) )/
||----w |
|| ||
>java Cowsay -n kitteh Moew-Moew!
Moew-Moew!
("`-' '-/") .___..--' ' "`-._
` *_ * ) `-. ( ) .`-.__. `)
(_Y_.) ' ._ ) `._` ; `` -. .-'
_.. `--'_..-_/ /--' _ .' ,4
( i l ),-'' ( l i),' ( ( ! .-'
>java Cowsay -l
Regular cows available: heifer kitteh dragon ice-dragon
File cows available: moose turkey turtle tux
>java Cowsay -n ninja Hello world!
Could not find ninja cow!
>java Cowsay -f tux Do you have any herring?
Do you have any herring?
.--.
|o_o |
|:_/ |
//
(| | ) /'_ _/` ___)=(___/
>java Cowsay -f alien Earth is ours!
Could not find alien cow!
>java Cowsay -f kitteh MEOW!!!
Could not find kitteh cow!
>java Cowsay -n tux How about tuna?
Could not find tux cow!