1479: 多重继承派生(3)--person、account、admin和master类

2023-11-06 22:30

本文主要是介绍1479: 多重继承派生(3)--person、account、admin和master类,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1479: 多重继承派生(3)--person、account、admin和master类

Description

Person类包含私有成员数据姓名name(string)和编号code(int)。Account类包含私有成员数据姓名name(string)、编号code(int)和工资pay(int)。Admin类包含私有成员数据姓名name(string)、编号code(int)和实践经验experience(string)。Master类包含私有成员数据姓名name(string)、编号code(int)、工资pay(int)和实践经验experience(string)。
请根据给定的main函数以及运行结果设计相应的类及相互间的继承关系。
main函数已给定(如下所示),提交时只需要提交main函数外的代码部分。
int main()
{
string name,experience;
int code,pay,Cas=0;
while(cin>>name>>code>>pay>>experience)
{
Cas++;
cout<<"CASE #"<<Cas<<":"<<endl;
Person person(name,code);
Account account(name,code,pay);
Admin admin(name,code,experience);
Master master(name,code,pay,experience);
Show(&person);
Show(&account);
Show(&admin);
Show(&master);
}
return 0;
}

Input

包含多组数据(数据均正确合法)
每组测试数据1行,分别表示姓名,编号,工资和实践经验。

Output

每组测试数据输出具体格式详见Sample Output。

Sample Input 

张三 201506 2541 绘画
王大夫 2012510 3654 跳舞
殷文琦 1005210 5412 写代码编程

Sample Output

CASE #1:
Person::Constructor Function is called.
Person::Constructor Function is called.
Account::Constructor Function is called.
Person::Constructor Function is called.
Admin::Constructor Function is called.
Person::Constructor Function is called.
Account::Constructor Function is called.
Admin::Constructor Function is called.
Master::Constructor Function is called.
Show Function is called.
Person::Show Function is called.
NAME:张三  CODE:201506
Show Function is called.
Account::Show Function is called.
NAME:张三 CODE:201506 PAY:2541
Show Function is called.
Admin::Show Function is called.
NAME:张三 CODE:201506 EXPERIENCE:绘画
Show Function is called.
Master::Show Function is called.
NAME:张三 CODE:201506 PAY:2541 EXPERIENCE:绘画
CASE #2:
Person::Constructor Function is called.
Person::Constructor Function is called.
Account::Constructor Function is called.
Person::Constructor Function is called.
Admin::Constructor Function is called.
Person::Constructor Function is called.
Account::Constructor Function is called.
Admin::Constructor Function is called.
Master::Constructor Function is called.
Show Function is called.
Person::Show Function is called.
NAME:王大夫  CODE:2012510
Show Function is called.
Account::Show Function is called.
NAME:王大夫 CODE:2012510 PAY:3654
Show Function is called.
Admin::Show Function is called.
NAME:王大夫 CODE:2012510 EXPERIENCE:跳舞
Show Function is called.
Master::Show Function is called.
NAME:王大夫 CODE:2012510 PAY:3654 EXPERIENCE:跳舞
CASE #3:
Person::Constructor Function is called.
Person::Constructor Function is called.
Account::Constructor Function is called.
Person::Constructor Function is called.
Admin::Constructor Function is called.
Person::Constructor Function is called.
Account::Constructor Function is called.
Admin::Constructor Function is called.
Master::Constructor Function is called.
Show Function is called.
Person::Show Function is called.
NAME:殷文琦  CODE:1005210
Show Function is called.
Account::Show Function is called.
NAME:殷文琦 CODE:1005210 PAY:5412
Show Function is called.
Admin::Show Function is called.
NAME:殷文琦 CODE:1005210 EXPERIENCE:写代码编程
Show Function is called.
Master::Show Function is called.
NAME:殷文琦 CODE:1005210 PAY:5412 EXPERIENCE:写代码编程

代码:

#include <iostream>
#include <string>
using namespace std;


class Person
{
public:
Person(string name,int code):name(name),code(code)
{
cout<<"Person::Constructor Function is called."<<endl;
}
virtual void Show()
{
cout<<"Person::Show Function is called."<<endl;
cout<<"NAME:"<<name<<"  CODE:"<<code<<endl;
}
string GetName()
{
return name;
}
int GetCode()
{
return code;
}
private:
string name;
int code;
};


class Account:virtual public Person
{
public:
Account(string name,int code,int pay):Person(name,code),pay(pay)
{
cout<<"Account::Constructor Function is called."<<endl;
}
void Show()
{
cout<<"Account::Show Function is called."<<endl;
cout<<"NAME:"<<GetName()<<" CODE:"<<GetCode()<<" PAY:"<<pay<<endl;
}
int GetPay()
{
return pay;
}
private:
int pay;
};


