题目是要通过cylinder类继承height类和circle类计算圆柱体得面积和体积 但是我的运行结果是0.不知道问题出在哪里,感觉值没有传进去
#include <iostream>
#define pi 3.14
using namespace std;
class height
{
protected:
int h;
public:
height(int a)
{
h=a;
}
} ;
class cirle
{
protected:
int r;
public:
cirle(int b)
{
b=r;
}
};
class cylinder :public height,public cirle
{
public:
cylinder(int x,int y):height(h),cirle(r){
}
double area()
{
return (2*pi*r*r+2*pi*r*h);
}
double tiji()
{
return(pi*r*r*h);
}
void show()
{
cout<<"表面积:"<<area()<<endl<<"体积:"<<tiji();
}
};
int main()
{
cylinder s(1,5);
s.show();
}