A player need to be selected as vice-captain of a sports team on the basis of his wins and losses over his career. Hence positons remain the same for selection as a vice captain. Write a class of a player, define relative data members and member function (setter, getters). Also add the wins and lose member functions.
#include <iostream>
using namespace std;
class player{
private:
string name;
int id;
int number_of_wins;
int number_of_loses;
public:
void setName(string n){
name=n;
}
string getName(){
return name;
}
void setID(int i){
id=i;
}
int getID(){
return id;
}
void setNumberOfWins(int w){
number_of_wins=w;
}
int getNumberOfWins(){
return number_of_wins;
}
void setNumberOfLoses(int l){
number_of_loses=l;
}
int getNumberOfLoses(){
return number_of_loses;
}
};
int main()
{
player p1;
p1.setName("John");
p1.setID(1234);
p1.setNumberOfWins(10);
p1.setNumberOfLoses(2);
cout<<"\nName: "<<p1.getName();
cout<<"\nID: "<<p1.getID();
cout<<"\nNumber of wins: "<<p1.getNumberOfWins();
cout<<"\nNumber of loses: "<<p1.getNumberOfLoses();
return 0;
}
Comments
Leave a comment