当前位置:网站首页>Pta:6-29 application of virtual base classes - people, teachers and students
Pta:6-29 application of virtual base classes - people, teachers and students
2022-06-23 04:38:00 【Sy_ Faker】
Derived class definition : According to the given base class , Complete the derived class definition under multiple inheritance
Function interface definition :
#include <iostream>
#include <string>
using namespace std;
// Define public base classes Person
class Person
{
public:
Person(string nam,char s,int a)
{
name=nam;sex=s;age=a;}
protected:
string name;
char sex;
int age;
};
// Defining classes 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;
};
// Defining classes 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;
};
/* The definition of the derived class is added here */
Sample referee test procedure :
int main( )
{
Graduate grad1("Wang-li",'f',24,"assistant",89.5,1234.5);
grad1.show( );
return 0;
}
sample output :
Here is the corresponding output . for example :
name:Wang-li
age:24
sex:f
score:89.5
title:assistant
wages:1234.5
Code up :
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;
}
};
边栏推荐
- PTA:7-69 数据的间距问题
- PTA:7-63 计算高考状元
- Lighthouse locally deployed TCA code analysis tool
- [multimode] unimo
- 语料库数据处理个案实例(分词和分句、词频统计、排序)
- Leetcode 1208. Try to make the strings equal as much as possible (finally solved, good night)
- PTA: spacing of 7-69 data
- 3D数学基础[十六] 匀加速直线运动的公式
- Xiaojinwei, chairman of Chenglian Technology: implement the national strategy of data economy and lead the development of new consumption in the digital era!
- 什么是元数据
猜你喜欢

How to make the page number start from the specified page in word

There is a problem with redis startup

A summary of PostgreSQL data types. All the people are here

x64dbg 基本使用技巧

IDEA-导入模块

Photoshop PS viewing pixel coordinates, pixel colors, pixel HSB colors

Tiktok x-bogus and_ Signature parameter analysis

Halcon glue line detection - template matching, pose transformation, glue width, glue continuity detection

最新编程语言排行榜

【深度学习】深度学习推理框架 TensorRT MNN OpenVINO ONNXRuntime
随机推荐
Static lookup tables and static lookup tables
LabVIEW在同一表中同时显示十六进制字符和普通字符
Dynamics 365 插件中权限操作
Pta:7-31 journal charges
leetcode 91. Decode ways (medium)
【Pytorch】用自动微分求sin(x)的导数
OpenJudge NOI 1.13 51:古代密码
Does the network disk also roll inside?
什么是元数据
Common interview questions in automated testing
Pytorch---Pytorch进行自定义Dataset
svg d3. JS generate tree tree view
[从零开始学习FPGA编程-40]:进阶篇 - 设计-竞争与风险Risk或冒险
Leetcode 1208. Make strings as equal as possible
Permission Operation in dynamics 365 plug-in
Ideal car × Oceanbase: when new forces of car building meet new forces of database
Halcon胶线检测—模板匹配、位姿变换、胶宽,胶连续性检测
顺序表查找
PTA:7-60 宠物的生长
Online JSON to CSharp (c) class tool