A team has two types of players: Batsman, Baller. It is required to assess their performance in a particular tournament and thus find out the best player in each of the categories. The assessment criterion for each type of player is different. For batsman, it is the average of his scores throughout the tournament. For ballers it’s the number of wickets taken in the tournament. Thus, the performance is determined based on score made (in-case of batsman), wickets taken (in-case of baller). There should be a display function that displays all the information of player of a particular category including team name.

Design a class hierarchy for the players in which you are required to find out the best player in each category according to their performance in a tournament. For this, you need to identify classes/objects, attributes against each class/object, operations against each class/object, type of association between (aggregation, composition, or inheritance) classes/objects. After identifying them, you need to make an object model. Your design should be such that which can be used to declare a list of players belonging to each category.

I don't know C++, but here's how I would set something like this up in PHP:

// All players have a name and belong to a team
class Player {
    private $name;
    private $team;

    // Create a new player by passing in their name and team
    public function __construct($name, $team) {
        $this->name = $name;
        $this->team = $team;
    }
}

// A baller is a type of player
class Baller extends Player {
    private $wickets = array();

    // Add the # of wickets for a tournament onto the array of wickets for this player
    public function new_tournament($wickets) {
        $this->wickets[] = $wickets;
    }

    // Print out a list of the number of wickets taken for this player in each tournament
    public function display() {
        print_r($this->wickets);
    }

    // Return a sum of this player's total wickets taken across all tournaments
    public function assessment() {
        return array_sum($this->wickets);
    }
}

// A batsman is another type of player
class Batsman extends Player {
    private $scores = array();

    // Add a new score for a tournament to the array of this player's tournament scores
    public function new_tournament($score) {
        $this->scores[] = $score;
    }

    // Return this player's average score across all of his tournaments
    public function assessment() {
        return array_sum($this->scores) / count($this->scores);
    }

    // Print out a list of this player's scores
    public function display() {
        print_r($this->scores);
    }
}

$player1 = new Batsman('Dave', 'Team DaniWeb');
$player2 = new Batsman('Joey', 'Team DaniWeb');
$player3 = new Baller('Mike', 'Team DaniWeb');

$player1->new_tournament(5);
$player3->new_tournament(1);
$player3->display();

This does almost everything that your assignment needs, but it's written in PHP, which is the language that I am most comfortable with, as opposed to C++, which I haven't looked at in over 20 years. You should be able to follow the logic here, of what I've written, and use it to create pseudocode, and then translate it into C++, to complete your assignment.

I've done enough of the work here that it shouldn't be completely overwhelming where to begin, but there's enough left to do that you will still need to understand what I did, and follow the code I have, and know what to change about it, to complete your assignment. Remember, this is PHP, a web development language, and not C++, although the syntax is somewhat similar. The main differences you'll notice are that PHP variables begin with $, and C++ is a strongly typed language, meaning that you can't just declare an empty array as I have, but rather a specific number of integers in a list.

Good luck!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.