Go to Post After the norovirus outbreak at VCU, we had our entire team sterilized. Oh, wait, that doesn't sound right... - dlavery [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 14-11-2005, 20:50
sglegend11 sglegend11 is offline
Registered User
no team
 
Join Date: Nov 2005
Location: FL
Posts: 2
sglegend11 is an unknown quantity at this point
C HELP PLEASE

I have to write a program using arrays and input and output files...it doesn't seem like it shoud be this hard but I can't seem to figure it out...any help would be greatly appreciated.

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

Problem: Fantasy Basketball
Last year you came in dead last in your fantasy basketball league. After taking Introduction to C Programming however, you've come up with an idea to take your league by storm. You have access to last year's statistics and have decided to use your C programming skills to comb through those stats to create an ordered list of players based upon how your fantasy league awards points. You will write a program that reads in an input file containing all the NBA's players with their statistics and then creates an output file listing the players and their "power rankings" in descending order of "power ranking." This output file will aid you in your draft. In addition to this task, for kicks, you will pick a league All-Star team using your program. Your program will pick five players: the center with the highest power ranking, the two forwards with the two highest power rankings, and the two guards with the two highest power rankings. This team of All-Stars should be outputted to the screen.

Input File Format
The first line of the input file will contain a single integer n (5 ≤ n ≤ 100), denoting the number of players, for which statistics are listed in the file. 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 Pts Rebounds Assists Steals Blocks

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 'C', 'F' or 'G', for center, forward or guard, respectively.

Pts will be an integer representing the number of points the player scored last season.

Rebounds will be an integer representing the number of rebounds the player had last season.

Assists will be an integer representing the number of assists the player had last season.

Steals will be an integer representing the number of steals the player had last season.

Blocks will be an integer representing the number of blocks the player had last season.


How to Compute a Power Ranking
For each player, their power ranking will be the sum of the points, two times the number of rebounds, 3 times the number of assists, 5 times the number steals and 5 times the number of blocks, all divided by 100. Thus, if a player had 1000 points, 600 rebounds, 200 assists, 50 blocks and 90 steals, then his power rating would be:

(1000 + 2*600 + 3*200 + 5*50 + 5*90)/100 = 35.00

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

The PowerRanking should be displayed to exactly two decimal places. Each piece of information on a single line should be separated by a single space.

What your program should do
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. Finally, your program should output five lines listing the five players for your All-Star team. 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: center, followed by the two forwards, followed by the two guards. Both the forwards and guards must be listed in descending order of power ranking.


Sample Input File (players.in)
10
Chris_Webber F 978 447 252 68 34
Allen_Iverson G 2302 299 597 180 9
Grant_Hill F 1317 318 220 97 28
Steve_Francis G 1663 450 547 112 28
Shaquille_O'Neal C 1669 760 200 36 171
Tim_Duncan C 1342 732 179 45 174
Steve_Nash G 1165 249 861 74 6
Dirk_Nowitzki C 2032 757 240 97 119
LeBron_James F 2175 588 577 177 52
Vince_Carter G 1886 401 327 109 48

Sample Output File(players.out)
10
LeBron_James F 62.27
Allen_Iverson G 56.36
Dirk_Nowitzki C 53.46
Steve_Francis G 49.04
Shaquille_O'Neal C 48.24
Steve_Nash G 46.46
Vince_Carter G 44.54
Tim_Duncan C 44.38
Grant_Hill F 32.38
Chris_Webber F 31.38


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.
Here is your All-Star team:
  #2   Spotlight this post!  
Unread 14-11-2005, 20:58
Unsung FIRST Hero
Greg Marra Greg Marra is offline
[automate(a) for a in tasks_to_do]
FRC #5507 (Robotic Eagles)
Team Role: Mentor
 
Join Date: Oct 2004
Rookie Year: 2005
Location: San Francisco, CA
Posts: 2,030
Greg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond repute
Re: C HELP PLEASE

What seems to be the specific nature of your problem?

What I would recommend doing is taking some paper and determining how your program is going to work. If YOU had to do this yourself, which order would you do all these steps in? Make a flowchart of how YOU (not the computer) would do the task, and then take this chart and use is as the framework for your code.

A flow chart is an excellent way to decide how your program will work.
  #3   Spotlight this post!  
Unread 14-11-2005, 21:01
sglegend11 sglegend11 is offline
Registered User
no team
 
Join Date: Nov 2005
Location: FL
Posts: 2
sglegend11 is an unknown quantity at this point
Re: C HELP PLEASE

One thing I really don't understand is how to take all the information in the input file and calculate the power ranking for each individual player and then store that information in the output file
  #4   Spotlight this post!  
Unread 14-11-2005, 21:03
Unsung FIRST Hero
Greg Marra Greg Marra is offline
[automate(a) for a in tasks_to_do]
FRC #5507 (Robotic Eagles)
Team Role: Mentor
 
Join Date: Oct 2004
Rookie Year: 2005
Location: San Francisco, CA
Posts: 2,030
Greg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond repute
Re: C HELP PLEASE

It seems then that what you need to do is look up how to import data from a text file in C. Perhaps some Googling is in order?

Once you have those variables loaded, the actual algebraic formula they are asking for should be very easy to perform. Then it's a matter of looking up how to write the data back out into a file.

And of course, do you want to do this one by one for each player, or do you want to load it all at once, calculate it all at once, and write it all back out at once?
  #5   Spotlight this post!  
Unread 14-11-2005, 21:35
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: C HELP PLEASE

If you just want the answer, rather than going through the exercise of writing a program to do it, any decent spreadsheet program is perfectly capable of computing the power ranking and sorting the result the way you want. It's a happy coincidence that you want the positions in alphabetical order.

If this is a programming problem for a class assignment, you should start by asking your instructor for advice instead of trying to get a bunch of robotics enthusiasts to do your homework for you.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 10:38.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi