《C++第十二周实验报告2-1》--分别定义Teacher(教师)类和Cadre(干部采用多重继承方式由这两个类派生出新类Teacher_Cadre(教师兼干部)

本文主要是介绍《C++第十二周实验报告2-1》--分别定义Teacher(教师)类和Cadre(干部采用多重继承方式由这两个类派生出新类Teacher_Cadre(教师兼干部),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

/*
【任务2】(教材P394习题9)分别定义Teacher(教师)类和Cadre(干部)类,
采用多重继承方式由这两个类派生出新类Teacher_Cadre(教师兼干部)。要求: 
(1)在两个基类中都包含姓名、年龄、性别、地址、电话等数据成员。 
(2)在Teacher类中还包含数据成员title(职称),在Cadre类中还包含数据成员post(职务),
在Teacher_Cadre类中还包含数据成员wages(工资)。 
(3)对两个基类中的姓名、年龄、性别、地址、电话等数据成员用相同的名字,在引用这些数据成员时,指定作用域。 
(4)在类体中声明成员函数,在类外定义成员函数。 
(5)在派生类Teacher_Cadre的成员函数show中调用Teacher类中的display函数,
输出姓名、年龄、性别、职称、地址、电话,然后再用cout语句输出职务与工资。
*/
/* (程序头部注释开始)
* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生 
* All rights reserved.
* 文件名称:    Person.cpp                          
* 作    者:   计114-3 王兴锋     
* 完成日期:    2012  年   5    月   7    日
* 版 本 号:       V 4.0
* 程序头部的注释结束
*/
#include <iostream>
#include <string>
using namespace std;
class Person
{
public:
Person(string name, int age, char sex, string add, string tel);
protected:
string name, add,  tel;
int age;
char sex;	
};
Person::Person(string name, int age, char sex, string add, string tel)
{
this->name = name, this->age = age, this->sex = sex, this->add = add, this->tel = tel;
}
class Teacher : virtual public Person
{
public:
Teacher(string name, int age, char sex, string add, string tel, string title);
protected:
string title;
void display();
};
Teacher::Teacher(string name, int age, char sex, string add, string tel, string title):Person(name, age, sex, add, tel)
{
this->title = title;
}
void Teacher::display()
{
cout << "姓名:" << name << endl;
cout << "年龄:" << age << endl;
cout << "性别:" << sex << endl;
cout << "职称:" << title << endl;
cout << "地址:" << add << endl;
cout << "电话:" << tel << endl;
}
class Cadre : virtual public Person
{
public:
Cadre(string name, int age, char sex, string add, string tel, string post);
protected:
string post;
};
Cadre::Cadre(string name, int age, char sex, string add, string tel, string post):Person(name, age, sex, add, tel)
{
this->post = post;
}
class Teacher_Cadre : public Cadre, public Teacher
{
public:
Teacher_Cadre(string name, int age, char sex, string add, string tel, string post, string title, double wages);
void show();
private:
double wages;
};
Teacher_Cadre::Teacher_Cadre(string name, int age, char sex, string add, string tel, string post, string title, double wages):
Teacher(name, age, sex, add, tel, title),
Cadre(name, age, sex, add, tel, post),
Person(name, age, sex, add, tel)
{
this->wages = wages;
}
void Teacher_Cadre::show()
{
display();
cout << "职务:" << post << endl;
cout << "工资:" << wages << endl;
}
int main()
{
Teacher_Cadre tc("张三",32,'f',"烟台大学","18253576921","主任","教师",3500);
tc.show();
system("PAUSE");
return 0;
}

这篇关于《C++第十二周实验报告2-1》--分别定义Teacher(教师)类和Cadre(干部采用多重继承方式由这两个类派生出新类Teacher_Cadre(教师兼干部)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/335763

相关文章

SpringBoot中@Value注入静态变量方式

《SpringBoot中@Value注入静态变量方式》SpringBoot中静态变量无法直接用@Value注入,需通过setter方法,@Value(${})从属性文件获取值,@Value(#{})用... 目录项目场景解决方案注解说明1、@Value("${}")使用示例2、@Value("#{}"php

SpringBoot分段处理List集合多线程批量插入数据方式

《SpringBoot分段处理List集合多线程批量插入数据方式》文章介绍如何处理大数据量List批量插入数据库的优化方案:通过拆分List并分配独立线程处理,结合Spring线程池与异步方法提升效率... 目录项目场景解决方案1.实体类2.Mapper3.spring容器注入线程池bejsan对象4.创建

C++右移运算符的一个小坑及解决

《C++右移运算符的一个小坑及解决》文章指出右移运算符处理负数时左侧补1导致死循环,与除法行为不同,强调需注意补码机制以正确统计二进制1的个数... 目录我遇到了这么一个www.chinasem.cn函数由此可以看到也很好理解总结我遇到了这么一个函数template<typename T>unsigned

C++统计函数执行时间的最佳实践

《C++统计函数执行时间的最佳实践》在软件开发过程中,性能分析是优化程序的重要环节,了解函数的执行时间分布对于识别性能瓶颈至关重要,本文将分享一个C++函数执行时间统计工具,希望对大家有所帮助... 目录前言工具特性核心设计1. 数据结构设计2. 单例模式管理器3. RAII自动计时使用方法基本用法高级用法

JavaScript中比较两个数组是否有相同元素(交集)的三种常用方法

《JavaScript中比较两个数组是否有相同元素(交集)的三种常用方法》:本文主要介绍JavaScript中比较两个数组是否有相同元素(交集)的三种常用方法,每种方法结合实例代码给大家介绍的非常... 目录引言:为什么"相等"判断如此重要?方法1:使用some()+includes()(适合小数组)方法2

HTTP 与 SpringBoot 参数提交与接收协议方式

《HTTP与SpringBoot参数提交与接收协议方式》HTTP参数提交方式包括URL查询、表单、JSON/XML、路径变量、头部、Cookie、GraphQL、WebSocket和SSE,依据... 目录HTTP 协议支持多种参数提交方式,主要取决于请求方法(Method)和内容类型(Content-Ty

使用shardingsphere实现mysql数据库分片方式

《使用shardingsphere实现mysql数据库分片方式》本文介绍如何使用ShardingSphere-JDBC在SpringBoot中实现MySQL水平分库,涵盖分片策略、路由算法及零侵入配置... 目录一、ShardingSphere 简介1.1 对比1.2 核心概念1.3 Sharding-Sp

深入解析C++ 中std::map内存管理

《深入解析C++中std::map内存管理》文章详解C++std::map内存管理,指出clear()仅删除元素可能不释放底层内存,建议用swap()与空map交换以彻底释放,针对指针类型需手动de... 目录1️、基本清空std::map2️、使用 swap 彻底释放内存3️、map 中存储指针类型的对象

Spring创建Bean的八种主要方式详解

《Spring创建Bean的八种主要方式详解》Spring(尤其是SpringBoot)提供了多种方式来让容器创建和管理Bean,@Component、@Configuration+@Bean、@En... 目录引言一、Spring 创建 Bean 的 8 种主要方式1. @Component 及其衍生注解

python中的显式声明类型参数使用方式

《python中的显式声明类型参数使用方式》文章探讨了Python3.10+版本中类型注解的使用,指出FastAPI官方示例强调显式声明参数类型,通过|操作符替代Union/Optional,可提升代... 目录背景python函数显式声明的类型汇总基本类型集合类型Optional and Union(py