Programs – Ch6b – Retrieving data from files

 

Sports Team Record Program

 

In this program, the program will open a data file and pull a team name and record (wins and losses).  These items will display on the screen and the program will ask the user to update the team’s record.  The user will choose whether the team has won or lost.  After their choice, the program should show the new record and update the data file.

 

Adventure Game Data Program

 

In this program, a data file will store a character’s name, gold, and experience.  (Gold and experience are common themes in adventure games). 

 

The program should open the data file at the start of the program and retrieve the data from the file to store in local variables. 

 

After the data is stored, it should display on the screen so the user knows the values.

 

Next, the user should be given four choices (in a loop):

  1. Change Name
  2. Add Experience
  3. Adjust Gold
  4. Quit

 

If the user chooses to change name, a subroutine runs that allows the user to enter a new name for the character.

 

If the user chooses to add experience, a different subroutine runs.  This subroutine shows the current level of experience points and asks the user how many points to add.  The appropriate adjustment to overall experience is made.

 

If the user chooses to adjust gold, a subroutine runs that asks the user if they wish to add to gold or subtract from gold.  The user chooses and then enters the amount to add or subtract.  The appropriate adjustment to overall gold is made.

 

Finally, the user may choose to quit.  When the user chooses to quit, the data file is opened and updated before the program ends.  The next time the program runs, any changes should be visible.