Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Implement a C++ program that helps to explain the syntax and the use of data str

ID: 3756714 • Letter: I

Question

Implement a C++ program that helps to explain the syntax and the use of data structures such as arrays and pointers. These data structures form part of the data members and constructors in a C++ class Declare the data members of Competition class as follows: (i) A string representing the title ofthe competition. (ii) An integer representing the number of players in the competition (ii) A dynamic location large enough to store the names of the players in the (iv) A dynamic location large enough to store the scores of the players in the (a) competition. The location is reference by a pointer string* players. competition. The location is reference by a pointer string* scores. (4 marks)

Explanation / Answer

// C++ class Competition

class Competition{

private:

       string title; // title of the competition

       int numPlayers; // number of players in the competition

       string *players; // dynamic array to hold the names of players whose size is determined by the number of players

       string *scores; // dynamic array to hold the scores of players whose size is determined by the number of players

      

public:

       // constructor to set the title and number of players and allocate memory enough to hold names and scores of players

       Competition(string title,int numPlayers)

       {

             this->title = title;

             this->numPlayers = numPlayers;

             players = new string[numPlayers]; // allocate memory for names of players

             scores = new string[numPlayers]; // allocate memory for scores of players

       }

};

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote