一个C++程序能在XP系统完整地显示所有内容,但在WIN8和WIN10不能完整地显示
#include
#include
#include
#define PI 3.1415
using namespace std;
//radius 半径,length 长度 width宽度 heighr 高度
class shape//基类
{
public:
virtual double area()=0;//定义纯虚函数
virtual double volume()=0;//定义纯虚函数
virtual double surface()=0;//定义纯虚函数
virtual double zhouchang()=0;//定义纯虚函数
};
class circle:public shape//圆形
{
protected:
double radius;
public:
circle(double r){radius=r;}
virtual double area(){return PI*radius*radius;}
virtual double zhouchang(){return PI*(radius*2);}
virtual double volume(){return 0;}
virtual double surface(){return 0;}
};
class sphere:public circle//圆球
{
public:
sphere(double r):circle(r){radius=r;}
double volume(){return (4/3)*PI*radius*radius*radius;}
double surface(){return 4*PI*radius*radius;}
};
class cylinder:public circle//圆柱
{
protected:
double height;
public:
cylinder(double r,double h):circle(r){height=h;}
double volume(){return PI*radius*radius*height;}
double surface(){return PI*radius*radius*2+2*radius*PI*height;}
};
class cone:public cylinder//圆锥
{
public:
cone(double r,double h):cylinder(r,h){}
double volume(){return PI*radius*radius*height*(1/3);}
double surface(){return PI*radius*radius+PI*radius*sqrt(radius*radius+height*height);}
};
class Rectangle:public shape//长方形
{
protected:
double length,width;
public:
Rectangle(double l,double w){length=l,width=w;}
double area(){return length*width;}
double zhouchang(){return 2*(length+width);}
virtual double volume(){return 0;}
virtual double surface(){return 0;}
};
class coboid:public Rectangle//长方体
{
protected:
double height;
public:
coboid(double l,double w,double h):Rectangle(l,w){height=h;}
double volume(){return length*width*height;}
double surface(){return length*width*2+length*height*2+width*height*2;}
};
int main()
{
int x;
double r,l,w,h;
shape *shape1 = 0 ;
while(x!=0)
{
cout<<"设计目标:简单的几何图形周长、面积、体积计算。\n"<<endl;
cout<<"1.圆形\n"<<endl;
cout<<"2.圆球\n"<<endl;
cout<<"3.圆柱\n"<<endl;
cout<<"4.圆锥\n"<<endl;
cout<<"5.长方形\n"<<endl;
cout<<"6.长方体\n"<<endl;
cout<<"0.退出\n"<<endl;
cout<<"请输入编号:";
cin>>x;
system("cls");
switch(x)
{
case 1:
{cout<<"输入圆的半径: ";
cin>>r;
circle circle(r);
shape1 = &circle ;
cout<<"圆的面积为 :"<<shape1->area()<<endl;
cout<<"圆的周长为:"<<shape1->zhouchang()<<endl;
system("pause");
system("cls") ;
break;
}
case 2:
{
cout<<"输入圆球的半径 :";
cin>>r;
sphere sphere(r);
cout<<"圆球的体积为 :"<<sphere.volume()<<endl;
cout<<"圆球的表面积为 :"<<sphere.surface()<<endl;
system("pause");
system("cls") ;
break;
}
case 3:
{
cout<<"输入圆柱的半径和高 :\n ";
cout<<"半径:";cin>>r;
cout<<"高:";cin>>h;
cylinder cylinder(r,h);
cout<<"圆柱的体积为 :"<<cylinder.volume()<<endl;
cout<<"圆柱的表面积为 :"<<cylinder.surface()<<endl;
system("pause");
system("cls") ;
break;
}
case 4:
{
cout<<"输入圆锥的半径和高 :\n";
cout<<"半径:";cin>>r;
cout<<"高:";cin>>h;
cone cone(r,h);
cout<<"圆锥的体积为: "<<cone.volume()<<endl;
cout<<"圆锥的表面积为 :"<<cone.surface()<<endl;
system("pause");
system("cls") ;
break;
}
case 5:
{
cout<<"输入长方形的长、宽:\n ";
cout<<"长:";cin>>l;
cout<<"宽:";cin>>w;
Rectangle rectangle(l,w);
cout<<"长方形的面积为: "<<rectangle.area()<<endl;
cout<<"长方形的周长为:"<<rectangle.zhouchang()<<endl;
system("pause");
system("cls") ;
break;
}
case 6:
{
cout<<"输入长方体的长、宽、高: \n";
cout<<"长:";cin>>l;
cout<<"宽:";cin>>w;
cout<<"高:";cin>>h;
coboid coboid(l,w,h);
cout<<"长方体的体积为 :"<<coboid.volume()<<endl;
cout<<"长方体的表面积为: "<<coboid.surface()<<endl;
system("pause");
system("cls") ;
break;
}
case 0:
break;
}
}
}