Problem 169

Getting Data from a File

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

Using Notepad or the text editor of your choice, create a text file containing the data above for two dogs. Save this file in same directory as this program.

  1. Create two Dog objects (not in an array).
  2. Ask the user for the name of a file to open, and open that file and read in attributes.
  3. Display the values you read in.
Which file to open: dogs.txt
Reading data from dogs.txt

First dog: Yorkie, 4, 14
Second dog: Great_Dane, 7, 93

For reference

Here is a repl.it for how to read in information from a file.


◄ 168: A Little Database is Shorter with a Loop 170: Getting More Data from 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.