class Admin:virtual public Person
{
public:
Admin(string name,int code,string experience):Person(name,code),experience(experience)
{
cout<<"Admin::Constructor Function is called."<<endl;
}
void Show()
{
cout<<"Admin::Show Function is called."<<endl;
cout<<"NAME:"<<GetName()<<" CODE:"<<GetCode()<<" EXPERIENCE:"<<experience<<endl;
}
string GetExperience()
{
return experience;
}
private:
string experience;
};


class Master:public Account,public Admin
{
public:
Master(string name,int code,int pay,string experience):Person(name,code),Account(name,code,pay),Admin(name,code,experience)
{
cout<<"Master::Constructor Function is called."<<endl;
}
void Show()
{
cout<<"Master::Show Function is called."<<endl;
cout<<"NAME:"<<GetName()<<" CODE:"<<GetCode()<<" PAY:"<<GetPay()<<" EXPERIENCE:"<<GetExperience()<<endl;
}
};
void Show(Person* p)
{
cout<<"Show Function is called."<<endl;
p->Show();
}
int main()
{
    string name,experience;
    int code,pay,Cas=0;
    while(cin>>name>>code>>pay>>experience)
    {
        Cas++;
        cout<<"CASE #"<<Cas<<":"<<endl;
        Person person(name,code);
        Account account(name,code,pay);
        Admin admin(name,code,experience);
        Master master(name,code,pay,experience);
        Show(&person);
        Show(&account);
        Show(&admin);
        Show(&master);
    }
    return 0;
}

这篇关于1479: 多重继承派生(3)--person、account、admin和master类的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



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

相关文章

hdu1171(母函数或多重背包)

题意:把物品分成两份,使得价值最接近 可以用背包,或者是母函数来解,母函数(1 + x^v+x^2v+.....+x^num*v)(1 + x^v+x^2v+.....+x^num*v)(1 + x^v+x^2v+.....+x^num*v) 其中指数为价值,每一项的数目为(该物品数+1)个 代码如下: #include<iostream>#include<algorithm>

BUUCTF靶场[web][极客大挑战 2019]Http、[HCTF 2018]admin

目录   [web][极客大挑战 2019]Http 考点:Referer协议、UA协议、X-Forwarded-For协议 [web][HCTF 2018]admin 考点:弱密码字典爆破 四种方法:   [web][极客大挑战 2019]Http 考点:Referer协议、UA协议、X-Forwarded-For协议 访问环境 老规矩,我们先查看源代码

多重背包转换成0-1背包

http://acm.hdu.edu.cn/showproblem.php?pid=2191 多重背包特点: 一种物品有C个(既不是固定的1个,也不是无数个) 优化的方法: 运用神奇的二进制,进行物品拆分,转化成01背包 物品拆分,把13个相同的物品分成4组(1,2,4,6) 用这4组可以组成任意一个1~13之间的数! 原理:一个数总可以用2^

JavaSE——封装、继承和多态

1. 封装 1.1 概念      面向对象程序三大特性:封装、继承、多态 。而类和对象阶段,主要研究的就是封装特性。何为封装呢?简单来说就是套壳屏蔽细节 。     比如:对于电脑这样一个复杂的设备,提供给用户的就只是:开关机、通过键盘输入,显示器, USB 插孔等,让用户来和计算机进行交互,完成日常事务。但实际上:电脑真正工作的却是CPU 、显卡、内存等一些硬件元件。

java线程深度解析(四)——并发模型(Master-Worker)

http://blog.csdn.net/daybreak1209/article/details/51372929 二、Master-worker ——分而治之      Master-worker常用的并行模式之一,核心思想是由两个进程协作工作,master负责接收和分配任务,worker负责处理任务,并把处理结果返回给Master进程,由Master进行汇总,返回给客

xss-labs-master通关教程

一.level1 先来进行一下代码审计 <?php ini_set("display_errors", 0);//关闭错误显示$str = $_GET["name"]; //接受URL来的get形式的name传参echo "<h2 align=center>欢迎用户".$str."</h2>";//在网页输出,并不是echo执行的,而是echo把HTML代码发送到浏览器,浏览器对发送的H

七、Maven继承和聚合关系、及Maven的仓库及查找顺序

1.继承   2.聚合   3.Maven的仓库及查找顺序

Dungeon Master -uva

一个简答的三维BFS遍历,我从中领悟到了惨痛的教训,关于栈的溢出!!! 不多说了。。郁闷 #include<stdio.h>#include<string.h>#include<stdlib.h>#define MAX_SIZE 50 + 10int Dung[MAX_SIZE][MAX_SIZE][MAX_SIZE];int time[MAX_SIZE][MAX_SIZE][M

OOP三个基本特征:封装、继承、多态

OOP三个基本特征:封装、继承、多态 C++编程之—面向对象的三个基本特征 默认分类 2008-06-28 21:17:04 阅读12 评论1字号:大中小     面向对象的三个基本特征是:封装、继承、多态。     封装 封装最好理解了。封装是面向对象的特征之一,是对象和类概念的主要特性。   封装,也就是把客观事物封装成抽象的类,并且类可以把自己的数据和方法只让可信