当前位置:网站首页>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;
}
};
边栏推荐
- What is the APM tool skywalking
- Weekly Postgres world news 2022w02
- Half search method
- Cool mouse following animation JS plug-ins 5
- How e-commerce makes use of small programs
- 如何保证应用程序的安全性
- Latest programming language rankings
- 自媒体时代的贤内助——AI 视频云
- Black horse PostgreSQL, why is it black in the end
- Online text filter less than specified length tool
猜你喜欢

Software project management 8.4 Software project quality plan

svg d3.js生成tree树状图

Cool mouse following animation JS plug-ins 5

怎么使用Shell脚本实现监测文件变化

在线JSON转CSharp(C#)Class工具

城链科技董事长肖金伟:践行数据经济系国家战略,引领数字时代新消费发展!
![[advanced binary tree] AVLTree - balanced binary search tree](/img/a5/aef68dd489ef5545e5b11ee2d3facc.png)
[advanced binary tree] AVLTree - balanced binary search tree

Xiaojinwei, chairman of Chenglian Technology: implement the national strategy of data economy and lead the development of new consumption in the digital era!

【二叉樹進階】AVLTree - 平衡二叉搜索樹

Flutter怎么实现不同缩放动画效果
随机推荐
Imitation 360 desktop suspended ball plug-in
背景彩带动画插件ribbon.js
Pytorch---使用Pytorch的预训练模型实现四种天气分类问题
Particle animation background login page particles js
2022年的软件开发:首席信息官应该知道的五个现实
Avltree - arbre de recherche binaire équilibré
What is the difference between redistemplate and CacheManager operation redis
Can MySQL be used in Linux
MySQL optimization, the SQL execution is very stuck, and the SQL structure will not be changed until it ends in 10 seconds
It supports running in kubernetes, adds multiple connectors, and seatunnel version 2.1.2 is officially released!
[tcapulusdb knowledge base] [list table] example code for replacing the data at the specified location in the list
会话和守护进程
What is metadata
[从零开始学习FPGA编程-40]:进阶篇 - 设计-竞争与风险Risk或冒险
mysql优化,sql执行非常卡顿,不改变sql结构达到10秒内结束
PTA:7-31 期刊收费
理想汽车×OceanBase:当造车新势力遇上数据库新势力
如何处理大体积 XLSX/CSV/TXT 文件?
A summary of PostgreSQL data types. All the people are here
[deep learning] deep learning reasoning framework tensorrt MNN openvino onnxruntime