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

当前位置:首页 > Visual C++面向对象程序设计教程与实验(第二版)清华大学出版社第5章习题参考答案

Visual C++面向对象程序设计教程与实验(第二版)清华大学出版社第5章习题参考答案

  • 62 次阅读
  • 3 次下载
  • 2025/5/4 22:32:04

public: };

char m_strID[12]; char m_strClass[12];

Student(char *name,int age,char sex,char *ID,char *Class) :Person(name,age,sex){ strcpy(m_strID, ID);

strcpy(m_strClass, Class); }

void ShowMe(){

cout<<\学 号:\Person::ShowMe();

cout<<\班 级:\}

void setID(char * ID){ strcpy(m_strID, ID); }

void setClass(char *Class){ strcpy(m_strClass, Class); }

char* getID(){ return m_strID; }

char* getClass(){ return m_strClass; }

class Employee:public Person{ int m_fSalary; public:

Employee(char *name,int age,char sex,int salary) :Person(name,age,sex){ m_fSalary = salary; }

};

void setSalary(int salary){ m_fSalary = salary; }

int getSalary(){ return m_fSalary; }

void ShowMe(){ Person::ShowMe();

cout<<\工 资:\}

void main(){ // 定义三个不同类的对象

//修改各类人员的属性 teacher1.setAge(40); teacher1.setSalary(4500); std1.setAge(21); emPloyee1.setAge(26); emPloyee1.setSalary(2000);

cout<<\cout<<\修改各类人员的属性后:\teacher1.ShowMe();

cout<<\std1.ShowMe();

Teacher teacher1(\刘馨\计算机系\Student std1(\刘丽\计算机03\Employee emPloyee1(\张鑫\

//显示各类人员的属性

teacher1.ShowMe();

cout<<\std1.ShowMe();

cout<<\emPloyee1.ShowMe();

}

cout<<\emPloyee1.ShowMe();

程序的执行结果为:

姓 名:刘馨

性 别:男 年 龄:38

工作单位:计算机系 月 薪:3800

------------------- 学 号:03016003 姓 名:刘丽 性 别:女 年 龄:20 班 级:计算机03 ------------------- 姓 名:张鑫 性 别:女 年 龄:25

工 资:1500

------------------- 修改各类人员的属性后: 姓 名:刘馨 性 别:男 年 龄:40 工作单位:计算机系 月 薪:4500 ------------------- 学 号:03016003 姓 名:刘丽 性 别:女 年 龄:21 班 级:计算机03 ------------------- 姓 名:张鑫 性 别:女 年 龄:26 工 资:2000

9. 假定车可分为货车和客车,客车又可分为轿车、面包车和公共汽车。请设计相应的类层次结构。

说明:可以把轿车、面包车和公共汽车定义为客车类的对象 参考程序:

#include using namespace std;

class vehicle {

public:

// 定义基类vehicle // 公有函数成员

vehicle(int in_wheels,float in_weight); // 给数据成员初始化 int get_wheels(); // 获取车轮数 float get_weight(); // 获取汽车重量 void setWeels(int wls);

void setWeight(float wt); void display(){ cout<<\车轮数:\

<<\ 汽车重量:\ }

private: // 私有数据成员 int wheels; // 车轮数

float weight; // 表示汽车承重 };

vehicle::vehicle(int in_wheels,float in_weight){ }

float vehicle::get_weight(){ }

int vehicle::get_wheels(){ return wheels; }

void vehicle::setWeels(int wls){ }

wheels = wls; return weight; wheels = in_wheels; weight = in_weight;

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

共分享92篇相关文档

文档简介:

public: }; char m_strID[12]; char m_strClass[12]; Student(char *name,int age,char sex,char *ID,char *Class) :Person(name,age,sex){ strcpy(m_strID, ID); strcpy(m_strClass, Class); } void ShowMe(){ cout<<\学 号:\Person::ShowMe(); cout<<\班 级:\} void setID(char * ID){ strcpy(m_strID, ID); } void se

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价: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