① 用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;
}