当前位置:网站首页>PTA:6-29 虚基类的应用-人与教师学生
PTA:6-29 虚基类的应用-人与教师学生
2022-06-23 03:47:00 【Sy_Faker】
派生类定义:根据所给的基类,完成多重继承下的派生类定义
函数接口定义:
#include <iostream>
#include <string>
using namespace std;
//定义公共基类Person
class Person
{
public:
Person(string nam,char s,int a)
{
name=nam;sex=s;age=a;}
protected:
string name;
char sex;
int age;
};
//定义类Teacher
class Teacher:virtual public Person
{
public:
Teacher(string nam,char s,int a,string t):Person(nam,s,a)
{
title=t;
}
protected:
string title;
};
//定义类Student
class Student:virtual public Person
{
public:
Student(string nam,char s,int a,float sco):
Person(nam,s,a),score(sco){
}
protected:
float score;
};
/*这里添加派生类的定义*/
裁判测试程序样例:
int main( )
{
Graduate grad1("Wang-li",'f',24,"assistant",89.5,1234.5);
grad1.show( );
return 0;
}
输出样例:
在这里给出相应的输出。例如:
name:Wang-li
age:24
sex:f
score:89.5
title:assistant
wages:1234.5
上代码:
class Graduate:virtual public Person ,public Teacher,public Student
{
public:
double wages;
Graduate(string nam,char s,int a,string t,float sco,double w):Person(nam,s,a),Teacher(nam,s,a,t),Student(nam,s,a,sco)
{
title=t;
score=sco;
name=nam;
sex=s;
age=a;
wages=w;
}
void show()
{
cout<<"name:"<<name<<endl;
cout<<"age:"<<age<<endl;
cout<<"sex:"<<sex<<endl;
cout<<"score:"<<score<<endl;
cout<<"title:"<<title<<endl;
cout<<"wages:"<<wages<<endl;
}
};
边栏推荐
- How can I realize video call and interactive live broadcast in a small program?
- 深度学习 简介
- How e-commerce makes use of small programs
- Avltree - arbre de recherche binaire équilibré
- 给你的AppImage创建桌面快捷方式
- PTA:7-86 集合的模拟实现(函数模板)
- 高效的远程办公经验 | 社区征文
- Svg+js smart home monitoring grid layout
- 虫子 日期类 下 太子语言
- Getting started with tensorflow
猜你喜欢

Pytorch---使用Pytorch的预训练模型实现四种天气分类问题

QMainWindow

Analysis on the current situation of the Internet of things in 2022

怎么用好MySQL索引

如何处理大体积 XLSX/CSV/TXT 文件?

无线网络安全的12个优秀实践

Differences between MyISAM and InnoDB of MySQL storage engine

在word里,如何让页码从指定页开始编号

在线文本过滤小于指定长度工具
![[deep learning] deep learning reasoning framework tensorrt MNN openvino onnxruntime](/img/a9/11bc00a91b79358f28ada2d4c99f32.png)
[deep learning] deep learning reasoning framework tensorrt MNN openvino onnxruntime
随机推荐
在 KubeSphere 上部署 Apache Pulsar
靜態查找錶和靜態查找錶
Similar to RZ / SZ, trzsz supporting TMUX has released a new version
Software development in 2022: five realities CIOs should know
在word里,如何让页码从指定页开始编号
仿360桌面悬浮球插件
基于FPGA的VGA协议实现
Sequence table lookup
Mobile terminal city list sorting JS plug-in vertitylist js
Two ways to improve the writing efficiency of hard disk storage data
会话和守护进程
JD cloud distributed database stardb won the "stability practice pioneer" of China Academy of information technology
How to ensure application security
[pycharm] ide Eval resetter
[tcapulusdb knowledge base] [list table] sample code for inserting data into the specified position in the list
mysql优化,sql执行非常卡顿,不改变sql结构达到10秒内结束
What is the digital "true" twin? At last someone made it clear!
【二叉樹進階】AVLTree - 平衡二叉搜索樹
在线文本过滤小于指定长度工具
Adobe international certification 𞓜 how IIT Madras brings efficiency and accessibility to scholars through Adobe e Acrobat