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

General Description: Write an application that allows the user to enter, view, s

ID: 3603137 • Letter: G

Question

General Description:

Write an application that allows the user to enter, view, search and sort statistics on a team of basketball players. The program should start by reading data from a file called “bballin.txt”, and should end by writing data to a file called “bballout.txt”.

A Statistic (stat) in the program consists of two numbers:

- number of points made

- number of points attempted.

A percentage is calculated with the formula (100*made)/attempted, rounded off. When the points attempted is zero, the percentage is zero.

Percentages are printed in the format mm/aa (nnn%) where mm is the points made, aa is the points attempted, and nnn is the percentage [note: always length 12]. Examples:

0/0( 0%) 12/12 (100%) 5/10 ( 50%)

A Player has the following data kept:

- name

- jersey number

- number of games played (max 40) – [note: this number will be the same for all players] and three lists of stats, one stat per game per list:

- 3-point field goals

- 2-point field goals

- free throws

Other data can be calculated from these stats:

- A stat of the overall 3-pointers (sum of 3-pointers made/attempted in all games).

- A stat of the overall 2-pointers (sum of 2-pointers made/attempted in all games).

- A stat of the overall free throws (sum of free throws made/attempted in all games).

- A list of total points scored, one for each game, calculated as:

3-pointers-made * 3 + 2-pointers-made * 2 + free-throws-made.

Printing a report for a player should look like this example. The name is “as is” read from the file. The jersey number is in square brackets.

A Team consists of:

- A list of Players

- The number of players (max 10)

- The number of games (max 15)

A user should be able to perform the following operations (one method each) on a team:

Print the Team Report:

Print the stat report for all players with a blank line between each player. Use the report format shown above. The program should pause after printing the last player.

Add a game to each player on the Team:

The user is asked to enter the stats for a new game for every player in the list.

For each player, it should:

- Display the player’s name and jersey number in square

brackets.

- Ask the user to enter the shots made and attempted for

- 3-pointers

- 2-pointers

- Free throws -

If the program already has the maximum number of games allowed, it should print a message and not add a new game.

Display a player by jersey number:

The program should ask the player to enter the jersey number of the player to find. When a player with the entered number is not found, it should print “Player not found”.

When the player is found, it should print the player’s stat report as usual.

Remove a player from the Team:

The program should ask the player to enter the jersey number of the player to remove. When a player with the number entered is found, the program removes the player from the list and prints a message “Player name [jersey] removed”. When the player is not found, the program prints “Player not found”.

Sort Team by Name:

The program sorts its internal list of players by name (names “as is”...no need to “parse” the name for first/last/etc.). It simply prints a message “Players sorted by name” on the screen.

Sort Team by Jersey:

The program sorts its internal list of players by jersey number. It simply prints a message “Players sorted by jersey” on the screen.

Read Team data:

On startup, the program should read the current team data from a file named “bballin.txt”. The format of the file is as follows:

- The first line contains the number of players and number of games.

- For each player:

o The first line contains the jersey number

and name. The name may contain

spaces.
o For each game, there is one line of six

numbers:
3-pointers made
3-pointers attempted 2-pointers made
2-pointers attempted Free throws made
Free throws attempted

Here is the file “bballin.txt”.

Write Team Data:

When the program ends, it should write the current data to a text file named “bballout.txt” in the exact same format at the input file.

Overall Operation:

The program should start by printing a logo with your name and section.

It should then display a menu of options and allow the user to an option. The program performs the selected option. When an invalid option is chosen, the program prints an error message. This repeats until the user enters the exit option.

Here is the main function that you should use

There should be a set() method and a get() method for each member.
o Each set() should validate the given arguments when needed (ex: points made <= points

attempted). When arguments are invalid, do not change the members and print an

error message.
o set()s may be combined where it makes sense. Ex: for a stat, set(made,attempted) is good.

Specific Requirements

- Do not use file streams (ifstream, ofstream) in any method besides the read() and write() methods of class team. Use methods of any sub-objects to set() and get() data from them.

Thank you in advance

if there is something not clear please let me know!!

Carrot, Carl [45] Game 3-Point FGS 2-Point FGs Free Throws Total 5/ 6 ( 83%) 1.8/22 ( 82%) 5/ 6 ( 83%) 3/ 4 ( 75%) 19 35 ( 54%) 3/ 4 ( 75%) 10/11 (91%) 22/30 (73%) 10/11 (91%) ALL 18/21(86%) 59/87 (68%) 18/21 (86%) 56 50 84 190

Explanation / Answer

#include <iostream>
//#include "team.h"
#include <vector>
#include <string>
#include <sstream>
#include <fstream>
#include <ctype.h>


using namespace std;

class Game{

int threePointsGoalMade;
int threePointsGoalAttempted;
int twoPointsGoalMade;
int twoPointsGoalAttempted;
int freeThrowsMade;
int freeThrowsAttempted;
  
public:
void setthreePointsGoalMade(int threePointsGoalL){
threePointsGoalMade = threePointsGoalL;
}
  
int getthreePointsGoalMade(){
return threePointsGoalMade;
}
  
void setthreePointsGoalAttempted(int threePointsGoalAttempted){
threePointsGoalAttempted = threePointsGoalAttempted;
}
  
int getthreePointsGoalAttempted(){
return threePointsGoalAttempted;
}
};

