admin 管理员组

文章数量: 887021


2024年1月10日发(作者:restful风格的缺点)

public:Sphere(void):_name("Sphere"), _radious(0.0){}virtual ~Sphere(void){}public:static const double PI;public:virtual void input(void);virtual double area(void) const;virtual double volume(void) const;virtual void display(void) const;private:const std::string _name; //本类名称,球体double _radious; //球体半径};const double Sphere::PI = 3.14159;void Sphere::input(void){cout>_radious;}double Sphere::area(void) const{return 4.0 * PI * _radious * _radious;}double Sphere::volume(void) const{double coefficient = 4 / 3;return coefficient*PI*_radious*_radious*_radious;}void Sphere::display(void) const{cout<<<

<}int main(int argc, char **argv){//设计菜单实现功能选择Shape *root = NULL;cout<<<>choice;switch(choice){case '1': root = new Sphere(); break;case '2': root = new Cube(); break;default: return 0;}while(1){system("cls");cout<<<<<>choice;switch(choice){case '1': root->input(); break;case '2': root->display(); break;case '3': cout

default: return 0;}}return 0;}


本文标签: 风格 球体 选择