CS12

Lab 1

In this lab you will be working with reading input from data files. You should already be familiar with handling getting data from standard input(as with cin) and outputing to standard output (with cout). Reading from a file is not much different except for the initial work of getting the file open for reading. Your TA's will show you how to do this during lab if you don't already know how. It might be helpful to skim over the basic sections of Chapter 14 in the Deitel & Deitel book. You should become very familiar with reading input from files rather than from the user as this will probably be the method of input for most of future assignments. You should also take this opportunity to make sure you know how to do nicely formatted output if for some reason you don't know yet.


Lab Assignment (to be completed by the end of your lab)

Write a program that reads in names, GPAs, and student ids from a file and outputs them to the screen nicely. Ask the user for the name of the file to read from and then use this file as the source for all your input. If the file can not be opened be sure to give an appropriate error message.

Assume the file is in the following format (id# gpa fullName), for example:

       1234  2.7 John Doe
       2534  3.7 Jane Doe
       4924  1.7 Bill Smith

       4234  4.5 Smart Freak

Remember that the file may contain blank lines between sets of information and blank lines at the end of the file. You should simply creat this file yoursel to test your program (you can even be creative and come up with your own names). Use an editor such as notepad or kwrite to create and save your file. Make sure your file is saved in the same directory as your program. The output should be made to the screen and be nicely formatted:

    Name        GPA    ID
    
    John Doe    2.7    1234   
    Jane Doe    3.7    2534   
    Bill Smith  1.7    4924   
    Smart Freak 4.5    4234  

You do not have to save this stuff anywhere as you read it in. Just simply read one thing at a time and output one thing at a time. If you want to do it some fancier way that is fine, just make sure it meets the basic requirements: