有关继承问题,初学,求教
#include<iostream>#include <math.h>
using namespace std;
class circle{
public:
void surface(int r,float s);
private:
int r;
float s;
};
void circle::surface(int r,float s)
{s=3.141592*r*r;
cout<<"圆 面积"<<" "<<"体积"<<endl;
cout<<s<<" "<<"0"<<endl;
}
class globe:public circle{
public:
void volume(int r1,float v1,float s1)
{s1=4*3.141592*r1*r1;
v1=4.0/3.0*3.141592*r1*r1*r1;
cout<<"球 表面积"<<" "<<"体积"<<endl;
cout<<s1<<" "<<v1<<endl;
}
private:
int r1;
float v1;
float s1;
};
class cylinder:public circle{
public:
void volume(int r2,float v2,float s2,int h2)
{s2=3.141592*r2*2*h2;
v2=3.141592*r2*r2*h2;
cout<<"圆柱 表面积"<<" "<<"体积"<<endl;
cout<<s2<<" "<<v2<<endl;
}
private:
int r2;
float v2;
float d2;
int h2;
};
class cone:public circle{
public:
void volume(int r3,float v3,float s3,int h3)
{s3=sqrt(r3*r3+h3*h3)*1.0/2.0*r3;
v3=1.0/3.0*3.141592*r3*r3*r3;
cout<<"圆锥 表面积"<<" "<<"体积"<<endl;
cout<<s3<<" "<<v3<<endl;
}
private:
int r3;
float v3;
float s3;
int h3;
};
int main()
{
int r,r1,r2,r3;
float s,s1,s2,s3;
float v,v1,v2,v3;
int h2,h3;
circle cir;
cout<<"请输入圆的半径"<<endl;
cin>>r;
globe glo;
cout<<"请输入球的半径"<<endl;
cin>>r1;
cylinder cyl;
cout<<"请输入圆柱的高和圆柱的底面半径"<<endl;
cin>>r2>>h2;
cone con;
cout<<"请输入圆锥的高和圆锥的底面半径"<<endl;
cin>>r3>>h3;
cout<<cir.surface()<<endl;
cout<<glo.volume()<<endl;
cout<<cyl.volume()<<endl;
cout<<con.volume()<<endl;
return 0;
}
我这继承应该不对吧,怎么改一下?下面是出现的错误,求解
ab-8.cpp
D:\VC++\program work\program work\lab8\lab-8.cpp(78) : error C2660: 'surface' : function does not take 0 parameters
D:\VC++\program work\program work\lab8\lab-8.cpp(79) : error C2660: 'volume' : function does not take 0 parameters
D:\VC++\program work\program work\lab8\lab-8.cpp(80) : error C2660: 'volume' : function does not take 0 parameters
D:\VC++\program work\program work\lab8\lab-8.cpp(81) : error C2660: 'volume' : function does not take 0 parameters
Error executing cl.exe.