class Player {
  
string name;
int jerseyNum;
std::vector<Game> playerStats;
  
public:
  
void setName(string nameL){
name = nameL;
}
  
void setJerseyNum(int jerseyNumL){
jerseyNum = jerseyNumL;
}
  
string getName(){
return name;
}
  
int getJerseyNum(int jerseyNumL){
return jerseyNum;
}
  
void addPlayerStats(Game playerStatsL){
playerStats.push_back(playerStatsL);
}
  
std::vector<Game> getPlayerStats(){
return playerStats;
}
};

class Team {
  
int playerCount;
int gameCount;
std::vector<Player> players;

public:
  
void setPlayerCount(int count){
playerCount = count;
}
void setGameCount(int gCount){
gameCount = gCount;
}
  
int getGameCount(){
return gameCount;
}
  
int getPlayerCount(){
return playerCount;
}
  
void read();
// void print();
void addPlayer(Player playerL);
void displayPlayer();
// void sortByName();
// void sortByJersey();
// void removePlayer();
// void write();
};

void Team::addPlayer(Player playerL) {
players.push_back(playerL);
}

void Team::displayPlayer(){
cout << " Players " << playerCount << endl;
cout << " Games " << playerCount << endl;
for(int x=0; x<players.size(); x++)
{
cout << " Playter Name " << players[x].getName() << endl;
for(int y=0; y<players[x].getPlayerStats().size(); y++)
{
cout << " Games Points Details " << players[x].getPlayerStats()[y].getthreePointsGoalAttempted() << endl;
}   
}
  
}

void Team::read(){
  
vector<string> fileTokens;
fileTokens.push_back("4 3");
fileTokens.push_back("15 Smith, Sam");
fileTokens.push_back("0 0 2 3 3 5");
fileTokens.push_back("2 3 5 6 2 2");
fileTokens.push_back("3 7 0 5 1 8");
fileTokens.push_back("22 Fender, Freddy");
fileTokens.push_back("0 0 4 4 4 6");
fileTokens.push_back("4 5 12 24 4 5");
fileTokens.push_back("3 4 18 30 4 4");
  
std::ifstream file("bballin.txt");
std::string line;
std::vector<Team> tokens;
int acountNum = 0;
//while(std::getline(file, line)) { // ' ' is the default delimiter
for(int y=0; y<fileTokens.size(); y++)
{
cout<<fileTokens[y]<<" ";
line = fileTokens[y];
  
std::vector<string> internal;
std::stringstream ss(line); // Turn the string into a stream.
string tok;

while(std::getline(ss, tok, ' ')) {
internal.push_back(tok);
}
Player p1;
for(int x=0; x<internal.size(); x++)
{
if(y == 0){
setPlayerCount(std::atoi(internal[0].c_str()));
setGameCount(std::atoi(internal[1].c_str()));
}else {
if (isdigit(internal[1].c_str()[0])){
p1.setName(internal[1]);
p1.setJerseyNum(std::atoi(internal[1].c_str()));
}else{
Game g ;
g.setthreePointsGoalMade(std::atoi(internal[0].c_str()));
g.setthreePointsGoalAttempted(std::atoi(internal[0].c_str()));
p1.addPlayerStats(g);
}
}
}
addPlayer(p1);
}
// }
//}

}

//------------------------------------------------------------------
// printLogo
//------------------------------------------------------------------
void printLogo() {
cout << "----------------------------------------------------- ";
cout << " BASKETBALL STATS SUPREME ";
cout << " by Xxxx Yyyyy ";
cout << "----------------------------------------------------- ";
} // printLogo()

//------------------------------------------------------------------
// askMenuOption
//------------------------------------------------------------------
// Returns: the menu option entered by the user
// Prints a menu and allows the user to enter a value. It extracts
// and capitalizes the first letter of the user's input.
//------------------------------------------------------------------
char askMenuOption() {
string choice = "D";
cout << endl;
cout << "P - Print team ";
cout << "A - Add game ";
//cout << "N - New player ";
cout << "D - Display player ";
cout << "R - Remove player ";
cout << "N - Sort list by name ";
cout << "J - Sort list by jersey number ";
cout << "X - Exit ";
cout << "Enter selection: ";
// cin >> choice;
return (char)(toupper(choice[0])); // upper case of first character
} // askMenuOption()

Team t;

//------------------------------------------------------------------
// main
//------------------------------------------------------------------
int main() {
// create a team object
char option = 'D'; // menu option

// print logo and read data from input file on startup
printLogo();
option = askMenuOption();
t.read();

// repeat menu until eXit is selected
do {
option = askMenuOption();
switch (option) {
// case 'P': t.print(); break;
// case 'A': t.addGame(); break;
case 'D': t.displayPlayer();
option = 'X';
break;
// case 'N': t.sortByName(); break;
// case 'J': t.sortByJersey(); break;
// case 'R': t.removePlayer(); break;
// case 'X': t.write(); break;
default: cout << "Invalid option! Try again! ";
}
} while (option != 'X');

// system("pause");
return 0;
} // main()