我把你说的都去掉了,只保留的最简单的部分,还有疑问可以给我线上留言。因为用到了输出函数cout,所以必须有#include
#include
using namespace std;
class CPoint
{
public:
double x,y,z;
};
class CCircle:public CPoint
{
public:
double radius,area;
void cal_area();//计算面积
};
void CCircle::cal_area()
{
double pi=3.14159265;
area=pi*radius*radius;
}
class CCylinder:public CCircle
{
public:
double height,volume;
void cal_volume();//计算体积
};
void CCylinder::cal_volume()
{
volume=area*height;
}
void main()
{
cout<<"create a point"<
p.x=1;
p.y=2;
p.z=3;
cout<<"The coordinate of P is:"<
cout<
c.radius=2;//设置圆半径为2
c.cal_area();
cout<<"The area of the circle is:"<
cout<
cy.radius=2;//设置圆柱半径为2
cy.cal_area();
cy.height=4;//设置圆柱高度为4
cy.cal_volume();
cout<<"The volume of the cylinder is:"<
}
下面是原来的版本
给你写了个简单的例子
#include
using namespace std;
class CPoint
{
public:
double x,y,z;
void input_coordinate(double a,double b,double c);//输入三个坐标
void print_coordinate();//输出
};
void CPoint::input_coordinate(double a,double b,double c)
{
x=a;
y=b;
z=c;
}
void CPoint::print_coordinate()
{
cout<<"x coordinate:"<
class CCircle:public CPoint
{
public:
double radius,area;
void cal_area();//计算面积
void print_area();//输出
};
void CCircle::cal_area()
{
double pi=3.14159265;
area=pi*radius*radius;
}
void CCircle::print_area()
{
cout<<"Radius is:"<
class CCylinder:public CCircle
{
public:
double height,volume;
void cal_volume();//计算体积
void print_volume();//输出
};
void CCylinder::cal_volume()
{
volume=area*height;
}
void CCylinder::print_volume()
{
cout<<"radius is:"<
void main()
{
cout<<"create a point"<
p.input_coordinate(1,2,3);//输入坐标[1,2,3]
p.print_coordinate();
cout<
c.input_coordinate(1,2,3);//输入坐标[1,2,3]
c.print_coordinate();
c.radius=2;//半径为2
c.cal_area();
c.print_area();
cout<
cy.input_coordinate(1,2,3);//输入坐标[1,2,3]
cy.print_coordinate();
cy.radius=2;//半径为2
cy.cal_area();
cy.height=4;//高度为4
cy.cal_volume();
cy.print_volume();
}