当前位置: 首页>>代码示例>>C++>>正文


C++ Shape::Area方法代码示例

本文整理汇总了C++中Shape::Area方法的典型用法代码示例。如果您正苦于以下问题:C++ Shape::Area方法的具体用法?C++ Shape::Area怎么用?C++ Shape::Area使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Shape的用法示例。


在下文中一共展示了Shape::Area方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

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;
}
开发者ID:highlightz,项目名称:Learn-C-CPP,代码行数:12,代码来源:polymorphism.cpp

示例2: main

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 = &square;
   cout << "\nSquare: ";
   p->Display();
   cout << "Square: ";
   cout << "Area = " << p->Area() << endl << endl;

   func(circle);
   func(rec);
   func(square);

   return 0;

}
开发者ID:nrichgels,项目名称:ClassCode,代码行数:43,代码来源:main.cpp

示例3: test_three

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) ;

}
开发者ID:lirui79,项目名称:CProject,代码行数:36,代码来源:main.c

示例4: func

void func(const Shape& s)
{
   s.Display();
   cout << "Area = " << s.Area() << endl << endl;
}
开发者ID:nrichgels,项目名称:ClassCode,代码行数:5,代码来源:main.cpp


注:本文中的Shape::Area方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。