UMBC CMSC 202 Computer Science II
Lab3: Introduction to C++ Classes
In this lab you will learn how to use classes.
Discussion
Topics:
C++ Classes Assignment: Dog
Your assignment is to learn how to use the Dog class (Dog.cpp, Dog.h).
Assignment: Write a main() function, in a file called Lab3.cpp, that uses the Dog class in the following ways:
- Create at least two different dogs
- Give the dogs to people
- Abuse and pat the dogs several different times
- Talk to the dogs
As you go through these actions, use the appropriate accessors to show information about the dog as it changes. You should not have to modify the Dog class.
Compiling: To compile your assignment, use the following commands:
g++ -ansi -Wall -c Dog.cpp
g++ -ansi -Wall -c Lab3.cpp
g++ -ansi -Wall -o Lab3 Dog.o Lab3.o
Sample Output:
Here is a sample output. Note that the assignment directions require you to do more than this.
Creating dogs...
Dog1's name is: grep
Dog2's name is: Dr. Pepper
Dog1's age is 32 years
Setting Dog2's owner to Red Bull
Dog2's owner is Red Bull
Abusing Dog2...
Abusing Dog2...
Abusing Dog2...
Abusing Dog2...
Abusing Dog2...
Abusing Dog2...
Abusing Dog2...
Dog2 is sad
Dog1 says woof
Extra Credit (4 points):
- Create a vector of dogs
- Push back at least 5 different dogs with varying ages
- Print out each dog's name along with its age
- Sort the vector of dogs by age
- Print out each dog's name along with its age