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

January 20th thru 22nd - Week #2

  1. Friday C++ example: Roman Numerals Textbook Problem from page 220.

    1. Illustrates an IF with an ELSE clause. This is done for error checking.

    2. Introduces the SWITCH statement.

    3. Converting Arabic numbers in range 1, 2, ..., 9 10 to Roman Numerals:

           Please enter a value between 1 and 10: 8
      
           The Arabic number 8 with Roman Numerals is: VIII
      
    4. I, II, III, IV, V, VI, VII, VIII, IX, X are ten of the eleven possible outputs the program will produce.

    5. The other output the program can produce is an error message, such as:
           Sorry.  The number has to be 1, 2, ..., 9 or 10!
      

  2. EVEN number 2,3,4,6,8 and 10 vs ODD numbers 1,3,5,7 and 9:
    evenOdd.cpp program to illustrate the if ... else if ... else and variation on the switch statement.

  3. ASSIGNMENT HANDED OUT: 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 will learn and get practice with how to do that in a hands-on class or classes during week #3 on Wednesday and it will be demonstrated Friday too.
    3. The programs will be due and can be submitted anytime before 9 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
      

  4. Wednesday 01/20 One page Handout - One Way and Two Way Selection and While loops.
    A few examples and explations from our textbook for if, if else and while.
    Sequencing    (s1; s2; s3; s4; ..., sn)
      
    Selection 
                One Way Selection                 Two Way Selection
                   if ( Boolean condition )          if ( Boolean condition )
                   {                                 {
                       s1;                              block of statements
                       s2;                                 often called the 
                       ...                                 then clause...
                       sn;                           }
                   }                                 else
                                                     {
                                                        block of statements
                                                           called the else clause
                                                     }
    Repetition
                 Not introduced yet:   
                                We will look at while, do while and for loops
                                                -----  --------     ---
    Subprograms
                 To be introduced during week #3
    

  5. Read and review carefully: C++/Introduction - Hello World! basic example explained.
    #include <iostream>
    using namespace std;
    
    int main()
    {
       cout << "Hello World!" << endl;
       cin.get();
       return 0;
    }
    
  6. C++/Variables and User Input basics. Declare, Assign, Types (floats versus doubles)...
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        char myChar;
    
        cout << "Enter a characer. ENTER: ";
        cin >> myChar;
        cout << "You entered: " << myChar << endl;
    
        return 0;
    }
    
  7. Simple C++ Math and using the C++ math library.

  8. Conditional Statements in C++ - the if ... then conditional statement with a then clause and an else clause.
    Note:  == is for equality comparison but = is for assignment operator
           == is a relational operator as is >=, <=, >, < and !=.
    
    if (x == 7) {
         //then clause is executed only if x does indeed contain the integer value 7
    }
    else {
         //else clause is executed if the preceding if condition evaluated to false
    }