Complete the Program
Your assignment is to learn how to use the Dog class. Download the files Dog.cpp and Dog.h and examine the code. Pay special attention to the interface file (Dog.h) since that is where all the class functions are defined.
Note: The lab files
(Dog.cpp, Dog.h, and
skeleton lab3.cpp) are also available on GL in the directory:
/afs/umbc.edu/users/c/m/cmarron/pub/cmsc202
You will modify the file lab3.cpp containing a main() function to use the Dog class in the following ways:
- Create at least two different dogs. You do this by simply declaring two variables of type Dog.
- Use the "Get" methods (accessors) to fetch the member values for one of the instances, and print them out.
- Give each Dog to a new owner using the appropriate class methods to set the owner for each to something interesting, then retrieve the owner and print it out to verify that it was changed successfully.
- Interact with your dogs to affect their happiness ratings. There is no direct way to set the happiness: you must modify it indirectly through the Scold() and Reward() methods.
- Get the dogs to talk to you.
As you go through these actions, use the appropriate accessors to fetch and output information about the dog to show that it changes. You should not have to modify the Dog class.
Use the following source file as the starting skeleton for your program. You will need to replace all of the blanks with code. You can cut-and-paste the skeleton code into your emacs buffer, or download the lab3.cpp skeleton.
// File: lab3.cpp // // Demonstrates uses the Dog class. // Compile together with Dog.cpp // #include <iostream> #include "Dog.h" using namespace std; int main() { // CREATE TWO OBJECTS OF THE "Dog" CLASS BY DECLARING VARIABLES // "dog1" AND "dog2" OF THAT CLASS TYPE: _________ dog1; _________ dog2; // PRINT THE INITIAL FIELD VALUES FOR THE dog1: cout << "dog1's original data:\n"; cout << " name is: " << dog1._______() << endl; cout << " age in 2016 is: " << dog1.______(____) << endl; cout << " owner is: " << dog1.________() << endl; // MODIFY dog1 AND dog2, BY USING THE APPROPRIATE Dog CLASS METHODS, // TO SET THE "owner" FIELD TO SOMETHING NEW, THEN FETCH THE FIELDS // BACK OUT AND PRINT cout << "Give the dogs to new owners:\n"; _____________________________________________; // set new owner for dog1 cout << "dog1's new owner is: " << dog1.________() << endl; _____________________________________________; // set new owner for dog2 cout << "dog2's new owner is: " << dog2.________() << endl; // iNTERACT WITH YOUR DOGS TO AFFECT THEIR HAPPINESS RATINGS, // BY USING THE Scold() AND Reward() METHODS cout << "Scold and reward a dog several times:\n"; // Fetch current happiness value and print it out cout << "dog1 starts out " << dog1.____________() << endl; // Now, scold dog1 once, then reward it twice, printing out the // happiness level after each change: ________________________; // scold the dog cout << "Scolded dog1: dog is now " << dog1.____________() << endl; ________________________; // reward the dog cout << "Rewarded dog1: dog is now " << dog1.____________() << endl; ________________________; // reward the dog cout << "Rewarded dog1: dog is now " << dog1.____________() << endl; // FINALLY, GET THE DOGS TO TALK TO YOU cout << "Asking dog1 to speak:\n"; dog1.____(); return 0; }