当前位置:网站首页>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;
}
};
边栏推荐
- Monitoring artifact ZABBIX, from deployment to application, goes deep layer by layer
- PTA:6-71 时钟模拟
- Pta:6-71 clock simulation
- Imitation 360 desktop suspended ball plug-in
- LabVIEW在同一表中同时显示十六进制字符和普通字符
- Pta:7-85 data spacing (overload + function template)
- Pta:7-37 student number analysis
- Online JSON to CSharp (c) class tool
- PTA:7-60 宠物的生长
- PTA:7-87 集合的模拟实现(类模板)
猜你喜欢

C语言刷题随记 —— 自由落体的球

Svg+js smart home monitoring grid layout
![[pytoch] calculate the derivative of sin (x) by automatic differentiation](/img/a7/16dd9ecc13a986a9141ecc3fba00a1.png)
[pytoch] calculate the derivative of sin (x) by automatic differentiation

摆烂LuoGu刷题记

离线数仓建模中常见的概念-术语

Pytoch --- pytoch customizes the dataset

众昂矿业:新能源新材料产业链对萤石需求大增

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

语料库数据处理个案实例(词性赋码、词性还原)

How to use shell script to monitor file changes
随机推荐
Pta:7-37 student number analysis
Implementation of VGA protocol based on FPGA
Mobile terminal city list sorting JS plug-in vertitylist js
PTA:7-58 图书音像出租管理
PTA: spacing of 7-69 data
Pta:6-33 student ranking table (destructor)
Sessions and Daemons
PTA:7-67 友元很简单2016final
Software development in 2022: five realities CIOs should know
Pta:7-31 journal charges
Lighthouse locally deployed TCA code analysis tool
[advanced binary tree] AVLTree - balanced binary search tree
Svg+js smart home monitoring grid layout
[binary tree] flip equivalent binary tree
Online JSON to CSharp (c) class tool
Introduction and use of MySQL view
Please use the NLTK Downloader to obtain the resource
Tables de recherche statiques et tables de recherche statiques
PTA:7-86 集合的模拟实现(函数模板)
语料库数据处理个案实例(分词和分句、词频统计、排序)