Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Activity 3: File Input & Data Processing Reading data from a file is often done in order to process and aggregate it to get additional

Activity 3: File Input & Data Processing

Reading data from a file is often done in order to process and aggregate it to get additional results. In

this activity you will read in data from a file containing win/loss data from the 2011 Major League

Baseball season. Specifically, the file mlb_nl_2011.txt contains data about each National League

team. Each line contains a team name followed by the number of wins and number of losses during the

2011 season. You will open this file and process the information to output a list of teams followed by

their win percentage (number of wins divided by the total number of games) from highest to lowest.

Instructions

Download the mlb_nl_2011.txt data file and the mlb.c C source files. Much of the program has

already been provided for you, including a convenience function to sort the lists of teams and their win

percentages as well as a function to output them.

1. Add code to open the data file and read in the team names, wins and losses and populate the

teams[] and winPercentages[] arrays with the appropriate data

2. Call the sort and output functions to sort and display your results

3. Answer the questions on your worksheet and demonstrate your working program to a lab

instructor

mlb_nl_2011.txt file

Braves 89 73 Phillies 102 60 Nationals 80 81 Mets 77 85 Marlins 72 90 Brewers 96 66 Cardinals 90 72 Reds 79 83 Pirates 72 90 Cubs 71 91 Astros 56 106 DBacks 94 68 Giants 86 76 Dodgers 82 79 Rockies 73 89 Padres 71 91

mlb.c file

#include #include #include

void sortMLB(char teams[][20], double winPerc[], int numTeams); void printMLB(char teams[][20], double winPerc[], int numTeams);

int main(void) { int const size = 200; int const numTeams = 16; char fileName[] = "mlb_nl_2011.txt"; char tempBuffer[size]; char tmp[size];

char teams[numTeams][20]; double winPercentages[numTeams];

//TODO: open the file, read it line by line, tokenize it to get the // team name, wins, and losses, and store the results into // teams[] and winPercentages[]

//sort them sortMLB(teams, winPercentages, numTeams); //print them out printMLB(teams, winPercentages, numTeams);

return 0; }

/** * A sorting function to sort the teams and their win percentages * using the selection sort algorithm which successively finds the * "maximum" element and places it at the front of the array */ void sortMLB(char teams[][20], double winPerc[], int numTeams) {

int i, j, max_index; char tmp_str[100]; double tmp_dbl; //for each element i for(i=0; i

}

void printMLB(char teams[][20], double winPerc[], int numTeams) {

int i=0; printf("%-12s %-10s ", "TEAM", "WIN PERC"); for(i=0; i

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

Project Management in Practice

Authors: Samuel J. Mantel Jr., Jack R. Meredith, Sco

4th edition

470533013, 978-0470533017

Students also viewed these Databases questions

Question

find all matrices A (a) A = 13 (b) A + A = 213

Answered: 1 week ago