📄 qingqing1.cpp
字号:
#include"iostream.h"
#include"math.h"
class circle //圆类的定义(抽象类)
{private:
float f_mr;
public:
circle()//构造函数;
{f_mr=0;
}
~circle()//构析函数
{cout<<" now destory the object of circle!"<<endl;
}
virtual float area(float r)=0;//纯虚函数
virtual float volume(float r)=0;//纯虚函数
};
class yuanzhu:public circle//定义圆柱类;
{private:
float f_mh1;
public:
yuanzhu(float r,float h1):circle()//构造函数;
{f_mh1=0;
}
~yuanzhu()//构析函数
{cout<<"yuanzhu类对象已被撤消"<<endl;
}
float area(float r,float h1);
float volume(float r,float h1);
};
float yuanzhu::area(float r,float h1)
{return 2*3.14*r*r+2*3.14*r*h1;
}
float yuanzhu::volume(float r,float h1)
{return 3.14*r*r*h1;
}
class zhui:public circle//定义圆锥类;
{private:
float f_mh2;
public:
zhui()//构造函数;
{f_mh2=0;
}
~zhui()//构析函数
{cout<<"now destroying the object of zhui!"<<endl;
}
float area(float r,float h2);
float volume(float r,float h2);
};
float zhui::area(float r,float h2)
{return 3.14*r*r+3.14*r*sqrt(r*r+h2*h2);
}
float zhui::volume(float r,float h2)
{return (1.0/3.0)*3.14*r*r*h2;
}
void main()
{float r,h1,h2;
cout<<"请输入圆的半径、圆柱的高、圆锥的高:"<<endl;
cin>>r>>h1>>h2;
yuanzhu *y;
zhui *z;
cout<<"圆柱的表面积:"<<y->area(r,h1)<<endl;
cout<<"圆柱的体积:"<<y->volume(r,h1)<<endl;
cout<<"圆锥的表面积:"<<z->area(r,h2)<<endl;
cout<<"圆锥的体积:"<<z->volume(r,h2)<<endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -