Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CS 2050 Homework Assignment 1 Baseball Statistics Summer 2018 Due : 20 th June, Wednesday 5:00 PM (No Extension) Introduction No global variables are to

CS 2050 Homework Assignment 1

Baseball Statistics

Summer 2018

Due: 20th June, Wednesday 5:00 PM (No Extension)

Introduction

No global variables are to be used in this homework. Please read this document in its entirety before beginning the homework. This homework is due Wednesday, June 20th by 5PM. In this homework you will be using the following concepts: file input/output, pointer, structures and malloc. You will be given 3 input files all containing instances of players structures. You will scan the information from all 3 of the input files into the SAME array. After all of the players have been scanned in from each file, you will use the calculate_slugging function to figure out each players slugging percentage and store that in the Slugging_Percentage variable in the structure. Note that you may have to typecast the variable as a double when doing the calculations. (See link at bottom of document). When the Slugging Percentages have been calculated, you will use the sort_array function(bubble sort) to sort the players in DESCENDING order by their slugging percentage. After they have been sorted, you will output the array to the output file specified on the command line argv[5]. Note that the array SHOULD BE sorted when it is output to the file. The input files for this lab can be found on blackboard in a zip folder under the assignments tab

Command Line Arguments

argv[0] - ./a.out (executable file)

argv[1] the number of players in ALL the input files combined

argv[2] input file 1

argv[3] input file 2

argv[4] input file 3

argv[5] output file

Note that each input file have the same amount of players in them, so if you are trying to figure out how many to scan in from each file try argv[1]/3.

Functions

typedef struct player {

char Fname[25];

char Lname[25];

int Singles;

int Doubles;

int Triples;

int Homeruns;

int At_Bats;

float Slugging_Percentage;

} Player;

// This function will read in size struct players from filename and add these // the players array. The function will use index to know where to start // writing the players to in the array.

// Parameters

//

// filename The name of the input file

// players a pointer to the array of player structures

// index The index of the array to start placing players into

// size The number of players in the input file

// Return - Nothing

void read_from_file(char* filename, Player* players, int index, int size);

// This function will take in an array of players and calculate their slugging // percentage using the other variables in the structure(Singles, Doubles, // Triples, Homeruns).

// Parameters

//

// players a pointer to the array of Players structures

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Databases With PostgreSQL From Novice To Professional

Authors: Richard Stones, Neil Matthew

2nd Edition

1590594789, 978-1590594780

More Books

Students also viewed these Databases questions