Programming Exercise 12 |
< Previous Next > |
The Fork Spring Golf Club has a tournament every weekend. The club president has asked you to write a program that will read each player's name and score from standard input. The program should contain a main() function which prompts the user for an output filename and how many players they want to add. This program will then call the function scores(outFile, N) where outFile is the file object variable and N is the number of records to be written. The scores function should prompt the user for each name and score individually and write them to the file. Finally, the main() function is responsible for closing the file after the scores function.
Please enter the name of the output file: golf.txt Please enter the number of players: 3 Please enter the name for player 1: Marie Please enter the score for player 1: 21 Please enter the name for player 2: Joseph Please enter the score for player 2: 32 Please enter the name for player 3: Elizabeth Please enter the score for player 3: 43 Wrote 3 records to golf.txt
Please enter the name of the output file: golfB.txt Please enter the number of players: 6 Please enter the name of player 1: Joey Please enter the score for player 1: 91 Please enter the name of player 2: Sally Please enter the score for player 2: 92 Please enter the name of player 3: Billy Please enter the score for player 3: 86 Please enter the name of player 4: Emma Please enter the score for player 4: 98 Please enter the name of player 5: Mary Please enter the score for player 5: 76 Please enter the name of player 6: Noah Please enter the score for player 6: 85 Wrote 6 records to golfB.txt
handin pe12 pe12.pyTo verify your submission, type the following in a terminal window:
handin pe12