Question: CSCI 15, Lab Assignment 7 Abstract Classes Abstract classes provide an interface to capabilities and behavior of class members without having to create one set

CSCI 15, Lab Assignment 7

Abstract Classes

Abstract classes provide an "interface" to capabilities and "behavior" of class members without having to create one set customized class for that one group. The class may have a few differences BUT have lot of common capabilities (class functions) and characteristics (class variables). Abstract allows us to customize a class based on a base class. An abstract class has at least one virtual class.

Different classes inherit the base class functions but

Determine the Area of the following geometric shapes:

Rectangle Width X Height

Triangle (Width X Height) / 2.0

Cylinder (2 X PI X Width X Height) + (2 X PI X Width X Width)

PI = 3.14159

Trapezoid ((Width1 + Width2) / 2.0) X Height

Circle PI X Width X Width

The base class functions:

Sets the Width

Sets the Height

The virtual function computes the area of the object

You might wish to use a menu interface to allow the user to run any or all of the objects

Example Output:

Determine the Area of the Objects:

1 - Rectangle

2 - Triangle

3 - Cylinder

4 - Trapezoid

5 - Circle

6 - Quit

Enter Option (1 - 6): 1

Rectangle Object

1 of 2 - Enter the Height for the Rectangle: 23.4

2 of 2 - Enter the Width for the Rectangle: 33.4

Total Rectangle area for 23.4 Height by 33.4 Width is : 781.56

Hit Any Key to continue...

Circle Object

1 of 1 - Enter the Radius of the Circle: 67.8

Total Circle area for pi X 67.8 X 67.8 is: 14442.8

Triangle Object

1 of 2 - Enter the Height for the Triangle: 11.7

2 of 2 - Enter the Width for the Triangle: 4.5

Total Triangle area for (11.7 X 4.5) / 2 is: 26.325

Cylinder Object

1 of 2 - Enter the Height for the Cylinder: 6.8

2 of 2 - Enter the Radius for the Triangle: 5.5

Total Cylinder area for ( 2 X pi X 5.5 X 6.8) + ( 2 X pi X 5.5 ^ 5.5) is : 425.099

Try this values to confirm that the formulas are probably correct: (precision depends on what you set it to display and PI (i.e. how many decimals accuracy, 3.14, 3.1416, 3.14159 etc.)

Rectangle Width = 2, Height = 4 Area = 8

Triangle Height = 3.5, Base = 5.6 Area = 9.8

Cylinder Height = 2, Radius = 3 Area = 94.2477

Trapezoid Height = 4, Base1 = 5.6, Base2 = 3.4 Area = 18

Circle Radius = 5 Area = 78.5397

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!