Question: I need to make a program using C. I will really appereciate your help.:( I put the inputs, outputs and template at the bottom. Complete

I need to make a program using C. I will really appereciate your help.:(

I put the inputs, outputs and template at the bottom.

Complete the following homework assignment using the description given in each section.

Purpose:

Use command line arguments to gather file names

Use formatted output to print out multiple arrays

Learn to use insertion or selection sort

Submission information:

Submit this assignment through the tc.rnet submission system by the deadline NO LATER! It must be submitted before the due date. Not doing so WILL result in a zero, no exceptions. If you are even one minute late in your submission, the system will close and your TA will not make an exception for you.

Description:

For this homework, you will be required to implement and use a number of functions relating to file IO, array allocation/manipulation, and output formatting. You must read in a list of hockey players and information about them. You will display this information, sort it, and display it again; you will then display other information, as outlined in the sample output below. A template file has been provided to you which explains all the functions that must be implemented in detail, along with a sample input file.

Keep the following things in mind as you work:

You must check for the proper number of command line arguments, as well as success when opening files. You should display an error message if any of these checks fail.

You are responsible for closing any files that you open. Failure to do so will result in a loss of points.

You are responsible for writing your own function that uses free() to free any memory that you dynamically allocated within the program. To check that all memory is freed, run your program inside valgrind using the following command:

valgrind ./a.out input.txt output.txt

You will be using strings extensively in the lab. Familiarize yourself with strcmp, strtok, and strcpy - you will need all 3 functions. If you try to compare two strings through the "==" operator, your code will not work and you will not receive points for that function.

Sample outputs

$ ./a.out input.txt output.txt

Read the following 9 players from the file.

Name Goals Assists

Redden 2 0

Berglund 5 2

Stewart 4 0

Oshie 3 5

McDonald 2 4

Pietrangelo 2 7

Perron 2 6

Tarasenko 5 5

Sorted player list.

Name Goals Assists

Berglund 5 2

Tarasenko 5 5

Stewart 4 0

Oshie 3 5

Redden 2 0

McDonald 2 4

Pietrangelo 2 7

Perron 2 6

MVP was Tarasenko with 10 points

Enter a player to find: Perron

Perron has 2 goals and 6 assists

------ BONUS ------

Name Goals Assists

Tarasenko 5 5

Berglund 5 2

Stewart 4 0

Oshie 3 5

Pietrangelo 2 7

Perron 2 6

McDonald 2 4

Redden 2 0

Guidelines for grading HW 1 - 50 points possible

If your program does not compile, does not link, or fails to produce any output, your homework will receive a grade of ZERO. If your program segfaults or infinitely loops you will receive a 50% deduction. For EACH block of memory that is not freed, you will receive a 20% deduction. ALWAYS COMPILE IMMEDIATELY BEFORE SUBMITTING YOUR CODE. If your submission fails for any reason and you do not notify your TA in advance, before the due date, you will receive a grade of ZERO.

If your program uses global variables including global arrays/pointers, you will receive a grade of ZERO.

To receive partial credit, your program must correctly provide output that includes some results from your program.

10 points sortPlayersByGoals function

10 points findPlayerByName function

5 points readLinesFromFile and writeToFile function

5 points findMVP function

5 points allocateMemory function

5 points freeing memory (write your own function)

5 points main function

3 points countLinesInFile function

2 points - printPlayers function

(Bonus) 5 points - sortPlayersByBoth function

In addition to these requirements, you can lose up to 10 points on the homework if your code is poorly formatted, poorly commented, or does not adhere to good code style. You should follow basic good practice: indent code within curly braces, give your variables meaningful names, and comment every block of code that is logically distinct from the block before it.

///////////////////////////////////////////////////////////////////

Inputs:

Fabbri 2 0 Berglund 5 2 Jaskin 2 0 Schwartz 4 0 Perron 3 5 Lehtera 2 4 Steen 2 7 Sobotka 2 6 Tarasenko 5 5

Outputs:

{ tf1\ansi\ansicpg1252\cocoartf1348\cocoasubrtf170 {\fonttbl\f0\fmodern\fcharset0 Courier;} {\colortbl; ed255\green255\blue255;} \margl1440\margr1440\vieww10800\viewh8400\viewkind0 \deftab720 \pard\pardeftab720 \f0\fs26 \cf0 \expnd0\expndtw0\kerning0 Tarasenko 5 5\ Berglund 5 2\ Fabbri 2 0\ Schwartz 4 0\ Perron 3 5\ Steen 2 7\ Sobotka 2 6\ Lehtera 2 4\ Jaskin 2 0\ } 

/////////////////////////////////////

Template:

#include #include #include

#define MAX_LINE 100 #define MAX_NAME 30

int countLinesInFile(FILE* fPtr); int findPlayerByName(char** names, char* target, int size); int findMVP(int* goals, int* assists, int size); void printPlayers(int* goals, int* assists, char** names, int size); void allocateMemory(int** goals, int** assists, char*** names, int size); void sortPlayersByGoals(int* goals, int* assists, char** names, int size); void writeToFile(FILE* fPtr, int* goals, int* assists, char** names, int size); void readLinesFromFile(FILE* fPtr, int* goals, int* assists, char** names, int numLines);

// Bonus function void bonusSortPlayersByBoth(int* goals, int* assists, char** names, int size);

// Main function receives two command line arguments. The first is the name // of the input file; the second is the name of the output file. If either one // is missing, or the input file cannot be opened, the program should print an // error message and end. // // You are responsible for making the output of your program match the sample // output. That means you must determine the appropriate algorithm on your own; // TAs will not provide a step-by-step list of functions to call, or how to // achieve the proper output. It is recommended that you implement main after // implementing some of the other functions; this may help you to see the purpose // of main more clearly. int main(int argc, char** argv) { }

// Counts how many lines are in the file provided. After counting, // this function should rewind the file for future use. // // INPUT: fPtr - A pointer to a file opened in read mode. // RETURNS: The number of lines in the file. int countLinesInFile(FILE* fPtr) {

}

// Finds a player by their name. // // INPUT: names - A pointer to the strings containing the player names. // target - The name of the player to find. // size - The number of players to search through. // RETURNS: The index of the player if found; -1 otherwise. int findPlayerByName(char** names, char* target, int size) {

}

