Basic Structure
Your assignment is to learn how to use the Dog class, which is available as two attachments: (Dog.cpp, Dog.h). Download and save the attachments as your starting point. You should go and quickly examine those files now. We'll go into more details later.
You will then create a file called Lab5.cpp, which contains a main() function, that uses 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 it out
- Give each Dog to a new owner, by 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:
Notice that 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
Use the following source file as the starting skeleton for your program: (cut-and-paste it into your emacs buffer, then replace all of the "________" with actual code)
// File: Lab5.cpp // // Demonstrates uses the Dog class. // Compile together with Dog.cpp // #include <iostream> #include "Dog.h" using namespace std; int main(int argc, char *argv[]) { // 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 2014 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; }