CS 1160 C/C++ Programming 12 MWF - Spring 2016

February 8th, 10th, and 12th - Week #4


Monday


  1. Assignment: rands.txt was the input file used by the above program. YOU CAN USE THIS FILE FOR YOUR ASSIGNMENT!

  2. Assignment #3: Exercise #24 Using Files---Numeric Processing - Page 299 of textbook.

  3. HOMEWORK SUBMISSION IS READY for programming assignment #3.
    Login with your UNI CatID and passphrase.
    Choose CS 1160, C++, Jacobson and then click the Continue button.


    HOMEWORK SUBMIT system: C++ Homework SUBMISSION for C++ Assignments for Jacobson
      files.cpp
    

  4. Reading an input file: fstream and ifstream and file handles. Finding the largest and smallest value in a file of integers. Possible values range from 0 to 999 (from Excel).
    #include <iostream>
    #include <fstream>
    using namespace std;
    
    int main()
    {
       int low, high, n;
    
       ifstream numbersFile;
    
       numbersFile.open("rands.txt");
    
       low = 9999;
       high = -123;
                                      // Wednesday Feb 10th          // Wednesday 01/10/2016
       while ( numbersFile >> n )     //   Subtle error              //   More obvious error
       {                              // WHY IS THIS WRONG?          // WHY EVEN MORE WRONG!!!
          if (n < low)                   if (n < low)                    if (n < low)
             low = n;                       low = n;                        low = n;
                                         else if (n > high)              else
          if (n > high)                     high = n;                       high = n;
          {
             high = n;
          }
       }
    
       cout << "\nThe largest value was " << high 
            << "\n    and the smallest value was " << low
            << endl;
    
       numbersFile.close();
    
       return 1;
    }   
    

Wednesday 2/10/2016


Study the example with FUNCTIONS - void return type. Menu example. Senior or Adult or Child or Quit menu choices.

See your Monday handout. Study the textbook and examples. VIP. Very challenging and VIP.

If you are working on the assignment, you can create your own data file of numbers, such as data.txt using the nano editor. Test and run your program with that input file ( ifstream ).
I will show you how to get rands.txt to your weblab.uni.edu account. There are 3 ways to do this, so I will show all 3 ways.


Friday 2/12/2016


  1. Using functions: happyValentines(), loveCpp(), and factorial() output and C++ code.

  2. 212.cpp C++ code example - study it carefully. Separation of declaration from definition of a function, iomanip, setw, long instead of int to handle larger integers.