#include <iostream>
using namespace std;
const double PI=3.14;
class shape
{
public:
virtual double Perimeter()=0;
virtual double area()=0;
virtual double volume()=0;
};
class Squar:virtual public shape
{
protected:
double a;
public:
Squar(double x)
{ a=x;}
double Perimeter()
{ return 4*a; }
double area()
{ return a*a; }
};
class Diamond:virtual public shape
{
protected:
double a;
double b;
public:
Diamond(double x,double y)
{ a=x;
b=y;}
double Perimeter()
{ return 2*b*a; }
//{ return 2*b; }怎样把根号打出来
double area()
{ return 0.5*a*b; }
};
class Circle:virtual public shape
{
protected:
float r;
public:
Circle(double x)
{ r=x;}
double Perimeter()
{ return 2*PI*r; }
double area()
{ return PI*r*r; }
};
class Cylinder:virtual public Circle
{
protected:
double h;
public:
Cylinder (double x,double y):Circle(x)
{ h=y; }
double area()
{ return 2*PI*r*(h+r); }
double volume()
{ return PI*r*r*h; }
};
int main ( )
{ Squar s(2.1);
Diamond d(4.1,3.1);
Circle c(3.1);
Cylinder m(4.1,2.1);
Shape *p;
p=&s;
cout<<"the Perimeter of Squar is :"<<p->Perimeter()<<endl;
cout<<"the area of Squar is :"<<p->area()<<endl;
p=&d;
cout<<"the Perimeter of Diamond is :"<<p->Perimeter()<<endl;
cout<<"the area of Diamond is :"<<p->area()<<endl;
p=&c;
cout<<"the Perimeter of Circle is :"<<p->Perimeter()<<endl;
cout<<"the area of Circle is :"<<p->area()<<endl;
p=&m;
cout<<"the area of Cylinder is :"<<p->area()<<endl;
cout<<"the volume of Cylinder is :"<<p->volume()<<endl;
return 0;
}
哪位帮我看一下,怎么得不出答案,(总共就三类错误!)