Activity #2

The Pet Shops

Activity Type: drama

Discipline: programming

Area: Object-Oriented Programming

Purpose:
To increase the understanding of data encapsulation, and the interaction of objects, class functions, and the main driver program.

Time needed (estimate): 30-40 minutes

Description:
The program has one class - the pet shop. Each class has four data values for the number of dogs, cats, fish, and birds that the pet shop has to sell. There are 4 member functions to increase the number of each type of pet called BuyDogs(int), BuyCats(int), etc. There are 4 memeber functions that decrease the number of each type of pet called SellDogs(int), etc. There are also member functions that will return HowManyDogs, HowManyCats, etc. the pet shop has.

A main driver program declares three objects of the class petshop, and then proceeds to manipulate them by buying and selling dogs, cats, fish and birds.

To use the program in class, print either code or english descriptions on slips of paper to be distributed to students in the class. I usually give one student all of the Buy functions, another the Sell, etc. I also break up the main program into individual instructions that also get passed out to the class. The number of slips I produce is based on the number of students in the class, since I want each student to be involved in the drama. The slips of paper that are produced from the program are numbered in the order that they are to be done.

When class time arrived, I put up a transparency with the program code. We then begin to step through it executing it a line at a time. I use a paper lunch bag for each of the pet shop objects, and we write the name of the object on the outside of the bag. I also create sheets of paper with black and white pictures of a dog, cat (lion), bird (owl), and a fish. When a pet store has 5 dogs in stock, we put five pictures of a dog in that bag.

As the activity progresses, students see that only member functions get to look in the bag, and they also see that there is one copy of each function that all of the objects use.

I usually do this about half way through CS1 - Intro to Programming. Students report that they understand classes much better after this activity. They also suggest I do it earlier in the semester, but I feel that until they have stuggled with the concept, the activity will not mean much to them.

Materials needed: a program on slips of paper, bag, and pictures -- some significant preparation time is required.


Submitted by Jeffrey J. McConnell on Wednesday, August 27, 1997 at 14:21:06 EDT/EST.


After you have tried this activity, you can add feedback on how it worked for you

You can also read the feedback of others who tried this activity


Return to the Activities List