当前位置:首页 » 编程语言 » c语言floatvolume
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

c语言floatvolume

发布时间: 2023-06-29 09:56:09

⑴ 用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()
{
cone
A(4,3);
A.getline();
A.surarea();
A.volume();
A.show();
return
0;
}

⑵ 用c语言工程求长方体的体积,表面积,周长.

#include "stdafx.h"
float chang,kuang,gao;

void fun1(){
printf("请输入长,宽,高:");
scanf("%f",&chang);
scanf("%f",&kuang);
scanf("%f",&gao);
}
float volume(){
return chang*kuang*gao;
}
float area(){
return 2*(chang*kuang+chang*gao+kuang*gao);
}
float perimeter(){
return 4*(chang+kuang+gao);

}
int main(int argc, char* argv[])
{
fun1();
printf("体积为:%f",volume());
printf("\n面积为:%f",area());
printf("\n周长为:%f\n",perimeter());

return 0;

}