Answer to Question #190494 in C++ for Manahil Faisal

Question #190494

You've to develop table tennis fantasy league.Here're details of league:no. of team (4) and no. of player/team (3). Each team will have to play

other team twice,so you can calculate total number of matches.

1.addPlayers():add player data.

Sr. No. Name Type Point Availability

1 Name Player 1 Attacking 35.93 true

3.assignRanks(): Assign ranking to 4 teams on the basis of random number.

4.teamSelection(): Form team on basis of strategy,defensive team will prefer two defensive

players and one attacking player.Whereas an attacking team will prefer two attacking players and

one defensive player.

6.generateMatchStats():This function will generate match status.Assign winning team players’ point

b/w 10 & 20 randomly. For losing team assign them point between 5 & 10 randomly.

7.bestPlayersInMatch():Display information of best player of both teams

8.UpdatePlayerPoints():After match update ranking point of players

9.printLeaderBoard():Print sorted list of player in all teams


1
Expert's answer
2021-05-07T23:42:05-0400
#include<iostream>
using namespace std;

// class declaration player
class Player{
string name,type;
bool availability;
double points;
// default constructor
public:
    Player(){

    }
    // parametrized constructor
    Player(string name,string type,double points,double availability){
        this->name=name;
        this->type=type;
        this->availability=true;
        this->points=points;
    }
    // getter function
string getName(){
return name;
}
string getType(){
return type;
}
double getPoints(){
return points;
}
bool getAvail(){
return true;
}

};

// class declaration team
class Team{
    public:
        string Name;
        int ranking;
        Player* tPlayers;

        //setter function
        void setRanking(int ranking){
        this->ranking=ranking;

        }
};

class Match{
public:
    int match;
    Team hostTeam, guestTeam;
    Team *team;
    int counting=0;
    Player* matchPlayer;
    int teamSize;
    Match(){
    team=new Team[4];
    teamSize=15;
    matchPlayer=new Player[teamSize];

    }

    int length(){
    return counting;
    }

    void addPlayer(){
    cout<<"Enter the total number of player in the team:"<<endl;
    cin>>teamSize;
    matchPlayer=new Player[teamSize];
    string playerName,type;
    double points;
    bool avail;

    for(int i=0;i<teamSize;i++){
            cout<<"---Player-----"<<i+1<<endl;
            cout<<"Enter Player Name:"<<endl;
            cin>>playerName;
            cout<<"Enter Player Type:"<<endl;
            cin>>type;
            points = 30 + static_cast <float> (rand())/( static_cast <float> (RAND_MAX/(40-30)));
            matchPlayer[i] = Player(playerName, type, points, true);

    }
    }

    Player* outPlayer(string type){

        static Player *players = new Player[teamSize];

        for(int i = 0; i<teamSize; i++){

            if(matchPlayer[i].getType() == type)
                players[counting++] = matchPlayer[i];
            }

        return players;
        }


    void provideRank(){
        int randomRank=rand()%4+1;
        for(int i=0;i<4;i++){
            team[i].setRanking(randomRank);
        }

        cout<<"\n The Rank has been allocated."<<endl;
    }
};



int main(){
Match match;
match.addPlayer();
string playerType;
cout<<"Enter player type:"<<endl;
cin>>playerType;

Player *players=match.outPlayer(playerType);
int size=sizeof(players)/sizeof(players[0]);
cout<<"The list of player type:"<<playerType<<endl;

for(int i = 0; i<match.length(); i++){

cout<<"\n Player"<<i+1<<endl;
cout<<"Name: "<<players[i].getName()<<endl;
cout<<"Points: "<<players[i].getPoints()<<endl;

}

match.provideRank();

return 0;
}

Output:






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