Code
Code
```cpp
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
class Player {
public:
string playerName;
int totalScore;
int ballsPlayed;
playerName = name;
};
int main() {
string playerNames[numPlayers] = {
};
Player players[numPlayers];
players[i].setName(playerNames[i]);
while (true) {
if (run == -1) {
players[i].ballsPlayed++;
break;
} else {
cout << "Ball " << players[i].ballsPlayed + 1 << ": " << run << " runs\n";
players[i].totalScore += run;
players[i].ballsPlayed++;
cout << "Total balls played by " << players[i].playerName << ": " << players[i].ballsPlayed << "\n\n";
cout << "Player: " << players[i].playerName << ", Score: " << players[i].totalScore << ", Balls Played: "
<< players[i].ballsPlayed << "\n";
manOfTheMatch = &players[i];
cout << "\nMan of the Match: " << manOfTheMatch->playerName << " with " << manOfTheMatch-
>totalScore << " runs\n";
return 0;
```
### Explanation:
1. **Include Directives:**
- `#include <iostream>`: Includes the input-output stream library for console input and output.
- `#include <cstdlib>`: Includes the C standard library for functions like `rand()`.
- `#include <ctime>`: Includes the C time library for functions like `time()`.
- `using namespace std;`: Allows us to use names from the standard library without the `std::` prefix.
3. **Player Class:**
- `class Player { ... };`: Defines a `Player` class to store each player's information.
- `void setName(string name) { playerName = name; }`: Method to set the player's name.
4. **Main Function:**
- `srand(time(0));`: Seeds the random number generator with the current time to ensure different
random numbers each run.
- `for (int i = 0; i < numPlayers; ++i) { players[i].setName(playerNames[i]); }`: Loop to assign names to
each player.
- `for (int i = 0; i < numPlayers; ++i) { ... }`: Loop through each player.
- `int run = -1 + rand() % 8;`: Generate a random number between -1 and 6 (excluding 5).
- `if (run == -1) { ... }`: If the player is out, print "OUT" and break the loop.
- `else { ... }`: Otherwise, add the score to `totalScore` and increment `ballsPlayed`.
- `Player* manOfTheMatch = &players[0];`: Initialize the pointer for "Man of the Match".
- `for (int i = 0; i < numPlayers; ++i) { ... }`: Loop through each player to print their summary and
determine "Man of the Match".
- `cout << "\nMan of the Match: " << manOfTheMatch->playerName << " with " << manOfTheMatch-
>totalScore << " runs\n";`: Print the name and score of the "Man of the Match".
### Summary:
- The match summary and "Man of the Match" are displayed at the end based on the players'
performance.