Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)

 efh0888 11Nov2007 10:19

Objectives
1. Review use of logical constructs and functions.
2. Use arrays to solve a problem with many pieces of information of the same type.
3. Use both input and output files.

Problem: Fantasy Football

Input File Format
The first line of the input file will contain a single integer n (5 ? n ? 1000), denoting the number of players, for which statistics are listed in the file. You are guaranteed enough players in the file to fill an All-Star team as specified above. The following n lines will have all the statistics for all the players with one player's statistics on a single line. Each line will have the following format:

Name Position PassYrds RushYrds RecYrds TDs

Name will be the player's name and contain no white space characters. It is guaranteed to be 29 characters or less.

Position will be a single character, either 'Q', 'R' or 'W', for quarterback, running back or wide receiver, respectively.

PassYrds will be an integer representing the number of passing yards the player had last season.

RushYrds will be an integer representing the number of rushing yards the player had last season.

RecYrds will be an integer representing the number of receiving yards the player had last season.
TDs will be an integer representing the number of touchdowns the player had last season.

How to Compute a Power Ranking
For each player, their power ranking will be the sum of their passing yards divided by 30, their rushing and receiving yards divided by 10, and 6 times the number of touchdowns. In this computation, use integer division. Thus, if a player had 3150 passing yards, 59 rushing yards and 63 receiving yards and twenty touchdowns, his power ranking would be

3150/30 = 105
(59 + 63)/10 = 12
20*6 = 120
----
237

Note that power rankings are always non-negative integers.

Output File Format
The output file you produce should have the following format:

The first line should contain a single integer n, representing the number of players in the file. The following n lines should have information about one player each and be in the following format:

Name Position PowerRanking

Each piece of information on a single line should be separated by a single space.

Your program should first prompt the user for the name of both the input file and the output file. Then, your program should process the input file and write out the sorted list (by descending power ranking) to the output file. If there are any ties, you must break these by name as compared by the string function strcmp. Finally, your program should output five lines listing the five players for your All-Star team to the screen. Each line should list the position, the name, and power ranking of the player, respectively, separated by spaces. The players must be listed as follows: quarterback, followed by the two running backs, followed by the two wide receivers. Both the running backs and wide receivers must be listed in descending order of power ranking.

Sample Input File (players.in)
10
Manning,Peyton Q 4397 36 0 35
Walker,Javon W 0 123 1084 9
Owens,Terrell W 0 0 1180 13
Jackson,Steven R 0 1528 806 16
Parker,Willie R 0 1494 222 16
Harrison,Marvin W 0 0 1366 12
Tomlinson,Ladainian R 0 1815 508 31
Wayne,Reggie W 0 0 1310 9
Johnson,Larry R 0 1789 410 19
Brees,Drew Q 4424 32 0 26

Sample Output File(players.out)
10
Manning,Peyton Q 359
Johnson,Larry R 333
Jackson,Steven R 329
Brees,Drew Q 306
Parker,Willie R 267
Harrison,Marvin W 208
Owens,Terrell W 196
Wayne,Reggie W 185
Walker,Javon W 174

Output Sample
Here's an example of how your program should run. User input is in bold and italics.

Please enter the input file with player data.
players.in
Please enter the name of the file you want to store the sorted player data.
players.out

Your output file has successfully been stored.

Q Manning,Peyton 359
R Johnson,Larry 333
W Harrison,Marvin 208
W Owens,Terrell 196

Deliverables
You must submit the following .c source file with the following name:

1) fantasy.c

Please submit this file over WebCT.

Restrictions
Although you may use other compilers, your program must compile and run using cygwin or gcc. Please use DevC++ to develop your program. Your program should include a header comment with the following information: your name, course number, section number, assignment title, and date. Also, make sure you include ample comments throughout your code describing the major steps in solving the problem.