Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How would I create this program using only the C language? Also how could I create this program without a global variable? I've included directions

How would I create this program using only the C language?

Also how could I create this program without a global variable? I've included directions to the program and sample output. Thank you

Directions:

Write this program Please use only the C language

No global variable are to be used in this.

you will be using the following: 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.

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;

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

// 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 calculate_slugging(Player* players, 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

// size the size of the array of structures

void sort_array(Player* players, int size);

//This function takes in an array of players and will sort this array based on Slugging

// Percentage. The formula for calculating slugging percentage can be found toward the

// bottom of the document.

// Parameters

//

// players a pointer to the array of Player structures

// size the size of the array

// Return - Nothing

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

// This function will take in a structure of players and print them into the

// given output file, filename

// Parameters

//

// filename the name of the output file

// players a pointer to the array of struct players to write to the file

// size the size of the players array

// Return - Nothing

How to calculate Slugging Percentage

To calculate slugging percentage, take the number of Total Bases (singles, doubles, triples and homers) and divide by At Bats. To add up Total Bases, each single counts for one, each double is two, etc.

For instance, in 1927, Babe Ruth had 192 hits. He had 29 doubles, 8 triples and 60 home runs, adding up to 97 extra-base hits; subtracting that from 192 leaves 95 singles. So you'd add 95 + (29 2) + (8 3) + (60 4) = 417 Total Bases. Divide that by the number of his At Bats that year, which was 540 and you get a slugging percentage of .772.

Additional Notes

To find out the number of hits a person has you simply need to add the number of singles, doubles, triples and homeruns.

Use val command to check for memory leaks

Programs that do not compile will not be accepted for submission

Programs with Segmentation faults will result in a minimum 50% deduction

Programs with memory leaks will result in a minimum of 10% deduction

INPUT FILES:

input1.txt

Andrew Jackson 129 33 38 30 506

Jeremy Warden 25 24 3 9 493

Jared Welch 130 1 43 27 422

Brandon Splitter 138 38 40 7 587

Joe Gwilliams 150 23 30 25 498

Ali Mohammed 119 43 13 6 598

Dheeraj Johnson 124 79 59 36 506

Bill Clinton 121 65 12 26 449

Jesse James 87 58 8 5 464

John Doe 129 100 0 12 548

input2.txt:

Gus Bus 54 0 70 12 455

Clint Eastwood 61 18 60 1 401

Harambe Thegreat 65 29 10 27 496

Sammy Sosa 34 4 18 6 427

Lauren Lohan 98 69 20 5 454

Operah Winfrey 49 2 22 68 441

Jimbob Bobjim 92 54 0 1 495

Steven Hawking 140 29 63 8 407

Olaf Count 184 56 39 42 541

Benjamin Franklin 74 68 40 25 403

input3.txt:

Wally Waldo 172 4 83 23 546

Nicholi Vladimir 66 36 16 16 481

Farris Bueller 102 41 37 42 544

Jason Witten 115 70 4 42 546

Whitney Houston 32 4 9 7 523

Bethony Gerrero 88 27 18 27 411

Melanie Heinz 102 62 1 23 563

Minnie Mouse 131 77 0 25 505

Micky Mouse 139 20 13 61 576

Theresa Waters 68 45 11 3 589

SAMPLE OUTPUT:

image text in transcribedimage text in transcribed

image text in transcribedimage text in transcribed

PLEASE NOTE NONE OF THE OUTPUT MATTERS OTHER THAN OUTPUT.TXT!!! I AM JUST DEMONSTRATING THE ORDER THIS PROGRAM CAN BE TESTED IN AND VISUALIZING IT FOR YOU ALL!!!

image text in transcribed

[jdwdm3@tc-login HW11s ./a.out INCORRECT USE OF PROGRAM Correct usage: ./a.out output> [jdwdm3@tc-login HW1ls

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

Database Concepts

Authors: David M Kroenke, David J Auer

6th Edition

0132742926, 978-0132742924

More Books

Students also viewed these Databases questions

Question

1. What are the peculiarities of viruses ?

Answered: 1 week ago

Question

Describe the menstrual cycle in a woman.

Answered: 1 week ago

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago