Lab 7 - May 9

  1. Reading from a file

    Download this example file to your account: lab7_input.txt. When you are logged into Helios, you should be able to do the following command to copy the file to your current directory:

    cp /usr/users/mdanfor/public_html/cs221/lab7_input.txt .
    Write a program to read in the data from this file and print it to the screen. Note that the file has an integer followed by a double. Your input statement should look something like this:
    int num;
    double dnum;
    
    fin >> num >> dnum;
    
  2. Comparing cout with printf

    Look at this small example of formatting output using printf: lab5_example.cpp. This is the output it produces:

    integer output
    right justify: |         5|
     left justify: |5         |
    
    double output (2 precision)
    right justify: |      5.50|
     left justify: |5.50      |
    
    A small table without borders:
    Name      Integer   Double
    Alice              5      6.20
    Bob                8     13.34
    Carol             12     19.00
    
    Write a program to do the same output using cout.
Email your files to my Helios account.