其資料成員包括油箱目前油量及車重,並設計必要的建構函式,建構函式需檢查參數中的目前尤輛及車重是否超過指定的上限直
以下是我做的 只完成一點點 不是很懂題目的意思 懇請先進大大可解惑
#include
#include
using namespace std;
class car{
public:
car(){gas=45;Carkg=1500;}
car(int,int);
private:
int gas;
int Carkg;
};
car::car(int gas,int Carkg){
if (gas>45) cout << "超過油箱容量油加爆了" << endl ;
else cout << "你的油箱容量還在標準內" << endl;
if (Carkg>1500) cout << "超過車重爆胎了啦" << endl;
else cout << "車重還在範圍內~ok的啦" << endl;
}
int main()
{
car t(50,1600);
system("PAUSE");
return EXIT_SUCCESS;
}
2007-10-14 10:55:37 · 1 個解答 · 發問者 瘋 1 in 電腦與網際網路 ➔ 程式設計
#include
#include
#define l_of_f 50//油量限制
#define l_of_w 100//重量限制
using namespace std;
class car//類別
{
private:
//這個就是 this->fuel
//這個就是 this->weight
double fuel,weight;
public:
car(double fuel, double weight)//建構子
{
this->fuel=fuel,this->weight=weight;
cout<<((fuel>l_of_f)?"Warning: Overfuel\n":"Safe: Underfuel\n");
cout<<((weight>l_of_w)?"Warning: Overweight\n":"Safe: Underweight\n");
}
double getW()//取回重量
{
return this->weight;
}
double getF()//取回油量
{
return this->fuel;
}
};
int main(int argc, char** argv){
//=====START=====//
car c1(5,100);
cout<<"Fuel= "<
system("PAUSE");
return 0;
}
2007-10-14 13:01:38 · answer #1 · answered by Big_John-tw 7 · 0⤊ 0⤋