Hi All,
I am working on a problem where I am meant to create a Point class, and then use these objects to pass into a Shape class hierarchy. I am comfortable with the concepts of derived classes, and overiding/virtual functions and operator overloading.
What is giving me problems is the idea of Points, with X/Y co ordinates, and passing them into functions, particularly constructors of the class hierarchy.
I was trying to think about how to define the Circle constructor there. I'm looking to have the Circle constructor accept two point objects as arguments, and set one to c1(center point) and c2(a point on the perimeter, or radius marker)
So then I do now need to define lines 31-33? I can go ahead and start making geometric functions (area, circumference etc...)
and in main:
int main() {
Point pt0(0, 0); // Point Center
Point pt1(0, 23); // Radius
Circle oc; //create a circle object, ( or can I overload the constructor here? Circle oc(&pt1, &pt2)
oc.Circle(pt 0, pt1) // call the constructor?
class Point{
public:
int x;
int y;
Point(int px, int py): x(px), y(py){}
friend ostream &operator << (ostream &stream, Point &p);
Point operator+(const Point& pt);
Point operator-(const Point& pt);
};
class Shape {
public:
virtualdouble area() = 0;
virtualdouble circumference() = 0;
virtualvoid display() = 0;
};
class Circle:: public Shape {
Point c1,c2;
public:
double distrad, area_c, circum_c;
Circle();
Circle(const Point &pt0, const Point &pt1): c1(pt1), c2(pt2){}
double area();
double circumference();
void display();
};
int main() {
Point pt0(0, 0); // Point Center
Point pt1(0, 23); // Radius
Circle oc; //create a circle object,? or
Circle oc(&pt1, &pt2);// think?
oc.Circle(pt 0, pt1); // call the constructor? not needed?
}
which of the last three lines is the proper way to create the object with the appropritate arguments?