Week #3 - C/C++ CS 1160 - Jan 25, 27, 29

  1. HOMEWORK SUBMISSION IS READY for programming assignment #1.
    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

  2. ASSIGNMENT handout: Programming Assignment #1 - Magic Dates, Area of Rectangles, and Body Mass Index.
    Three programs from chapter four of the textbook.

    1. The three C++ programs are turned in by using a user friendly web browser based submit system.
    2. You got practice with how to do that in a hands-on class on Wednesday. It will be demonstrated in class on Friday too.
    3. The programs will be due and can be submitted anytime before 10 pm on Saturday, January 30th.
    4. Each of your programs will have a comment block that indicates who wrote the program (your name) and what the name of the program file is.

      The program file names will be:

      dates.cpp             All lower case letters for the file name
      
      rectangles.cpp        All lower case letters for file name
      
      BMI.cpp               BMI is an acronym, so all UPPER CASE letters B M I
      
      questions.txt         This is optional, if you want to submit here instead
                                of handing the answers in on Friday during class.
      
  3. 01/27/Wednesday - The HOMEWORK SUBMIT system: C++ Assignments for Jacobson
    Login with your UNI CatID and passphrase.
    Choose CS 1160, C++, Jacobson and then click the Continue button.
    The files you will upload will be named:
    
         forLoop.cpp
         questions.cpp               CaSe SenSiTiVe - 52 letters a != A, etc.
    

  4. Where do I get the secure shell client so as to connect to weblab.uni.edu from home or from my laptop commputer?

    its/free-software-players-and-viewers and download and then install SSH Secure Shell.

    Telnet
        PuTTY              <------ Not user friendly at all
        SSH Secure Shell   <------ Download and install this one 
    
                                   SSH Secure Shell is the one used in class.
    
  5. Chapter 5 first example: WHILE loop to obtain the sum of the first n positive integers.
    [jacobson@weblab ~]$   g++ loop1.cpp     COMPILE loop1.cpp
    [jacobson@weblab ~]$   ./a.out           RUN (EXECUTE) the program a.out
    
    Please enter a positive integer: 5
    
    The sum 1, 2, ..., 5 is 15
    
    -------------------------------   --------
    Textbook Programming Challenges - page 294 of book and see Monday 01/25 handout.
    -------------------------------   --------
      1. Sum of Numbers 
                                 See page 233 of textbook
    
                                 See page 239 of textbook
         Write a program that asks for a positive integer value.
         Use a loop to get the sum of all the integers 
                                from 1 up to the number entered.
         For example, if the user enters 5, the program will find
                                the sum of the 1, 2, 3, 4 and 5.
    
         Actors needed in this drama:
    
       I      Input:  n    will be the positive integer value, such as 5 or 50.
       O     Output:  sum  will be the answer obtained that is to be output.
        
       P Processing:  i    will be the variable that starts out at 1 and 
                                is incremented each time so it ranges
                                through the numbers 1, 2, 3, ..., n-1, n
                                and at each value is added to the sum.
    
       I P O
    
  6. Here is the C++ program sample runs. More on Wednesday.
    [jacobson@weblab ~]$ g++ loop1.cpp
    [jacobson@weblab ~]$ ./a.out
    Please enter a positive integer: 5
    
    The sum 1, 2, ..., 5 is 15
    
    [jacobson@weblab ~]$ ./a.out
    Please enter a positive integer: 10
    
    The sum 1, 2, ..., 10 is 55
    
    [jacobson@weblab ~]$ ./a.out
    Please enter a positive integer: 100
    
    The sum 1, 2, ..., 100 is 5050
    
    [jacobson@weblab ~]$ ./a.out
    Please enter a positive integer: 4
    
    The sum 1, 2, ..., 4 is 10
    
    
    
  7. Here is the C++ program code.
    // Page 294 - Programming Challenges problem #1.
    #include <iostream>
    using namespace std;
    
    int main()
    {
       int i, n, sum;
    
       cout << "Please enter a positive integer: ";
       cin >> n;
    
       i = 1;
    
       sum = 0;
    
       while (i <= n)
       {
          sum = sum + i;
          i = i + 1;
       }
    
       cout << "\nThe sum 1, 2, ..., " << n 
            << " is " << sum 
            << endl << endl;
    }