我試圖解決C++中的問題,但因爲我是一個begginer我不知道該怎麼做! 問題是,如果你能幫我:) :):類C++測試
通過使用下面的C++代碼創建關於類「汽車」&「卡車」正確的構造函數。每個功能必須將合適的參數傳遞給父級車輛。另外,功能汽車在創建對象時應該初始化乘客。卡車類應在創建對象時初始化裝載限制。
對象與汽車()和卡車()語句將如下:
車OB(人次,輪轂,範圍);
truck ob(loadlimit,wheels,range);
#include <iostream>
using namespace std;
class vehicle{
int num_wheels;
int range;
public:
vehicle(int w, int r){num_wheels = w; range = r;}
void showv(){
cout << "Wheels: " << num_wheels << endl;
cout << "Range: " << range << endl;
}
};
class car : public vehicle {
int passengers;
public:
void show(){
void showv();
cout << "Passengers: " << passengers << endl;
}
};
class truck : public vehicle {
int loadlimit;
public:
void show(){
void showv();
cout << "Loadlimit: " << loadlimit << endl;
}
};
int main(){
car c(5, 4, 500);
truck t(3000, 12, 1200);
cout << "Car: " << endl;
c.show();
cout << "Truck: " << endl;
t.show();
return 0;
}
同樣的事情在哪裏級「車」和「卡車」的人的其他數據成員需要初始化? – Subhajit
感謝您的回答。我不知道它可能會在哪裏開始,那是怎麼測試..對不起。 (?) 不知道這麼多來引導/幫助.. IM Cott,我試着學習與我的C知識:/ – user3610729