P481tabtenn0
编程环境为Qt Creator 4.0.3 (Community)
tabtenn0.h
#ifndef TABTENN0_H
#define TABTENN0_H
#include <string>
using namespace std;
//简单的基类
class TableTennisPlayer
{
private:
string firstname;
string lastname;
bool hasTable;
public:
TableTennisPlayer(const string &fn="none",
const string &ln="none",bool ht=false);
void Name() const;
bool HasTable() const { return hasTable;};
void ResetTabel(bool v) {hasTable=v;}
};
//简单的继承类
class RatePlayer:public TableTennisPlayer
{
private:
unsigned int rating;
public:
RatePlayer(unsigned int r=0,const string &fn="none",
const string &ln="none",bool ht=false); //继承类的构造函数
RatePlayer(unsigned int r,const TableTennisPlayer &tp);
unsigned int Rating() const{return rating;}
void ResetRating(unsigned int r){rating=r;}
};
#endif // TABTENN0_H
main.cpp
#include <iostream>
#include "tabtenn0.h"
using namespace std;
void Show(const TableTennisPlayer &rt);
TableTennisPlayer::TableTennisPlayer(const string &fn,
const string &ln, bool ht):firstname(fn),lastname(ln),hasTable(ht){}
void TableTennisPlayer::Name() const
{
std::cout<<lastname<<","<<firstname;
}
RatePlayer::RatePlayer(unsigned int r,
const string &fn,
const string &ln, bool ht):TableTennisPlayer(fn,ln,ht)
{
rating=r;
}
RatePlayer::RatePlayer(unsigned int r,
const TableTennisPlayer &tp):TableTennisPlayer(tp),rating(r)
{
}
int main(int argc, char *argv[])
{
cout << "Hello World!" << endl;
TableTennisPlayer player1("Tara","Boomdea",false);
RatePlayer rplayer1(1140,"Mallory","Duck",true);
rplayer1.Name(); //继承的类使用基类的方法
if(rplayer1.HasTable())
{
cout<<":has a table\n"<<endl;
}
else
{
cout<<":hasn't a table"<<endl;
}
player1.Name(); //基类使用基类的方法
if(player1.HasTable())
{
cout<<":has a table"<<endl;
}
else
{
cout<<"hasn't a table"<<endl;
}
//使用基类的对象初始化继承类
RatePlayer rplayer2(1212,player1);
cout<<"Name:";
rplayer2.Name();
cout<<": Rating:"<<rplayer2.Rating()<<endl;
Show(player1);
Show(rplayer1);
//将基类对象初始化为派生类对象
RatePlayer olaf1(1840,"Olaf","Loaf",true); //派生类对象
TableTennisPlayer olaf2(olaf1); //基类对象
olaf2.Name();
return 0;
}
void Show(const TableTennisPlayer &rt)
{
using std::cout;
cout<<"Name:";
rt.Name();
cout<<"\nTable:";
if(rt.HasTable())
{
cout<<"yes"<<endl;
}
else
{
cout<<"no"<<endl;
}
}
运行结果如下

P481tabtenn0的更多相关文章
随机推荐
- 用Java实现MVPtree——MVPtree核心算法代码的搭建
项目需要,需要把MVPtree这种冷门的数据结构写入Java,然网上没有成形的Java实现,虽说C++看惯了不过对C++实现复杂结构也是看得蒙蔽,幸好客户给了个github上job什么的人用Java写 ...
- fjwc2019 D2T3 排序(堆)
#183. 「2019冬令营提高组」排序 贴一段ppt 考虑模拟出这个算法进行k轮(即外层的i循环到k)时的序列,之后再暴力模拟零散的步. 考虑这个算法在01序列上的表现,k轮后实际上就是将最开始的不 ...
- NT1_keras下搭建一个3层模型并且修改。
In [1]: import keraskeras.__version__ C:\ProgramData\Anaconda3\lib\site-packages\h5py\__init__.py:36 ...
- 一道cf水题
题意:输入数字n表示字符串中元素个数,字符串中只含有RGB三个字符,现在要求任意两个相同的字符他们的下标之差能整除3. 思路:任意两个相同的字符的下标能整除3,也就是任意三个为一组的字符串当中的字符不 ...
- ubuntu安装微软雅黑和Consolas字体
原文:http://fooler5.iteye.com/blog/2406227 [字体下载] YaHeiConsolas.tar:http://www.mycode.net.cn/wp-conten ...
- P3979 遥远的国度
P3979 遥远的国度 思路 一开始我用这个函数得到左端点 int get_l(int x,int y) { if(top[x]==top[y]) return son[x]; int last=to ...
- Docker 安装Hadoop HDFS命令行操作
网上拉取Docker模板,使用singlarities/hadoop镜像 [root@localhost /]# docker pull singularities/hadoop 查看: [root@ ...
- SpringBoot 使用jwt进行身份验证
这里只供参考,比较使用jwt方式进行身份验证感觉不好,最不行的就是不能退出 登陆时设定多长过期时间,只能等这个时间过了以后才算退出,服务端只能验证请求过来的token是否通过验证 Code: /** ...
- 比酒量|2012年蓝桥杯B组题解析第三题-fishers
(5')比酒量 有一群海盗(不多于20人),在船上比拼酒量.过程如下:打开一瓶酒,所有在场的人平分喝下,有几个人倒下了.再打开一瓶酒平分,又有倒下的,再次重复...... 直到开了第4瓶酒,坐着的已经 ...
- Almost Union-Find (并查集+删除元素)题解
思路: 当时只有暴力的思想,1.3都很好达到,只要加一个sum[ ]和num[ ]就可以,但是2比较麻烦,不知道谁以p为根,就想直接扫描然后一个个和p脱离关系,果然超时emmm.通常的想法是我们先用一 ...