Problem 170

Getting More Data from a File

Using Notepad or the text editor of your choice, create a text file containing five names and five ages. Save this file in the same directory as your program.

Make a class to store information about a person. It should contain fields for:

  1. Create an array of type Person with five slots. Call it people (since that makes sense).
  2. Ask the user for the name of a file to open, and open that file and read in five names and ages from the file.
  3. Display the contents of the array using a loop.
Which file to open: nameage.txt
Reading data from nameage.txt

Steve_Jobs is 50
James_Brown is 71
Britney_Spears is 23
Michael_Jackson is 46
Stanley_Kubrick is 76

◄ 169: Getting Data from a File 171: Storing Data in a File ►



Adapted from ProgrammingByDoing.com
©2013 Graham Mitchell

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States License.