8054:根据题目要求填写代码B

Time/Memory Limit:1000 MS/32768 K
Submitted: 296 Accepted: 184

 Problem Description

根据题意,在自写代码处填写正确的代码,其中PI取3.14159.

#include <iostream.h>
class Shape{
public:
 virtual double perimeter()=0;
 virtual double area()=0;
private:
};
class Shape2D:public Shape{
public:
 Shape2D(double x,double y){
  /*自写代码*/
 }
private:
 double x;
 double y;
};

class Circle:public Shape2D{
public:
 Circle(double x,double y,double radius):Shape2D(x,y){
  /*自写代码*/
 }
public:
 virtual double area(){
  /*自写代码*/
 }
 virtual double perimeter(){
   /*自写代码*/
 }
private:
 double radius;
};

class Rectangle:public Shape2D{
public:
 Rectangle(double x,double y,double a,double b):Shape2D(x,y){
   /*自写代码*/
  }
public:
 virtual double area(){
   /*自写代码*/
 }
 virtual double perimeter(){
   /*自写代码*/
 }  
private:
 double a;
 double b;
};
//test
int main(){
 double x1,y1,radius;
 double x2,y2,a,b;
 cin>>x1>>y1>>radius;
 cin>>x2>>y2>>a>>b;
 //
 Circle c(x1,y1,radius);
 Rectangle rect(x2,y2,a,b);
 //
 Shape* pShapeArray[]={/*自写代码*/};
 //
 for (int i=0;i<2;i++){
  cout<<"perimeter:"<<pShapeArray[i]->perimeter()<<endl;
  cout<<"area:"<<pShapeArray[i]->area()<<endl;
 }
 return 0;
}
 

 Input

输入7个double型数据,数据之间用空格分隔.

 Output

输出格式由程序已经限定.

 Sample Input

1.1 2.2 1.0 3.3 4.4 2.0 3.0

 Sample Output

perimeter:6.28318
area:3.14159
perimeter:10
area:6

 Author

wtf

 Recommend

zh