Assignment 11 - Polymorphic Quadrilaterals

due Tuesday, December 8th, 1:45 pm.  This assignment is not accepted late.

This assignment will give you practice with inheritance and polymorphism.

Class Hierarchy

Class Descriptions

Class Description
Quadrilateral Abstract base class
Contains 4 double members for the sides and a string for the type
Kite Derived from Quadrilateral
Pairs of adjacent sides equal
Contains 1 double member, p, for a diagonal
Rectangle Derived from Quadrilateral
Opposite sides equal
Square Derived from Rectangle
All 4 sides are equal
Trapezoid Derived from Quadrilateral
Sides a and c are parallel
Contains a double height member (calculated using 4 sides)
IsoscelesTrapezoid Derived from Trapezoid
Legs (b and d) are equal
Parallelogram Derived from Trapezoid
Opposite sides are equal
Rhombus Derived from Parallelogram
All 4 sides are equal

Input File (updated 12/2)

ki 1.5 2.7 2.3
tr 5.5 2.2 5.3 2.3
it 6.7 2.1 6
pa 4.5 6.7 1.5
rh 7.1 1.0
re 25 2.5
sq 1.7
ki 1 2 1.5
ki 3 4 1
...


Input File Description


Data Type Code Data Description
Kite ki 3 doubles: 2 sides (a and b) and a diagonal (p)
Trapezoid tr 4 doubles: 2 bases (a and c), 2 legs (b and d)
IsoscelesTrapezoid it 3 doubles: 2 bases (a and c), 1 leg (b)
Parallelogram pa 3 doubles: 2 adjacent sides (a and b), and a height (h)
Rhombus rh 2 doubles: a side (a) and a height (h) 
Rectangle re 2 doubles: 2 adjacent sides (a and b)
Square sq 1 double: a side (a)

Program Requirements

Area Formulas

Data Type Area Formula
Kite
Area = 1/2 * p * q
Trapezoid
Area = 1/2 * h * (a + c)
IsoscelesTrapezoid Area function is inherited
Parallelogram Area = a * h
Rhombus Area function is inherited
Rectangle Area = a * b
Square Area function is inherited

Suggested main function

int main()
{
    // Open input file
    Quadrilateral* ptrQuad;

         // Process each line from the input file
    while (fin >> code)
    {
        if (code == "ki")
        {
           ...
        }
        if (code == "tr")
        {
            ...
        }
        if (code == "it")
        {
            ...
        }

        ...

        cout << *ptrQuad << endl;

        ...
    }

}

Program Output

Kite:                sides:  1.5  2.7  2.7  1.5  area:  3.92  perimeter:   8.4
Trapezoid:           sides:  5.5  2.2  5.3  2.3  area: 10.51  perimeter:  15.3
Isosceles Trapezoid: sides:  6.7  2.1  6.0  2.1  area: 13.15  perimeter:  16.9
Parallelogram:       sides:  4.5  6.7  4.5  6.7  area:  6.75  perimeter:  22.4
Rhombus:             sides:  7.1  7.1  7.1  7.1  area:  7.10  perimeter:  28.4
Rectangle:           sides: 25.0  2.5 25.0  2.5  area: 62.50  perimeter:  55.0
Square:              sides:  1.7  1.7  1.7  1.7  area:  2.89  perimeter:   6.8
Kite:                sides:  1.0  2.0  2.0  1.0  area:  1.89  perimeter:   6.0
Kite:                sides:  3.0  4.0  4.0  3.0  area:  3.46  perimeter:  14.0

...