21.8 Programming Exercises

I l @ ve RuBoard

Exercise 21-1: Combine the checkbook class of Exercise 13-2 with the queue class of Exercise 13-3 to implement a checkbook class that can print out the last ten entries of your checkbook .

Exercise 21-2: Define a "string-match" base class.

 class string_matcher {     public:         // Returns true if string matches, false if not         int match(const char *const match); ... 

Define derived classes that match words, numbers , and blank strings.

Exercise 21-3: Define a base class shape that can describe any simple shape, such as a square, circle, or equilateral triangle. The size of all these shapes can be reduced to a single dimension.

Define derived classes for each of the three shapes.

Create a virtual function in the base class that returns the area of each shape.

Note that you will need to more precisely define what dimensions are stored in the base class. (Is the size in the base class for circle the radius of the circle or the diameter?)

Exercise 21-4: Write a base class called pet that describes any common household pet. Define two derived classes called fish and dog with items specific to that type of animal. Write pure virtual functions in the base class for operations that are common to both types of animals yet are handled in different ways by each of them.

Exercise 21-5: Write a base class number that holds a single integer value and contains one member function, print_it . Define three derived classes to print the value in hex, octal, and decimal.

I l @ ve RuBoard


Practical C++ Programming
Practical C Programming, 3rd Edition
ISBN: 1565923065
EAN: 2147483647
Year: 2003
Pages: 364

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net