Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that creates a class hierarchy for simple geometry. 1. Start with a Point class to hold x and y values of a

Write a program that creates a class hierarchy for simple geometry.

1. Start with a Point class to hold x and y values of a point. Overload the << operator to print point values, and the + and operators to add and subtract point coordinates (Hint: keep x and y separate in the calculation).

2. Create a pure abstract base class Shape, which will form the basis of your shapes. The Shape class will contain abstract functions to calculate area and circumference of the shape, plus provide the coordinates (Points) of a rectangle that encloses the shape (a bounding box). These will be overloaded by the derived classes. Create a display() function that will display the name of the class, and all stored information about the class (including area, circumference, and bounding box).

3. Build the hierarchy by creating the Shape classes Circle, Square, and Triangle. For these derived classes, create default constructors, and constructors whose arguments can initialize the shapes appropriately using the correct number of Point objects (i.e., Circle requires a Point center and a radius, Square requires four Point vertices, while Triangle requires three Point vertices).

4. In main(), create one instance each of the following: Circle (10, -5) with a radius of 23; Square (5, -5)(-10,7)(4,23)(-6,12); and Triangle(0,0)(10,10)(-15,15). Display the information from each object.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is meant by decentralisation of authority ?

Answered: 1 week ago

Question

Briefly explain the qualities of an able supervisor

Answered: 1 week ago

Question

Define policy making?

Answered: 1 week ago

Question

Define co-ordination?

Answered: 1 week ago

Question

What are the role of supervisors ?

Answered: 1 week ago