I wrote my code perfectly but the output should be like this:
new player has been created
new player has been created
new player has been created
new player has been created
new player has been created
kill him boy!FINISH HIM!!
4
1
this player is died and removed from the server
this player is died and removed from the server
this player is died and removed from the server
this player is died and removed from the server
this player is died and removed from the server
instead it gives me this:
new player has been created
new player has been created
new player has been created
this player is died and removed from the server
new player has been created
this player is died and removed from the server
new player has been created
this player is died and removed from the server
kill him boy!FINISH HIM!!
1
4
this player is died and removed from the server
this player is died and removed from the server
this player is died and removed from the server
this player is died and removed from the server
this player is died and removed from the server
what's wrong?
( I need to use the COD_player(string Username,string Password) constructor )
What I have tried:
#include<iostream>
#include<string>
using namespace std;
class COD_player{
string name,id,username,password;
int level;
bool gender;
static int shots,online_players,died_players;
public:
void set_counters1(){
int o;
this->online_players=o;
}
void set_counters2(){
int d;
this->died_players=d;
}
static int get_counters1(){
return online_players;
}
static int get_counters2(){
return died_players;
}
COD_player()
{
cout<<"new player has been created"<<endl;
name="";
id="";
username="";
password="";
level=0;
shots=0;
gender=false;
online_players++;
}
COD_player(string Username,string Password)
{
cout<<"new player has been created"<<endl;
this->username=Username;
this->password=Password;
online_players++;
}
void fire()
{
shots++;
cout<<"kill him boy!FINISH HIM!!"<<endl;
online_players--;
died_players++;
}
~COD_player()
{
cout<<"this player is died and removed from the server"<<endl;
online_players--;
died_players++;
}
};
int COD_player::online_players=0;
int COD_player::died_players=0;
int COD_player::shots=0;
int main()
{
string x,y;
COD_player p1=COD_player();
COD_player p2=COD_player();
COD_player p3=COD_player(x,y);
COD_player p4=COD_player(x,y);
COD_player p5=COD_player(x,y);
p1.fire();
cout<<COD_player::get_counters1();
cout<<endl;
cout<<p1.get_counters2();
cout<<endl;
return 0;
}