Write your question here.Hello,
I am stuck on this assignment question and am unsure as to how to get started.
Could anyone help me get started?
This is the question,
1. Write a program that creates a class hierarchy for simple geometry.
a. 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).
b. Create a base class Shape which will form the basis of your shapes. The Shape class will contain 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 as necessary.
Create a display() function that will display the name of the class plus all stored information about the class (including area, circumference, and bounding box).
c. 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: a Circle with a radius of 23, a Square with sides 25, and a Triangle with sides 10, 20, 30. Define all of them so that the origin (0,0) is somewhere within each object. Display the information from each object.
Below is what I have so far. I'm having troubles understanding how to get area from pointers. Can I just get the difference between points and multiply them? I thought pointers pointed to an address in the memory in hexadecimal? A little confused on where to go from here.Thanks everyone!
Thanks
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
class Point{
public:
double x, y;
ostream &operator >> (ostream &os, const Point &p);
Point &operator+(const Point&rhs);
Point &operator-(const Point &rhs);
private:
};
class Shape{
public:
double area();
double circumference ();
void boundingBox(Point &top, Point &left, Point &right, Point &bottom);
};
int main()
{
return 0;
}
|