int main( ) { Shape* pShape = 0; pShape = new Circle( 10 ); cout << "Circle的面积是:" << pShape->Area( ) << endl; delete pShape; pShape = 0; pShape = new Rect( 5, 6 ); cout << "Rect的面积是:" << pShape->Area( ) << endl; delete pShape; return 0; }
int main() { Circle circle(2.5, 37, 43); cout << "Circle: "; circle.Display(); cout << "Circle area: " << circle.Area() << endl << endl; Rectangle rec(2,4,8,9); cout << "Rectangle: "; rec.Display(); cout << "Rectangle area: " << rec.Area() << endl << endl; Square square(4,6,5); cout << "Square: "; square.Display(); cout << "Square area: " << square.Area() << endl << endl; Shape* p; p = &circle; cout << "Circle: "; p->Display(); cout << "Circle: "; cout << "Area = " << p->Area() << endl; p = &rec; cout << "\nRectangle: "; p->Display(); cout << "Rectangle: "; cout << "Area = " << p->Area() << endl; p = □ cout << "\nSquare: "; p->Display(); cout << "Square: "; cout << "Area = " << p->Area() << endl << endl; func(circle); func(rec); func(square); return 0; }
void test_three() { Circle *circle ; Point *point ; Shape *shape ; IMethod *ptr ; double area = 0.0 ; circle = New(Circle) ; circle->Set(circle , 10.0 , 20.0) ; circle->Move(circle , 100.0 , 300.0) ; circle->Position(circle) ; circle->SetRadius(circle , 30.0) ; area = circle->Area(circle) ; circle->SetCircle(circle , 1.0 , 2.0 , 3.0) ; shape = (Shape*)circle ; shape->Position(shape) ; area = shape->Area(shape) ; point = (Point*)circle ; point->Move(point , 1000.0 , 2000.0) ; point->Position(point) ; circle->AddRadius(circle , 50.0) ; area = point->Area(point) ; ptr = (IMethod*)circle ; // area = ptr->Area() ; ptr->GetClassName() ; Delete(ptr) ; }
void func(const Shape& s) { s.Display(); cout << "Area = " << s.Area() << endl << endl; }