鐵之狂傲

 取回密碼
 註冊
搜尋

【技術討論】 main函式的部分要怎麼寫??

[複製連結] 檢視: 2322|回覆: 0

發表於 06-12-17 21:28:08 |顯示全部樓層 大字 中字 小字 正體化 简体化
建立一個擁有length(長), width(寬), height(高)的Rectangle_Solid類別,
這三個屬性預設值皆為1.0
提供計算長方體周長,表面積,體積的成員函式
並且提供設定和取得length, width, height值的成員函式
設定屬性的函式必須檢查length, width, height是否大於0.0和小於100.0
在main函式裡測試此類別物件的每個成員函式
(註:length, width, height的預設值可由Rectangle_Solid的建構函式初始化)

以下順帶附上程式碼


#include <iostream>
#include "Rectangle_Solid.h"

using namespace std;

class Rectangle_Solid {
public:
Rectangle_Solid(float length = 1.0, float width = 1.0, float height = 1.0);

float perimeter();
float area();
float volumn();

void setlength(float);
void setwidth(float);
void setheight(float);

float getlength();
float getwidth();
float getheight();
private:
float _length, _width, _height;
};

Rectangle_Solid::Rectangle_Solid
(float length, float width, float height):_length(length), _width(width), _height(height) {
}

float Rectangle_Solid::perimeter() {
return (4 * (_length + _width + _height));
}

float Rectangle_Solid::area() {
return (2 * (_length * _width + _length * _height + _width * _height));
}

float Rectangle_Solid::volumn() {
return (_length * _width * _height);
}

void Rectangle_Solid::setheight(float height) {
if (height>0.0 && height<100.0)
_height = height;
else
cerr<<"Input error!"<<endl;
}

void Rectangle_Solid::setwidth(float width) {
if (width>0.0 && width<100.0)
_width = width;
else
cerr<<"Input error!"<<endl;
}

void Rectangle_Solid::setlength(float length) {
if (length>0.0 && length<100.0)
_length = length;
else
cerr<<"Input error!"<<endl;
}

float Rectangle_Solid::getlength() {
return _length;
}

float Rectangle_Solid::getwidth() {
return _width;
}

float Rectangle_Solid::getheight() {
return _height;
}

main函式的部分要怎麼寫會比較完整呢??
 

回覆 使用道具 檢舉

全世界最先進的跳動筆
你需要登入後才可以回覆 登入 | 註冊

存檔|手機版|聯絡我們|新聞提供|鐵之狂傲

GMT+8, 24-3-29 12:58 , Processed in 0.051135 second(s), 15 queries .

回頂部