(Latest Revision: 03/01/2000)


Week 03 Notes for CS 1500 -- Spring 2000
(this is draft material)

* Take roll

* The tutoring schedule is now available 
  in the General_Info section

==================================================
MONDAY
==================================================
* Take care of lab partner assignments

* Glance at schedule to see what we have lined
  up for this week.

* Show how cout can be used to output numbers,
  expressions, literals.  Give students an
  example of a function with parameters. 

* Discuss simple C++ constructs
  + use of cout stream
  + Using expressions with <<
  + use of endl
  + using functions
    - good for parts of programs that have to be
      repeated.
    - with parameters, good for taking care of a
      large number of similar tasks with just
      one chunk of program code -- one small set
      of instructions with flexibility to do
      many different jobs.
  + idea of a return value

* int's and float's

* declaring and naming variables


==================================================
WEDNESDAY
==================================================
* Hand back lab #1 printouts

* I need to discuss partners with:
    + Steve Netniss
    + Kristi Nasrawi
    + Rashad Elliot

* I need to have a word with:
    + Pardeep -- get full name, give class handouts
    + Johnnie Gevarges -- discuss account problem

* (Show example of how to read e-mail on the Sun
  Ultra's? Or did we do this?

* assignment statements, lvalues, rvalues

* separate and combined declaration-initialization

* integer arithmetic -- including surprises about integer division

* modulus operator % and unary -

* operator precedence

* interactive programs

* Look at the changes in the directions for the
  lab on Friday

* You will be sending 4 pieces of e-mail.

* Rehearse strategies for saving versions of
  your work.

==================================================
FRIDAY 
==================================================

* Take roll

* We perform the lab

* Remind students that Solo program #1 is due
  before midnight on Monday, March 6.  Check the
  web space for details.  Also, review the Hello
  World assignment (Lab00) and Lab01 to recall
  skills required for completing the assignment.

* Remind students that they must check the web
  space frequently for class information.  Weekly
  reading assignments, assignment due dates, and
  quiz dates are all to be found in the schedule
  or will appear there sometime during the
  semester.

==================================================
EXAMPLES
=================================================

---------- START lab021.cpp ----------
// Opening comment that describes the program
// Preprocessor directive to include header file iostream.h

int main(void)
{
   // Declarations of 3 variables with comments for each

   // Initialization of speed and time elapsed
   // Calculation of distance covered
   // Print values of 3 variables

   return 0;
}
----------  STOP lab021.cpp ----------


----------  START John's example ----------
#include <iostream.h>

// THINK ABOUT THE OUTPUT THAT EACH STATMENT PRODUCES

void DoTimes(int yourNumber)
{
  cout << "One times " << yourNumber << " makes " <<   1 * yourNumber << endl ;
  cout << "Two times " << yourNumber << " makes " <<   2* yourNumber << endl ;
  cout << "Three times " << yourNumber << " makes " << 3* yourNumber << endl ;
  cout << "Four times " << yourNumber << " makes " <<  4* yourNumber << endl ;
  cout << "Five times " << yourNumber << " makes " <<  5* yourNumber << endl ;
}


int Square (int yourNumber)
{
   int s_temp ;
   s_temp = yourNumber * yourNumber ;
   return s_temp ;
}

int main(void)
{
  int n ;
  cout << endl ; // skip a line in the output

  cout << "One and One are: " << 2 << endl;
  cout << "Two and Two are: " << 2 + 2 << endl;
  cout << "Six times Eight makes: " << 6*8 << endl;

  cout << endl ;  // skip a line in the output

  DoTimes(4)  ;
  DoTimes(12) ;
  n = Square(15) ;

  cout << endl ; // skip a line in the output

  cout << "The square of 15 is: " << n << endl ;

  cout << endl ; // skip a line in the output

  cout << "What number is this? " << 14 - 10 / 2 + 8 << endl ;
  cout << "What number is this? " << (14 - 10) / 2 + 8  << endl ;
  cout << "What number is this? " << 14 - 10 / (2 + 8)  << endl ;
  cout << "What number is this? " << (14 - 10) / (2 + 8)  << endl ;

  cout << endl ; // skip a line in the output

  return 0;
}
----------  STOP John's example ----------


----------  START ex0201.cpp ----------
// Declare, assign, and print an integer variable 
   
#include <iostream.h>
   
int main(void)      
{   
   int NumberOfDays;         // number of days in week 
   
   NumberOfDays = 7;    
   cout << NumberOfDays << " days are in a week.\n";   
   
   return 0;  
}   
---------- STOP  ex0201.cpp ----------



----------  START ex0202.cpp ----------
// Example 2.2. Program to print the number of units in 17 dozen 
   
#include <iostream.h>
      
int main(void)    
{   
   const int DOZEN = 12;    // number of units in a dozen
   int NumberOfDozens = 17, // number of dozens 
       units;               // number of units 
         
   units = NumberOfDozens * DOZEN;    
   cout << NumberOfDozens << " dozen contain " 
        << units << " units.\n";
       
   return 0;   
}   
---------- STOP  ex0202.cpp ----------



----------  START ex0205.cpp ----------
//    
// Example 2.5. Program to convert a measurement in inches    
// to yards, feet, and inches   
//    
   
#include <iostream.h>
   
int main(void)   
{   
   int TotalNumInches = 158, // total length in inches     
       yards,                // # yards  in TotalNumInches 
       feet,                 // # feet   in TotalNumInches 
       inches;               // # inches in TotalNumInches 
   
   feet   = TotalNumInches / 12;   
   inches = TotalNumInches % 12;   
   
   yards  = feet / 3;   
   feet   = feet % 3;   
   
   cout << "In " <<  TotalNumInches << " inches there are "
        << yards << " yard(s), " << feet << " foot(feet), and "
        << inches << " inch(es)\n";
   
   return 0;
}
----------  STOP ex0205.cpp ----------


----------  START ex0220.cpp ----------
// Example 2.20. Program to input an integer and print its square   
   
#include <iostream.h>
   
int main(void)   
{   
   int num,      // input 
       square;   // square of num 
   
   
   cout << "Please type in an integer: ";
   cin >> num;
   
   square = num * num;   
   cout << "The square of " <<  num << " is " << square << ".\n";

   return 0;
}   
---------- STOP ex0220.cpp ----------