Game.h
#pragma once
class person
{
int m_id;
const char* m_name;
int m_score;
int m_money;
private:
static int m_count;
static int m_averagescore;
public:
person(int id, char* name);
static int getcount();
static int getaveragescore();
void setplayer(int id, char* name);
void showplayer();
void chaegemoney(unsigned int money);
void usemoney(unsigned int money);
~person() { delete[]m_name; };
};
玩家.cpp
#include<iostream>
using namespace std;
#include"Gamer.h"
person::person(int id = 0,char * name = "default")
{
m_id = id;
m_score = 0;
m_money = 0;
m_count++;
m_name = name;
}
int person::m_count = 0;
int person::m_averagescore = 0;
int person::getcount()
{
return m_count;
}
int person::getaveragescore()
{
return m_averagescore;
}
void person::setplayer(int id, char* name)
{
m_id = id;
m_name = name;
}
void person::showplayer()
{
cout << "id:[" << m_id << "]\n" << "name:[" << m_name << "]\n"
<< "score:[" << m_score << "]\n" << "money:[" << m_money << "]\n"
<< "cout:[" << m_count << "]\n" << "averagescore:[" << m_averagescore << "]" << endl;
}
void person::chaegemoney(unsigned int money)
{
m_money += money;
}
void person::usemoney(unsigned int money)
{
m_money -= money;
m_score = money;//积分获取方式,累计消费
m_averagescore += (m_score / m_count);//所有玩家得分平均值
}
int main()
{
person _A, _B;
_A.setplayer(4, "course04");
_A.chaegemoney(100);
_A.usemoney(90);
_A.showplayer();
_B.setplayer(44, "course044");
_B.chaegemoney(444);
_B.usemoney(111);
_B.showplayer();
system("pause");
return 0;
}
不知道怎么改,help