﻿ ICS 212: Program Structure by William McDaniel Albritton

Assignment Instructions

1. Edit, compile, and run the following program on the UH UNIX shell:
1. Develop a Shape class hierarchy and define the following classes in the hierarchy: Shape, Circle, Sphere, Cylinder, Square, Cube, Triangle, and Tetrahedron.
2. From the abstract Shape class, derive concrete classes Circle, Square, and Triangle. From class Circle, derive concrete classes Sphere and Cylinder. From class Square, derive concrete class Cube. And from class Triangle, derive class Tetrahedron.
3. Use the following functions:
a. virtual char* name() const - returns the name of the class
b. virtual void printSize() const - display the area, or surface area & volume of the object
c. virtual void inputData() - ask the user for the radius, side, and/or height of the object and set the appropriate data member(s)
d. virtual double area() const - returns the area or surface area of the object
e. virtual double volume() const - returns the volume of the object
4. The assignment24.cpp file contains class Shape - an abstract base class containing the interface to the hierarchy (Note: DO NOT change the Shape class definition), a class definition for the class Circle, the main() function, and example output.
5. You should change the main() function when you first start testing your program. For example, you should create the class Circle first, and test all the functions to make sure that it is working correctly. After you've finished the program, you should put in the original main() function. In other words, turn in your program with the same main() function as the main() function that is already in the assignment24.cpp file.
6. For those rusty in geometry, here are some formulas:
PI = 3.14
cylinder's surface area = 2*(circle's area) + h*(circle's circumference)
cylinder's volume = h*(circle's area)

square's area = s*s
cube's surface area = 6*(square's area)
cube's volume = s*s*s

equilateral triangle's area = s*s*sqrt(3)/4
regular tetrahedron's surface area = 4*(equilateral triangle's area)
regular tetrahedron's volume = s*s*s*sqrt(2)/12
7. ** NOTE: The main error students make with this assignment is to repeat data unnecessarily. The point of inheritance is to be a lazy programmer and not reinvent the wheel. For example, if the base class Circle has a radius, the derived class Sphere does NOT need a radius, because it already has a radius, which is inherited from the base class Circle. Please keep this concept in mind when writing your code. **
8. Email your makefile and C program to the instructor, or show it to the instructor in class.
2. For the submission guidelines and the grading guidelines, see the syllabus.

Example I/O

Select an object from the menu (enter 7 to quit).
0. Circle
1. Sphere
2. Cylinder
3. Square
4. Cube
5. Triangle
6. Tetrahedron
0
The Circle's area = 314

Select an object from the menu (enter 7 to quit).
0. Circle
1. Sphere
2. Cylinder
3. Square
4. Cube
5. Triangle
6. Tetrahedron
1
The Sphere's surface area = 5024
The Sphere's volume = 33493.3

Select an object from the menu (enter 7 to quit).
0. Circle
1. Sphere
2. Cylinder
3. Square
4. Cube
5. Triangle
6. Tetrahedron
2
Enter the Cylinder's height: 40
The Cylinder's surface area = 13188
The Cylinder's volume = 113040

Select an object from the menu (enter 7 to quit).
0. Circle
1. Sphere
2. Cylinder
3. Square
4. Cube
5. Triangle
6. Tetrahedron
3
Enter the Square's side: 50
The Square's area = 2500

Select an object from the menu (enter 7 to quit).
0. Circle
1. Sphere
2. Cylinder
3. Square
4. Cube
5. Triangle
6. Tetrahedron
4
Enter the Cube's side: 60
The Cube's surface area = 21600
The Cube's volume = 216000

Select an object from the menu (enter 7 to quit).
0. Circle
1. Sphere
2. Cylinder
3. Square
4. Cube
5. Triangle
6. Tetrahedron
5
Enter the Triangle's side: 70
The Triangle's area = 2121.76

Select an object from the menu (enter 7 to quit).
0. Circle
1. Sphere
2. Cylinder
3. Square
4. Cube
5. Triangle
6. Tetrahedron
6
Enter the Tetrahedron's side: 80
The Tetrahedron's surface area = 11085.1
The Tetrahedron's volume = 60339.8

Select an object from the menu (enter 7 to quit).
0. Circle
1. Sphere
2. Cylinder
3. Square
4. Cube
5. Triangle
6. Tetrahedron
7