Solved–Project 1 –Solution

$35.00 $24.00

For this project you will be provided with a file to read. This file will contain the names of 20 Quarterbacks. Next to each name will be 5 stats separated by spaces: Completions, Attempts, Yards, Touchdowns, Interceptions in that order. This file will be the input file for your program. All of the following functions…

You’ll get a: . zip file solution

 

 
Categorys:
Tags:

Description

5/5 – (2 votes)

For this project you will be provided with a file to read. This file will contain the names of 20 Quarterbacks. Next to each name will be 5 stats separated by spaces: Completions, Attempts, Yards, Touchdowns, Interceptions in that order. This file will be the input file for your program. All of the following functions should be put into one file.

Part 1 : 20 points

Write a function take a file name as a parameter. This function will open the given file for reading and then read each line of the input file and put each line into a list. If the user passes the name of a file that doesn’t exist you should catch the exception that is thrown by the open() function and return an empty list. If a valid file name is passed this function will return the list that is created.

Part 2 : 20 points

Write a function that will take a list as a parameter. This list will be the list from the previous function. This function will take each element of that list and calculate the Quarterback rating for each QB in the list. You will want to use the float() function instead of the int() function to convert strings to numbers. For each line you will create a tuple where the first element of the tuple is the Quarterback’s name and the second element is the quarterback’s Passer rating. You will then place that tuple into a list. This function will return that list. The formula for Passer Rating is as follows:

Part 3 : 20 Points

Write a function that will accept a list as a parameter. This list will be the list from the previous function. This function will use the selection sort algorithm that we used earlier in the semester to sort the list according to each quarterback’s QB rating. This list will be sorted so that the highest QB rating is at the top instead of the lowest QB rating. Remember, you are sorting the tuples, not JUST the qb ratings. You should end up with a list of tuples that is sorted by QB rating and each tuple will have the name and rating for a quarterback. Remember, since lists are pass by reference you will not need to return the list from this function. Do NOT use built in sorting functions

Part 4 : 20 points

Write a function that will take the name of a file and a list. This list will be the sorted list from the list from the previous function. This function will open a file for writing with the name of the file that was passed. It will then write the contents of each tuple to that file. Each line should first write the QB rating followed by the name of the quarterback who had that rating. This is should be the reverse of the order that these elements are stored in each tuple. Do not print the parentheses of the tuple to the file.

Part 5 : 20 points

Write a main function that will display a menu with 6 options: Select input file, Calculate ratings, Sort ratings, Output ratings to a file, Output ratings to console, and exit.

If select input file is chosen you should prompt the user for a file name, call the function from part 1 and store the returned value in a variable.

If calculate ratings is selected and QB statistics have already been read you should call the function from part 2 with the list returned from part 1 and store the returned value in a variable. If calculate ratings is selected and QB statistics have not been read you should tell the user that no statistics have been read.

If sort ratings is selected and QB ratings have been calculated you should call the function from part 3 with the list returned from part 2. If sort ratings is selected and QB ratings have not been calculated then you should tell the user that no ratings have been calculated.

If output ratings to file is selected and the ratings list has been calculated and sorted you should prompt the user for a file name and call the function from part 4 with the file name they input and the sorted list as arguments. If output ratings to file is selected and the ratings list has not been calculated or sorted you should inform the user that the list either has not been calculated or has not been sorted.

Selecting Output ratings to console will operate similarly to Output ratings to file except you will not have to prompt the user for a file name and you will print to the console instead of a file. You may write a function for this if you would like but you do not have to.

After each selection that the user makes your program should execute the appropriate actions, reprint the menu and prompt the user for another selection until they select exit.

If the user enters a selection that is not a valid menu selection you should ask the user to make another selection and redisplay the menu.