//File : shapes.h //Author : Andre Long //Due : November 3, 2004 //Description : Demonstate the concept of inheritence #include #include #include #include using namespace std; class shape { protected: float x; float y; public: shape() { x=0; y=0; } shape(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(shape test) { if(x==test.x && y==test.y) return true; else return false; } }; //Specifications for lines class line : public shape { 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(shape first, shape 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; } }; //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; float area; public: rectangle() { shape first(1,1); //default point values, which are objects shape two(1,1); shape third(1,1); shape fourth(1,1); float area=1; float m=0; bool rombus=true; bool rectangleObject=true; float perimeter=1; } rectangle(shape first, shape second, shape third, shape 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(); } area = (base)*(height); 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; } void setHeight(float h) { height=h; } void setBaes(float b) { base=b; } void setArea(float a) { area=a; } float getHeight() { return height; } float getBase() { return base; } float getArea() { return area; } float circumferance(line L1, line L2, line L3, line L4) { perimeter = (L1.lineDistance() + L2.lineDistance() + L3.lineDistance() + L4.lineDistance()); return perimeter; } }; //Specifications for cubes class cube : public rectangle { protected: float height; float base; float width; public: cube() { base=1; width=1; height=1; } cube(shape first, shape second, shape third, shape fourth) { shape pt1=first; shape pt2=second; shape pt3=third; shape pt4=fourth; rectangle rombus(pt1, pt2, pt3, pt4); base=rombus.getBase(); height=rombus.getHeight(); } void setBase(float B) { base=B; } void setWidth(float W) { width=W; } void setHeigth(float H) { height=H; } float getBase() { return base; } float getWidth() { return width; } float getArea() { return base*height; } float getHeigth() { return height; } float getVolume() { return (base)*(height)*(width); } };