## PIC 10B

(Sec. 1a-1b)

C++ Programming and Problem Solving

## Instructor: Ivo Dinov, Asst. Prof.Neurology, Mathematics, Statistics

 http://www.math.ucla.edu/~dinov/10b.1.011/

Due Date:

# Tuesday, 8:00 PM, Aug. 07, 2001

Please, submit your homework electronically using the "submit" system. Please try to follow the "good programming" conventions we discussed in class. Write modular code and include all of your functions in the same CPP file as your main.

• (HW_5_1.cpp/exe) Write a Point, Square, Cube program. Do this with inheritance much like we did the Point, Circle, Cylinder example in class. You need to provide at least as many member functions within each class as to gain the complete functionality we saw in class (e.g., printing objects of each type, interface methods for setting/getting private members, coordinates, areas, volume computation tools, etc.) We have the following basic inheritance relationships betweeen the three data types: Point <-- Square <-- Cube, in other words, Square extends Point and Cube objects extend Squares.

Sample Run:
%> This program illustrates the use of class-extensions, inheritance and polymorphism with the objects: Point <-- Square <-- Cube
%> The default settings are: X coordinate is 12,   Y coordinate is 23 and   Size of 2.5
%> The Cube printed as a Point is:[12,23]
%> The Cube printed as a Square is: Center =[12,23];Size =2.5 units
%> The area of the Square is 6.25 units2. The surface area of the Cube is 37.5 units2. The volume of the Cube is 15.625 units3
%> Would you like to enter a new set of parameters (Y/N)?
%> Y
%> Enter X and Y coordinates as integers and Size as a double, in that order.
%> 2 3 4.0
%> You entered: X coordinate is 2,   Y coordinate is 3 and   Size of 4.0
%> The Cube printed as a Point is:[2,3]
%> The Cube printed as a Square is: Center =[2,3];Size =4.0 units
%> The area of the Square is 16 units2. The surface area of the Cube is 96.0 units2. The volume of the Cube is 64.0 units3
%> Would you like to enter a new set of parameters (Y/N)?
%> N
%> Bye!

\Ivo D. Dinov, Ph.D., Department of Neurology and Program in Computing, UCLA School of Medicine/