//File : points.h //Author : Andre Long //Due : November 3, 2004 //Description : Demonstate the concept of inheritence #include #include #include #include using namespace std; class point { protected: float x; float y; public: point() { x=0; y=0; } point(float x_coordinate, float y_coordinate) { x=x_coordinate; y=y_coordinate; } void setX(float x_ordinate) { x=x_ordinate; } void setY(float y_ordinate) { y=y_ordinate; } float getX() { return x; } float getY() { return y; } bool compareTo(point test) { if(x==test.x && y==test.y) return true; else return false; } }; //Specifications for lines class line : public point { protected: float deltaX; float deltaY; float distance; float m; string slope; public: line() { deltaX=1; deltaY=1; slope="enter points and calculate"; distance=1; } line(point first, point second) { deltaX = (second.getX() - first.getX()); deltaY = (second.getY() - first.getY()); if(deltaX==0) slope="vertical line"; else m = (deltaY) / (deltaX); } float lineDistance() { distance = sqrt( pow(deltaX,2) + pow(deltaY,2) ); return distance; } void setDeltaX(float x) { deltaX = x; } void setDeltaY(float y) { deltaY = y; } float getDeltaX() { return deltaX; } float getDeltaY() { return deltaY; } float getDistance() { return distance; } float getM() { return m; } string getSlope() { return slope; } }; //abstract class class shape :public line { protected: public: virtual float area()=0; virtual void draw()=0; }; //Specifications for rectangles #include class rectangle : public shape { public: bool compareTo(); bool flag1; bool flag2; bool flag3; bool flag4; bool flag5; bool flag6; bool rombus; bool rectangleObject; float perimeter; protected: float x1; float x2; float x3; float x4; float y1; float y2; float y3; float y4; float height; float base; public: rectangle() { point first(1,1); //default point values, which are objects point two(1,1); point third(1,1); point fourth(1,1); //float area=1; float m=0; bool rombus=true; bool rectangleObject=true; float perimeter=1; } rectangle(point first, point second, point third, point fourth) { if(first.compareTo(second)) flag1=true; if(first.compareTo(third)) flag2=true; if(first.compareTo(fourth)) flag3=true; if(second.compareTo(third)) flag4=true; if(second.compareTo(fourth)) flag5=true; if(third.compareTo(fourth)) flag6=true; if(flag1==true || flag2==true || flag3==true || flag4==true || flag5==true || flag6==true) { cout<<"All points for rectangle must be unquie"< L2.getDeltaX() && L1.getDeltaX() > L3.getDeltaX() && L1.getDeltaX() > L4.getDeltaX()) { height = L1.getDeltaX(); } else if(L2.getDeltaX() > L3.getDeltaX() && L2.getDeltaX() > L4.getDeltaX() && L2.getDeltaX() > L1.getDeltaX()) { height = L2.getDeltaX(); } else if(L3.getDeltaX() > L4.getDeltaX() && L3.getDeltaX() > L1.getDeltaX() && L3.getDeltaX() > L2.getDeltaX()) { height = L3.getDeltaX(); } else if(L4.getDeltaX() > L1.getDeltaX() && L4.getDeltaX()> L2.getDeltaX() && L4.getDeltaX() > L3.getDeltaX()) { height = L4.getDeltaX(); } else { height = L1.getDeltaX(); } if(L1.getDeltaY() > L2.getDeltaY() && L1.getDeltaY() > L3.getDeltaY() && L1.getDeltaY() > L4.getDeltaY()) { base = L1.getDeltaY(); } else if(L2.getDeltaY() > L3.getDeltaY() && L2.getDeltaY() > L4.getDeltaY() && L2.getDeltaY() > L1.getDeltaY()) { base = L2.getDeltaY(); } else if(L3.getDeltaY() > L4.getDeltaY() && L3.getDeltaY() > L1.getDeltaY() && L3.getDeltaY() > L2.getDeltaY()) { base = L3.getDeltaY(); } else if(L4.getDeltaY() > L1.getDeltaY() && L4.getDeltaY()> L2.getDeltaY() && L4.getDeltaY() > L3.getDeltaY()) { base = L4.getDeltaY(); } else { base = L1.getDeltaY(); } if( (L1.getM()==L2.getM() || L1.getM()==L3.getM() || L1.getM()==L4.getM()) && (L2.getM()==L3.getM() || L2.getM()==L4.getM() || L2.getM()==L1.getM()) ) { rombus=true; if((L1.getDistance()==L2.getDistance() || L1.getDistance()==L3.getDistance() || L1.getDistance()==L4.getDistance()) && (L2.getDistance()==L3.getDistance() || L2.getDistance()==L4.getDistance() || L2.getDistance()==L1.getDistance())) { rectangleObject=true; } else rectangleObject=false; } else rombus=false; } virtual float area() { cout<(pi); const float pi= (float)3.14159; class circle: public shape { protected: float raduis; point centerPoint; public: circle() { raduis=1; } circle(point first, float raduis) { centerPoint = first; (*this).raduis=raduis; } virtual void draw() { cout<