一個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;
}
}
}
看著這麼眼熟。
你編譯時的warning錯誤不看嗎?
warning C4700: 使用了未初始化的局部變量“x”
int main()
{
int x=1;//修改,未初始化