#include<iostream>
#include<string>
#include<map>
#include<cstdlib>
using namespace std;
class User
{
public:
string rank[3] ={ "beginner", "professional", "expert"};
string get_name();
void login();
void logout();
bool is_online();
int get_login_times();
int get_played_matches();
int get_won_matches();
int get_won_ratio();
string get_rank();
void play_with(User* another, bool win);
static User *getUser();// To get the guest
static User *getUser(string name);// To get the user
static map<string,User*>user;
private:
string name_;
int login_time;
int played_matches;
int won_matches;
bool is_login;
};
string User::get_name()
{
return this->name_;
}
void User::login()
{
this->is_login = 1;
}
void User::logout()
{
this->is_login = 0;
}
bool User::is_online()
{
return this->is_login;
}
int User::get_login_times()
{
return this->login_time;
}
int User::get_played_matches()
{
return this->played_matches;
}
int User::get_won_matches()
{
return this->won_matches;
}
int User::get_won_ratio()
{
return played_matches
? double(this->won_matches) / (this->played_matches) * 100
:0.0;
}
string User::get_rank()
{
if (this->played_matches>= 50&& this->get_won_ratio >= 70)
return User::rank[1];
if (this->played_matches >= 100 && this->get_won_ratio >= 80![图片说明](https://img-ask.csdn.net/upload/201605/06/1462520992_907853.png))
return User::rank[2];
else
return User::rank[0];
}
void User::play_with(User* another, bool win)
{
if (this->is_login&&another->is_login)
{
this->played_matches++;
another->played_matches++;
win ? (this->won_matches++) : (another->won_matches++);
}
}
User* User::getUser()// To get the guest
{
User* p = new User;
p->is_login = 1;
p->login_time = 1;
p->name_ = "guest";
char buffer[16];
static int id = 0;
_itoa(id++, buffer, 10);
p->name_ += buffer;
p->played_matches = 0;
p->won_matches=0;
user[p->name_] = p;
return p;
}
User* User::getUser(string name)// To get the user
{
map<string, User*>::iterator it;
it = user.find(name);
if (it != user.end())
return it->second;
else
{
User* p = new User;
p->is_login = 1;
p->login_time = 1;
p->name_ = name;
p->played_matches = 0;
p->won_matches=0;
user[p->name_] = p;
return p;
}
}
int main()
{
User *guest0 = User::getUser();
User *guest1 = User::getUser();
guest0->login();
guest0->is_online(); // true
guest0->logout();
guest0->is_online(); // false
guest1->get_login_times(); // 0
User *maoge = User::getUser("Maoge");
maoge->get_name(); // Maoge
maoge->login();
maoge->logout();
maoge->login();
maoge->login();
maoge->get_login_times(); // 2
User *maogeCopy = User::getUser("Maoge");
User *kuanye = User::getUser("Kuanye");
kuanye->play_with(maoge, true);
kuanye->get_won_matches(); // 0
kuanye->login();
kuanye->play_with(maoge, true);
kuanye->get_won_matches(); // 1
maogeCopy->get_played_matches(); // 1
return 0;
}
LNK2001一个无法解析的外部命令还有>=不能转化的问题
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答
- threenewbee 2016-05-06 15:42关注
this->get_won_ratio
->
this->get_won_ratio()还有一些类似的错误,照着一样的修改
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥50 有数据,怎么建立模型求影响全要素生产率的因素
- ¥50 有数据,怎么用matlab求全要素生产率
- ¥15 TI的insta-spin例程
- ¥15 完成下列问题完成下列问题
- ¥15 C#算法问题, 不知道怎么处理这个数据的转换
- ¥15 YoloV5 第三方库的版本对照问题
- ¥15 请完成下列相关问题!
- ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
- ¥15 求daily translation(DT)偏差订正方法的代码
- ¥15 js调用html页面需要隐藏某个按钮