Computer Science and Programming
Rowan
University
Prof. Gregory Safko
Assigned: April 30, 2003
Due April 30, 2003
Finish writing the remaining objects in last week's lab (rhombus.cpp and parallelogram.cpp). Write their (virtual) function area, which will return the area of the given quadrilateral. The other files (quad.cpp, rect.cpp, square.cpp, and trap.cpp, as well as their header files) are found here. As a reminder, the areas of the following quadrilaterals area:
Trapezoid: Area = (base 1 + base 2) * height / 2
Parallelogram: Area = base * height
Rectangle: Area = height * base
Rhombus: Area = base * height
Square: Area = base * base
Add a polymorphic perimeter method to the family of quadrilateral objects. Use the minimum number of variables to compute the perimeter.
Create a menu system where the user will select a shape (Trapezoid, Parallelogram, Rectangle, Rhombus, or Square). Based on what the user selected, the computer will prompt the user for data, and report the objects area and perimeter.
Here is an example: (User input is underlined here for illustration only. Also note if they want to select a Parallelogram, for example, then they just type 'P', 'p', or 2)
Welcome to the Quadrilateral Program!
Please select a shape:
1. (T)rapezoid
2. (P)arallelogram
3. (R)ectangle
4. R(h)ombus
5. (S)quare
6. (Q)uit
Enter your Selection: H
Enter a base for the Rhombus: 4
Enter a height for the Rhombus: 3
The area is 12The perimeter is 16
Welcome to the Quadrilateral Program!
Please select a shape:
1. (T)rapezoid
2. (P)arallelogram
3. (R)ectangle
4. R(h)ombus
5. (S)quare
6. (Q)uit
Enter your Selection: 1
Enter base 1 for the Trapezoid: 6
Enter base 2 for the Trapezoid: 3
Enter height for the Trapezoid: 2
Enter leg 1 for the Trapezoid: 3
Enter leg 2 for the Trapezoid: 3
The area is 9The perimeter is 15
Welcome to the Quadrilateral Program!
Please select a shape:
1. (T)rapezoid
2. (P)arallelogram
3. (R)ectangle
4. R(h)ombus
5. (S)quare
6. (Q)uit
Enter your Selection: W
Invalid Selection!
Welcome to the Quadrilateral Program!
Please select a shape:
1. (T)rapezoid
2. (P)arallelogram
3. (R)ectangle
4. R(h)ombus
5. (S)quare
6. (Q)uit
Enter your Selection: q
Goodbye
Press any key to continue
(Hint: A switch/case structure would be your best tool to use in creating a menu system)
(Hint: You may want to write a virtual polymorphic getData( ) method for each of your objects, since each object's data needs are different)