第1个回答 2013-10-21
#include<iostream.h>
#define pi 3.14
class Shape
{
public:
double area()
{
return a;
}
double grith()
{
return g;
}
protected:
double a;
double g;
};
class Cricle:public Shape
{
public:
double area(double x=2)
{
a=pi*x*x;
return a;
}
double grith(double x=2)
{
g=2*pi*x;
return g;
}
show()
{
cout<<"Shape Opject:"<<endl;
cout<<"Cricle"<<endl;
cout<<"area:"<<area()<<endl;
cout<<"grith:"<<grith()<<endl;
}
protected:
double g;
double a;
};
class Triangle:public Shape
{
public:
double area(double x=1,double y=2,double z=3)
{
a=0.5*x*y;
return a;
}
double grith(double x=1,double y=2,double z=3)
{
g=x+y+z;
return g;
}
show()
{
cout<<"Shape Opject:"<<endl;
cout<<"Tritangle"<<endl;
cout<<"area:"<<area()<<endl;
cout<<"grith:"<<grith()<<endl;
}
protected:
double a;
double g;
};
class Rectangle:public Shape
{
public:
double area(double x=1,double y=2)
{
a=x*y;
return a;
}
double grith(double x=1,double y=2)
{
g=2*(x+y);
return g;
}
show()
{
cout<<"Shape Opject:"<<endl;
cout<<"Tritangle"<<endl;
cout<<"area:"<<area()<<endl;
cout<<"grith:"<<grith()<<endl;
}
protected:
double a;
double g;
};
void main()
{
Cricle A;
A.show();
Triangle B;
B.show();
Rectangle C;
C.show();
}本回答被网友采纳