云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > c++面向对象程序设计试题和答案(经典题目)

c++面向对象程序设计试题和答案(经典题目)

  • 62 次阅读
  • 3 次下载
  • 2025/5/26 12:12:01

class rectangle //(2分) {

private: int x1,y1,x2,y2; // (2分)

public: rectangle(int xx1,int yy1,int xx2,int yy2) //(1分)

{

x1=xx1;y1=yy1;x2=xx2;y2=yy2; }

int getarea() //(2分) { }

return abs((x2-x1)*(y1-y2));

};

void main() { rectangle rect1(3,7,8,5); (2分) }

2、(10分)

#include class car;(1分) class boat{

private: int weight; //(1分) public: boat(int w):weight(w){} //(1分)

friend int totalweight(boat b1,car c1); //(2分) };

class car{ /(1分) private: int weight; (1分)

public: car(int w):weight(w){}; friend int totalweight(boat b1,car c1); (1分) };

int totalweight(boat b1,car c1) //(1分) {

系名____________班级____________姓名____________学号____________ 密封线内不答题 cout<

return b1.weight+c1.weight;

}

void main() { }

3、(10分)

#include

class vehicle // 定义汽车类 (3分) {

protected:

int wheels; // 车轮数 float weight; // 重量

public:

vehicle(int wheels,float weight); int get_wheels(); 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; }

float vehicle::get_weight()

car c1(1000); boat b1(2000);

cout<

——第10页——

{

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()

{

cout <<\车型:小车\

vehicle::show();

cout << \载人:\人\ cout << endl; }

void main ()

{

car car1(4,2000,5); (1分) cout << \输出结果\ car1. show (); (1分) }

密封线内不答题

  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

class rectangle //(2分) { private: int x1,y1,x2,y2; // (2分) public: rectangle(int xx1,int yy1,int xx2,int yy2) //(1分) { x1=xx1;y1=yy1;x2=xx2;y2=yy2; } int getarea() //(2分) { } return abs((x2-x1)*(y1-y2)); }; void main() { rectangle rect1(3,7,8,5); (2分) } 2、(10分) #include class car;(1分) cla

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com