This assignment will give you practice with inheritance.
Use the following 5 classes for your solutionClass | Description |
Location | Represents the x-y coordinates of Shape class
objects Should contain two doubles Add an overloaded insertion operator for this class |
Shape | Base class Should contain 3 members: a Location, color (string) and type (string) Add an overloaded insertion operator for this class |
Square | Derived from Shape Add an area function |
Circle | Derived from Shape Add an area function |
Triangle | Derived from Shape Add an area function |
int main() { cout << setprecision(2) << fixed << left; Shape sh(4,5,"red"); cout << sh << " area = " << sh.area() << endl; cout << endl; Square sq1(1.0,2.0,3.1,"green"); cout << sq1 << " area = " << sq1.area() << endl; Square sq2(1.5,2.5,3.2,"lime green"); cout << sq2 << " area = " << sq2.area() << endl; Square sq3(6.7,0.0,3.3,"chartreuse"); cout << sq3 << " area = " << sq3.area() << endl; cout << endl; Circle c1(0.0,2.0,3.4,"blue"); cout << c1 << " area = " << c1.area() << endl; Circle c2(0.0,2.0,3.5,"peacock blue"); cout << c2 << " area = " << c2.area() << endl; Circle c3(0.0,2.0,3.6,"sapphire"); cout << c3 << " area = " << c3.area() << endl; cout << endl; Triangle t1(1.4,2.0,1.1,1.2,1.3,"red"); cout << t1 << " area = " << t1.area() << endl; Triangle t2(1.23,2.0,3,4,5,"cardinal red"); cout << t2 << " area = " << t2.area() << endl; Triangle t3(4.56,2.75,1,1,1,"crimson"); cout << t3 << " area = " << t3.area() << endl; } |
shape red (4.00,5.00) area = n/a Square green (1.00,2.00) area = 9.61 Square lime green (1.50,2.50) area = 10.24 Square chartreuse (6.70,0.00) area = 10.89 Circle blue (0.00,2.00) area = 36.32 Circle peacock blue (0.00,2.00) area = 38.48 Circle sapphire (0.00,2.00) area = 40.72 Triangle red (1.40,2.00) area = 0.61 Triangle cardinal red (1.23,2.00) area = 6.00 Triangle crimson (4.56,2.75) area = 0.43 |