Answer to Question #230079 in C++ for mahnoor

Question #230079


 


 

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.

 


1
Expert's answer
2021-08-27T03:25:13-0400


#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS