当前位置:首页 > c++面向对象程序设计试题和答案(经典题目)
.
{ }
void main() { }
3、(10分)
#include
class vehicle // 定义汽车类 (3分) {
protected:
int wheels; // 车轮数 float weight; // 重量 public:
vehicle(int wheels,float weight); int get_wheels();
word
return b1.weight+c1.weight;
car c1(1000); boat b1(2000);
cout< float get_weight(); float wheel_load(); void show(); }; class car:public vehicle // 定义小车类 (3分) { int passenger_load; // 载人数 public: car(int wheels,float weight,int passengers=4); int get_passengers(); void show(); }; vehicle::vehicle(int wheels1,float weight1) //(1分) { wheels=wheels1; weight=weight1; } int vehicle::get_wheels() { return wheels; ——第14页—— . } float vehicle::get_weight() { return weight; } void vehicle::show() (1分) { cout << \车轮:\个\ cout << \重量:\公斤\ } car::car(int wheels, float weight, int passengers) :vehicle(wheels, weight) { passenger_load=passengers; } int car::get_passengers () { return passenger_load; } void car::show() word { cout <<\车型:小车\ vehicle::show(); cout << \载人:\人\ cout << endl; } void main () { car car1(4,2000,5); (1分) cout << \输出结果\car1. show (); (1分) } 欢迎您的光临,word文档下载后可以修改编辑。双击可以删除页眉页脚。谢谢!单纯的课本内容,并不能满足学生的需要,通过补充,达到内容的完善 ——第16页——
共分享92篇相关文档