用c++编写由圆和高多重继承派生出圆锥类,在主函数中能够实现圆锥体积和表面积的计算

没有能运行的?

#include<iostream>
#include<cmath>
#define N 3.1415
using namespace std;

class Height
{
private:
float h;
public:
Height(float h):h(h)
{}
float getheight()
{
return h;
}
};

class Circle
{
private:
float radius;
public:
Circle(float r):radius(r)
{}
float getradius();
float area();
};

float Circle::getradius()
{
return radius;
}

float Circle::area()
{
return N*radius*radius;
}

class cone:public Height,public Circle
{
private:
float line;
public:
cone(float h,float r):Height(h),Circle(r)
{}
void getline();
float surarea();
float volume();
void show();
};

void cone::getline()
{
float a=getradius();
float b=getheight();
line=sqrt(a*a+b*b);
}

float cone::surarea()
{
return area()+N*getradius()*line;
}

float cone::volume()
{
return area()*getheight()/3;
}

void cone::show()
{
cout<<"圆锥的表面积为:"<<surarea()<<endl;
cout<<"圆锥的体积为:"<<volume()<<endl;
}

int
main()
{
double r,h;
cout<<"请输入半径跟高"<<endl;
cin>>r>>h;
cone A(r,h);
A.getline();
A.surarea();
A.volume();
A.show();
return 0;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-06-15

/*错误:char b[]后面少了;还有,少了b数组的长度.
还有,reverse是一库函数,得改一下名.还有,你的程序是不对.你main()函数中用到返回值,但是在reverse()函数中没有返回.我来给你写一段吧,如下:*/
#include <iostream.h>
#include <string.h>
#define max 100

char *sreverse(char *s,int sta,int end)
{
char c,e;
int n=end;
if(end>sta)
{
c=s[sta];
e=s[end];
s[sta]=e;
s[end]=c;
sta++;
end--;
sreverse(s,sta,end);
}
return s;
}
void main()
{
char a[max];
char *p;
cout<<"请输入字符串:";
cin>>a;
cout<<"逆序前为:"<<a<<endl;
p=sreverse(a,0,strlen(a)-1);
cout <<"逆序后为:"<<p<<endl;

}
第2个回答  2011-06-16
忻州师院的吧 哥救你 但是 运行不了 希望你不是 二班的
#include<iostream.h>
#include<math.h>
#define PI 3.14159;
class circle
{
double a,b,r;
public:
void fun1(double i,double j,double k)
{
a=i;
b=j;
r=k;
}
void fun2()
{cout<<"圆锥圆心坐标:"<<a<<","<<b<<endl<<"底面圆的半径:"<<r<<endl;}
void area()
{
double s;
s=PI*r*r;
cout<<"圆锥的底面积是:"<<s<<endl;
}
};
class height
{
int h;
public:
fun3(int i)
{h=i;}
fun4()
{cout<<"圆锥高为:"<<h;}
};
class c:public circle,public height
{
public:
void V()
{
int v;
v=1/3*PI*r*r*h;
cout<<"圆锥的体积为:"<<v<<endl;
}
void S()
{
c=PI*r*sqrt(h*h-r*r)+PI*r*r;
cout<<"圆锥的表面积为:"<<c<<endl;
};
void main()
{
int i,j,k
cout<<"请输入圆锥的底面圆的圆心坐标:"<<endl;
cout<<"请输入圆锥的高:"<<endl;
cin>>i>>j>>k;
c obj;
obj.fun1(i,j);
obj.fun2();
obj.fun3(k);
obj.fun4();
obj.V();
obj.S();
}
相似回答