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: 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:
  1. g++ -ansi -Wall -c Dog.cpp
  2. g++ -ansi -Wall -c Lab3.cpp
  3. 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):
  1. Create a vector of dogs
  2. Push back at least 5 different dogs with varying ages
  3. Print out each dog's name along with its age
  4. Sort the vector of dogs by age
  5. Print out each dog's name along with its age