C++这道题应该怎么做?
#include<iostream>
#include<cstring>
using namespace std;
class vehicle {
int wheels, weight;
public:vehicle() {
wheels = 5;
weight = 5;
}
void set(int wh, int wei) {
wheels = wh;
weight = wei;
}
void showme() {
cout << "wheels = " << wheels << endl;
cout << "weight=" << weight << endl;
}
~vehicle() {
cout << "Now destroying the instance of vehicle\n";
}
};
class car :public vehicle {
int passenger_load;
public: car() {
passenger_load = 5;
}void set(int a, int b, int c) {
vehicle::set(a, b);
passenger_load = c;
}
void showme() {
vehicle::showme();
cout << "passenger_load=" << passenger_load << endl;
}
~car() {
cout << "Now destroying the instance of car\n";
}
};
class truck :public car{
int payload;
public:truck() {
payload = 5;
}
void set(int a, int b, int c, int d) {
car::set(a, b, c);
payload = d;
}
void showme() {
car::showme();
cout << "payload=" << payload << endl;
}
~truck() {
cout << "Now destroying the instance of truck\n";
}
};
int main() {
truck a;
a.showme();
return 0;
}