日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

C语言输出长方柱的体积,需要求3个长方柱的体积,请编写一个基于对象的程序。数据成员包括length(长)、width(宽)、 height(高)。要求用成员函数实现以下功能...

發布時間:2024/9/3 编程问答 41 豆豆

需要求3個長方柱的體積,請編寫一個基于對象的程序。數據成員包括length(長)、width(寬)、 height(高)。要求用成員函數實現以下功能:

(1) 由鍵盤分別輸入3個長方柱的長、寬、高;

(2) 計算長方柱的體積;

(3) 輸出3個長方柱的體積。

請編程序,上機調試并運行。

以下是此題的【c++源代碼】

答案1,源代碼:

#include

using namespace std;

class Box

{public:

void get_value();

float volume();

void display();

public:

float lengh;

float width;

float height;

};

void Box::get_value()

{ cout<

cin>>lengh;

cin>>width;

cin>>height;

}

float Box::volume()

{ return(lengh*width*height);}

void Box::display()

{ cout<

int main()

{Box box1,box2,box3;

box1.get_value();

cout<

box1.display();

box2.get_value();

cout<

box2.display();

box3.get_value();

cout<

box3.display();

return 0;

}

******************************************

答案2,源代碼:

#include

using namespace std;

class Box

{public:

void get_value();

void volume();

void display();

public:

float lengh;

float width;

float height;

float vol;

};

void Box::get_value()

{ cout<

cin>>lengh;

cin>>width;

cin>>height;

}

void Box::volume()

{ vol=lengh*width*height;}

void Box::display()

{ cout<

int main()

{Box box1,box2,box3;

box1.get_value();

box1.volume();

cout<

box1.display();

box2.get_value();

box2.volume();

cout<

box2.display();

box3.get_value();

box3.volume();

cout<

box3.display();

return 0;

}

總結

以上是生活随笔為你收集整理的C语言输出长方柱的体积,需要求3个长方柱的体积,请编写一个基于对象的程序。数据成员包括length(长)、width(宽)、 height(高)。要求用成员函数实现以下功能...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。