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

c语言用box求体积

发布时间: 2022-08-02 06:44:38

① 用vc++编程 设计一个立方体类Box,它能计算并输出立方体的体积和表面积。

#include <iostream>
using namespace std;
class Box{
public:
Box(double s):side(s) {}
double getArea(){ return 6*side*side; }
double getVolume(){ return side*side*side; }
private:
double side;
};
int main( int argc, char *argv[] ){
Box myBox( 3 );
cout << myBox.getArea() <<endl;
cout << myBox.getVolume() <<endl;
return 0;
}

② 设计一个立方体类Box,计算并输出立方体的体积和表面积,并求一边长为5的立方体的体积和表面积。

您好,我是软件之家的♂北极熊熊,很高兴为您解答。 ================================================================================== 代码如下: #include<iostream> using namespace std; class Box { public: Box(int x){a=x;} int a; int S() { return(a*a*6); } int V() { return(a*a*a); } }; int main() { Box b(5); cout<<b.S()<<endl; cout<<b.V()<<endl; return 0; } ================================================================================== 如您满意,谢谢五星采纳~~~~~↖(*^ω^*)↗

③ 建立类box,box的构造函数被传递了3个double值,每一个double值表示盒子的一条边长。用BOX类计算立方的体积

class Box
{
double a,b,c;
public:
Box(double,double,double);
Void VOI();
};
Date::Box(double x,double y,double z)
{
a=x;
b=y;
c=z;
}
void Box::VOI()
{
double v=a*b*c;
printf("%f",v);
}

④ 如何用C语言求长方形体积

长方形是平面几何的概念,无法求体积,只有面积。只有立体几何的长方体才可以求体积。

对于长方形,要求面积,只需要将两边相乘即可。

对于长方体,要求体积,只需要将三边相乘即可。


所以抽象到C语言的时候,这两种计算,均是如果几个数值,然后将所有数值相乘,最终输出结果的过程。其中求面积需要输入两个数,而求体积需要输入三个数。

以求体积为例:

#include<stdio.h>
intmain()
{
inta,b,c;//三个边长宽高的值。
intv;//体积。
scanf("%d%d%d",&a,&b,&c);//输入三个值。
v=a*b*c;//计算。
printf("%d ",v);//输出结果。
return0;
}

⑤ 面向对象 1)问题:设计一个长方体类Box,它能计算并输出长方体的体积

#include
using namespace std;

class Cuboid {
private :
int length;
int width;
int height;
public :
Cuboid() {length = width = height = 0;}
Cuboid(int l,int w,int h) {
length = l;
width = w;
height = h;
}
int Volume() { return length * width * height; }
int SuperficialArea() {
return 2 * (length * width + width * height + height * length);
}
void Show() {
cout << "长 " << length << endl;
cout << "宽 " << width << endl;
cout << "高 " << height << endl;
}
};

int main() {
int len,w,h;
cout << "输入长方体的长、宽、高(空格隔开) : ";
cin >> len >> w >> h;
Cuboid Ca(len,w,h),Cb;
cout << "Ca属性 :\n";
Ca.Show();
cout << "体积 : " << Ca.Volume() << endl;
cout << "表面积 : " << Ca.SuperficialArea() << endl;
cout << "Cb属性 :\n";
Cb.Show();
cout << "体积 : " << Cb.Volume() << endl;
cout << "表面积 : " << Cb.SuperficialArea() << endl;
return 0;
}

⑥ 设计一个立方体类Box,它能计算并输出立方体的体积和表面积.

添加类box(double x,double y,double z)
然后在类下面写出体积和表面积公示,然后返回体积和表面积两个值
最后在函数中调用box

⑦ c++:要求定义Box类,计算盒子的体积及表面积。我想通过Get函数输出体积和表面积,但报错了,跪求指点

class Box{
private double length;

private double width;

private double height;

public Box() {
if(lenght < 0 || width < 0 || height <0) {
System.out.println("输入值不合法!");
}

System.out.println("盒子体积是:"+length*height*width);
}

}

⑧ C++设计一个立方体类Box,它能计算并输出立方体的体积和表面积。

#include<iostream>
using namespace std;
class Box
{
public:
Box(double n){arc=n;}
double V(){return arc*arc*arc;}
double S(){return 6*arc*arc;}
private:
double arc;
};

int main()
{
Box b(3);
cout<<"Vb="<<b.V()<<endl;
cout<<"Sb="<<b.S()<<endl;
return 0;
}

⑨ 设计一个立方体类Box,它能计算并输出立方体的体积和表面积。C++,别百度粘贴啊。。。

#include<iostream>
usingnamespacestd;
classA
{
inta,b,c;
public:
A(inti,intj,intk):a(i),b(j),c(k){}
intS()const
{
return2*(a*b+a*c+b*c);
}
intV()const
{
returna*b*c;
}
};

intmain()
{
Aa(1,2,3),b(4,5,6);
cout<<a.S()<<''<<a.V()<<endl;
cout<<b.S()<<''<<b.V()<<endl;
}