Assignment Instructions

  1. Edit, compile, and run the following program on the UH UNIX shell:
    1. Create a base class called Circle for storing the radius and calculating the area of a circle.
    2. Create a derived class called Cylinder (which inherits all data members and member functions of class Circle) for storing the radius (in base class Circle) and height and calculating the area (surface area) and volume of a cylinder.
    3. Include appropriate set() and get() methods.
    4. In the public section of the Circle class, include this code for the value of Pi:
      static const double PI = 3.1415926;
    5. In the driver program (main() function), create at least three (3) Circles and/or Cylinders and test all of the member functions for both classes.
    6. 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

Test Circle class constructor and area() function:
Circle cir1: radius=10
area of cir1 = 314.159

Test set and get methods for class Circle:
Circle cir2: radius=12
get data members for cir2: 12

Test Cylinder class constructor, area(), and volume() functions:
Cylinder cyl1: radius=20 height=30
area of cyl1 = 6283.19
volume of cyl1 = 37699.1

Test set and get methods for class Cylinder:
Cylinder cyl2: radius=40 height=50
get data members for cyl2: 40, 50

Click to validate the HTML code

Click to validate the CSS code