各位帮忙看看吧!出问题了,呜呜。。。。。。。。。
程序代码:
//MyClass.h #include<iostream> const float PI=3.14f; using namespace std; /////////////////////////////////// //////下面定义了一个Circle类 class Circle { public: Circle(); Circle(float); ~Circle(); Get_R(float r); Get_Area(); Get_Radius();//供派生类访问基类私有成员 Display(); private: float Radius; }; ////////////////////////////////////// ////////下面定义了一个Boll类 class Ball:public Circle { public: // Ball(); // Ball(); ~Ball(); Get_Volume(); Get_Superficial_Area(); Display(); }; //////////////////////////////////////// ////////////下面定义了一个Cylinder类 class Cylinder:public Circle { public: Cylinder(); Cylinder(float); ~Cylinder(); Get_Volume(); Get_Height(float); Get_Superficial_Area(); Display(); private: float Height; }; ////////////////////////////////////////////// ////////////////////////////////////////////// ////////下面定义了一个Conicalness类 class Conicalness:public Circle { public: Conicalness(); Conicalness(float); ~Conicalness(); Get_Volume(); Get_Superficial_Area(); Display(); private: float Height; }; ////////////////////////////////////////////////// //Myclass.cpp #include"MyClass.h" #include<cmath> //////////////////////////// ////////下面是Circle类成员函数的实现 Circle::Circle() { Radius=0.0; }// Circle::Circle(float r) { Radius=r; }// Circle::~Circle() { cout<<"Circle destructor!"<<endl; }// Circle::Get_R(float r) { Radius=r; }// Circle::Get_Radius() { return Radius; }// Circle::Get_Area() { return (PI*Radius*Radius); }// Circle::Display() { cout<<"Radius:"<<Get_Radius()<<endl; cout<<"Area:"<<Get_Area()<<endl; }// ////////////////////////////////////////// ////////////下面是Ball类成员函数的实现 Ball::~Ball() { cout<<"Ball destructor!"<<endl; }// Ball::Get_Volume() { return ((4.0*PI*Get_Radius()*Get_Radius()*Get_Radius())/3.0); }// Ball::Get_Superficial_Area() { return (4.0*Get_Area()); }// Ball::Display() { Circle::Display(); cout<<"Superficial_Area:"<<Get_Superficial_Area()<<endl; cout<<"Volume:"<<Get_Volume()<<endl; }// //////////////////////////////////////////// /////// ///////////下面是Cylinder类成员函数的实现 Cylinder::Cylinder() { Height=0; }// Cylinder::Cylinder(float height) { Height=height; }// Cylinder::~Cylinder() { cout<<"Cylinder destructor!"<<endl; }// Cylinder::Get_Volume() { return float(PI*Get_Radius()*Get_Radius()*Height); }// Cylinder::Get_Superficial_Area() { return((2.0)*PI*Get_Radius()*Height); }// Cylinder::Display() { Circle::Display(); cout<<"Superficial_Area:"<<Get_Superficial_Area()<<endl; cout<<"Volume:"<<Get_Volume()<<endl; }// /////////////////////////////////////////////// ////////下面是Conicalness类成员函数的实现 Conicalness::Conicalness() { Height=0; }// Conicalness::Conicalness(float height) { Height=height; }// Conicalness::~Conicalness() { cout<<"Conicalness destructor!"<<endl; }// Conicalness::Get_Volume() { return ((1.0/3.0)*Height*Get_Area()); }// Conicalness::Get_Superficial_Area() { return(PI*Get_Radius()*sqrt(Height*Height+Get_Radius()*Get_Radius())+Get_Area()); }// Conicalness::Display() { Circle::Display(); cout<<"Superficial_Area:"<<Get_Superficial_Area()<<endl; cout<<"Volume:"<<Get_Volume()<<endl; }// ////////////////////////////////////////////// //主函数 #include"MyClass.h" int main() { Circle *cir=new Circle; Ball *ball=new Ball; Cylinder *cyl=new Cylinder; Conicalness *con=new Conicalness; cout<<"------------Circle------------"<<endl; cir->Get_R(2.0); cir->Display(); cout<<"------------Ball--------------"<<endl; ball->Get_R(3.0); ball->Display(); cout<<"------------Cylinder----------"<<endl; cyl->Get_R(4.0); cyl->Display(); cout<<"------------Conicalness-------"<<endl; con->Get_R(5.0); con->Display(); cout<<"------------------------------"<<endl; delete cir; delete ball; delete con; delete cyl; return 0; }输出的结果不对啊?各位帮忙看下
本来的意思是要输出浮点数的,结果是整形