+1 (315) 557-6473 

Create A Program to Create Basketball Statistics Analyzer in C++ Assignment Solution.


Instructions

Objective
To complete a C++ assignment, you'll need to write a program that functions as a basketball statistics analyzer. This program should be designed to efficiently gather and analyze basketball game data, providing insights into player performance, team statistics, and other relevant metrics. By utilizing C++ language features, you can develop a robust and user-friendly application that handles data input, processing, and output effectively. This assignment will not only test your coding skills but also your ability to design a practical solution for real-world data analysis needs.

Requirements and Specifications

program to create basketball statistics analyzer in C++

Source Code

#include

#include

// Structure that stores information about model houses

struct Game {

char name[100];

int minutes;

int points;

};

// identifiers

struct Game getLongestGame(struct Game games[1000], int n_games);

struct Game getHigherScoreGame(struct Game games[1000], int n_games);

int main() {

// char array to store file names

char file_name[100];

// array fo struct to store games

struct Game games[1000];

// Ask for file name

std::cout << "Enter the name of the file you wish to analyze: ";

std::cin.getline(file_name, 100, '\n');

// variable to count the number of games read

int n_games = 0;

// read file

FILE* myFile;

myFile = fopen(file_name, "r");

// check that file opened correctly

if(myFile == NULL) {

printf("File %s could not be opened.", file_name);

return 1;

}

char name[100];

char line[100];

int minutes, points;

bool isInt = false;

int line_id = 0;

while(fscanf(myFile, "%s %i %i", &name, &minutes, &points) == 3)

{

// Create game

struct Game game;

memcpy(&game.name, &name, 100);

game.minutes = minutes;

game.points = points;

games[n_games] = game;

n_games++;

}

fclose(myFile);

// get longest game

struct Game longest_game = getLongestGame(games, n_games);

// Get game with higher score

struct Game higher_score_game = getHigherScoreGame(games, n_games);

std::cout << "Player with the highest minutes is: " << longest_game.name << std::endl;

std::cout << "Player with the highest point total is: " << higher_score_game.name << std::endl;

std::cout << std::endl << std::endl;

system("pause");

return 0;

}

struct Game getLongestGame(struct Game games[1000], int n_games)

{

// get game with the longest duration

Game ret_game = games[0];

for(int i = 1; i < n_games; i++)

{

if(games[i].minutes > ret_game.minutes) {

ret_game = games[i];

}

}

return ret_game;

}

struct Game getHigherScoreGame(struct Game games[1000], int n_games)

{

// get game with the higher score

Game ret_game = games[0];

for(int i = 1; i < n_games; i++)

{

if(games[i].points > ret_game.points) {

ret_game = games[i];

}

}

return ret_game;

}