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

An indoors soccer team needs to have a program that hold the statistics (just th

ID: 3762805 • Letter: A

Question

An indoors soccer team needs to have a program that hold the statistics (just the scored goals of the team). The team has 5 players and an extra goalkeeper.

Each player provides the following information:
Name
Description (Position, speed, and more general characteristics)
Scored goals in each game (3 games played so far)

Write a program that reports the following information to the output file “soccer_statistics.txt”

-Player1’s name Player1’s description goal average;
-Player2’s name Player2’s description goal average;
……………………. ………………………
Total’s team average Average

   Requirements of the program:

Create a class called player: Write the proper attributes
Name (string), Description (pointer to char), goals for every game (array of int) and the correct methods (Accessors and mutators that access and update the info of the attributes. Create the right spec file and implementation file. (.h and .cpp files)

Create an array of the 5 players and initialize their values to name=””, Description=null and goals to [0,0,0,0,0] through a constructor.
The program asks to enter the players info to the user and keep that info in local variables. Then it should update the objects attributes through the mutators.
Create an extra object of the class player (goalkeeper2) and initialize it with the value of the goalkeeper object.(1st in the array) After initializating it, the program should ask for the player’s name and run its mutator function to update the name accordingly.
Use the iomanipulators to display the average results in the output file. Use fixed, setw(), setprecision(2), and showpoint.

Explanation / Answer

Player.h:

#ifndef PLAYER_H
#define PLAYER_H

#include<string>
using namespace std;
class Player
{
public:
Player();
Player(string,char*,int[]);
void setName(string name);
string getName();
char* getDescription();
void setDescription(char*);
void setGoals(int goals[5]);
int* getGoals();
private:
string name;
char* description;
int goals[5];
};

#endif // PLAYER_H

//##########################################################################

Player.cpp:

#include "Player.h"

Player::Player()
{
this->name = "";
this->description = NULL;
for(int i=0;i<5;i++)
goals[i] = 0;
}
Player::Player(string name,char* description,int goals[])
{
this->name = name;
this->description = description;
for(int i=0;i<5;i++)
this->goals[i] = goals[i];
}
void Player::setName(string name)
{
this->name = name;
}
string Player::getName()
{
return this->name;
}
char* Player::getDescription()
{
return this->description;
}
void Player::setDescription(char* description)
{
this->description = description;
}
void Player::setGoals(int goals[5])
{
for(int i=0;i<5;i++)
this->goals[i] = goals[i];
}
int* Player::getGoals()
{
return this->goals;
}

//####################################################################################

main.cpp:

#include <fstream>
#include <iostream>
#include "Player.h"

using namespace std;

int sum(int goals[5])
{
int ret = 0;
for(int i=0;i<5;i++)
ret += goals[i];
return ret;
}
int main()
{
Player players[5];
string name;
char description[100];
int goals[5];
for(int i=0;i<5;i++)
{
cout<<"Enter the name of the player: ";
cin>>name;
char skip;
cin.get(skip);
cout<<"Enter the description: ";
cin.getline(description,100);
for(int j=0;j<5;j++)
{
cout<<"Enter number of goals in game "<<(j+1)<<": ";
cin>>goals[j];
}
players[i].setName(name);
players[i].setDescription(description);
players[i].setGoals(goals);
}
Player goalKeeper;
goalKeeper.setName(players[0].getName());
goalKeeper.setDescription(players[0].getDescription());
goalKeeper.setGoals(players[0].getGoals());

cout<<"Enter the goalkeeper2 name: ";
cin>>name;
goalKeeper.setName(name);


cout<<" "<<endl;
ofstream outfile;
outfile.open("soccer_statistics.txt");

int totalGoals = 0;
for(int i=0;i<5;i++)
{
totalGoals += sum(players[i].getGoals());
cout<<"Player"<<(i+1)<<"'s name: "<<players[i].getName()<<" Description: "<<players[i].getDescription()<<" Goal avg: "<<(sum(players[i].getGoals())/5.0)<<endl;
outfile<<"Player"<<(i+1)<<"'s name: "<<players[i].getName()<<" Description: "<<players[i].getDescription()<<" Goal avg: "<<(sum(players[i].getGoals())/5.0)<<endl;
cout<<endl;
}

cout<<"Goalkeeper "<<"'s name: "<<goalKeeper.getName()<<" Description: "<<goalKeeper.getDescription()<<" Goal avg: "<<(sum(goalKeeper.getGoals())/5.0)<<endl;
outfile<<"Goalkeeper "<<"'s name: "<<goalKeeper.getName()<<" Description: "<<goalKeeper.getDescription()<<" Goal avg: "<<(sum(goalKeeper.getGoals())/5.0)<<endl;
cout<<endl;
outfile<<"----------------- --------------------"<<endl;
outfile<<"Team's average: "<<(totalGoals/25.0)<<endl;

return 0;
}

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