Lab 2

  1. This involves using the lab from last class. Create a file, called input.data, that contains an a single name. Use this file for input instead of console input, and output the data from the program into a file called output.data. You should do all of this without changing the original program.

    Script this all using the instructions from the prior lab. Be sure to cat the input and output files, as well as the program itself.

  2. Modify the program from last lab (hint: use cp to make a copy of it) to read in a data file, and output the results to another file. The input file should have more than 3 names in it. This should work without using the unix redirection operators.

  3. Do Chapter 1 - Lab Exercise 3 from the lab manual. Here it is, after this, please buy the lab manual!
    //Chapter 1 of C++ How to Program
    // digits.cc
    //
    #include <iostream>
    
    using std::cout;
    using std::cin;
    using std::endl;
    
    int main()
    {
       int number;
       
       cout <<"Enter a five-digit number: ";
       cin >>number;
    
       // Write a statement to print the leftmost digit of the 5 digit number
       // Write a statement that changes number from 5 digits to 4 digits 
       // Write a statement to print the leftmost digit of the 4 digit number
       // Write a statement that changes number from 4 digits to 3 digits
       // Write a statement to print the left most digit of the 3 digit number
       // Write a statement that changes number from 3 digits to 2 digits
       // Write a statement to print the left most digit of the 2 digit number
       // Write a statement that changes number from 2 digit to 1 digit
    
       cout << number << endl;
    
       return 0;
    } //end main
    
    If you're really good, you will only need 2 statements and a while loop to do the above part.


Grading:
  1. 20% for Part 1
  2. 40% for Part 2 (should include good error checking, etc)
  3. 40% for Part 3