// Finds the most valuable player (MVP) of the players. (The MVP has the greatest goals + assists total.) // // INPUT: goals - An array containing the number of goals scored per player. // assists - An array containing the number of assists per player. // size - The number of players in each array. // RETURNS: The index of the MVP. You may assume that size > 0 and therefore, there will always be // an MVP. In the event of a tie, you may return any of the players in the tie. int findMVP(int* goals, int* assists, int size) {

}

// Prints the players names along with their goals and assists. // YOU MUST USE FORMATTED OUTPUT IN THIS FUNCTION. Failing to do so // will result in a loss of half of the points for this function. // Players should be printed out as follows: // // Name Goals Assists // Backes 4 2 // Pietrangelo 3 1 // // You must include the column headers in your output. THIS FUNCTION, // AND MAIN, SHOULD BE THE ONLY OUTPUT-PRODUCING FUNCTIONS IN YOUR PROGRAM. // If other functions produce output, you will lose half of the points for // those functions. It is very important not to produce errant output! // // INPUT: goals - An array containing the number of goals per player. // assists - An array containing the number of assists per player. // names - An array containing the names of each player. // size - The number of players in each array. void printPlayers(int* goals, int* assists, char** names, int size) {

}

// Allocates memory for the player names, their goals, and their assists. // HINT: Allocating the memory for the goals and assists is straightforward; // allocating memory for the names is going to be very similar to lab 2, with // an extra dereference to account for the fact that we are using a char***. // // INPUT: goals - A pointer to a variable which should contain the malloced memory for goals. // assists - A pointer to a variable which should contain the malloced memory for assists. // names - A pointer to a variable which should contain the malloced memory for names. // size - The number of players to malloc memory for. void allocateMemory(int** goals, int** assists, char*** names, int size) {

}

// Sorts the players according to the number of goals they've scored, in descending order. // You must use insertion sort or selection sort for this function. // USE OF ANY OTHER SORTING FUNCTION WILL RESULT IN NO POINTS FOR THIS FUNCTION. // Keep in mind that moving an entry in one array will require you to // move entries in the other two arrays, to keep player information synchronized. // (There are a few ways to accomplish this with names, some easier than others.) // // INPUT: goals - An array containing the number of goals per player. // assists - An array containing the number of assists per player. // names - An array containing the names of each player. // size - The number of players in each array. void sortPlayersByGoals(int* goals, int* assists, char** names, int size) {

}

// Writes the player information to the given file, in the same order as the input file. // You should not call this function until after you have sorted the player information, // so that the information appears in sorted order in the output file. // // INPUT: fPtr - A pointer to a file to write to. // goals - An array containing the number of goals per player. // assists - An array containing the number of assists per player. // names - An array containing the names of each player. // size - The number of players in each array. void writeToFile(FILE* fPtr, int* goals, int* assists, char** names, int size) {

}

// Reads the player information from the given file. Information is in the following format: // // [name] [goals] [assists] // Backes 1 5 // Pietrangelo 2 7 // // YOU MAY NOT USE FSCANF IN THIS FUNCTION! Doing so will result in no points. Instead you // must use fgets in combination with the strtok function in order to break the line into // pieces. You can read about strtok online or in your textbook; email your TA with any // questions. // // INPUT: fPtr - A pointer to a file to read from. // goals - An array to be filled with the number of goals per player. // assists - An array to be filled with the number of assists per player. // names - An array to be filled with the names of each player. // size - The number of players in each array. void readLinesFromFile(FILE* fPtr, int* goals, int* assists, char** names, int numLines) {

}

// BONUS FUNCTION - worth 5 extra points. You may only receive points for the bonus // if you have implemented all other functions with no major flaws. This is up to the // discretion of your TA. // // This function sorts the players according to two fields - goals and assists. // Players should be sorted according to their goals scored first, then they will // be sorted by the number of assists they have scored as a second criteria. Example: // // Tarasenko 5 5 // Berglund 5 2 // Pietrangelo 2 7 // Perron 2 6 // McDonald 2 4 // Redden 2 0 // Backes 1 5 // // Note that within each grouping of players with the same number of goals, // they are subsequently sorted by the number of assists. If two players have // the same number in each category, you may place them in any order. // // Unlike the other sort function, you may use any type of sort algorithm to // implement this function. Note that this does not excuse you from implementing // the other sort function with the proper algorithm. It will probably be easiest // to simply call the other sort function from within this one, and then perform // the sub-sort afterwards. void bonusSortPlayersByBoth(int* goals, int* assists, char** names, int size) {

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!