Date: Mon, 11 Nov 1996 17:03:27 GMT
Server: NCSA/1.5
Content-type: text/html
Last-modified: Wed, 06 Nov 1996 22:33:10 GMT
Content-length: 5234
CS 302 Section 10 Notes and Examples
CS 302 Section 10 Notes and Examples
Chapter 1-2
Some sample programs which demonstrate material from Ch. 1.3-2.5:
C++ Basics: (Ch 1.3-2.3,2.5)
- Baseball (Demonstrates basic
C++ structure, declaring and using variables, int vs. double,
char, cin and cout, arithmetic operators,
how to get a double result when dividing two ints,
commenting)
- Dividing Money (New concepts:
difference between dividing ints and doubles, use of
/ and % (divide and modulus) for integers) This is similar but not
identical to the program we went over in class.
Flow Control: (Ch 2.4)
- Income Taxes (New concepts:
if and if-else statements, nested if
statements, use of const for constants) This is similar
but not identical to the program we went over in class.
- Multiplication Tables (New
concepts: while and do-while loops)
Chapter 3
Some sample programs that demonstrate material from Ch. 3:
- Force Equation (New concepts:
functions, prototypes vs. definitions, formal vs. actual parameters)
This is similar but not identical to the program we went over in
class.
- A Confusing Example (New concepts:
names of formal and actual parameters do not need to match, using local
variables in functions)
- Area of Shapes (New concepts:
function name overloading) This is the program we went over in
class.
Chapter 4
Some sample programs that demonstrate material from Ch. 4:
- Compass Headings (New concepts:
void functions, precondition/postcondition, re-prompting user for valid
input, a userful thing to use the % operator for)
- Making Change (New concepts:
call-by-reference, good use of global constants) This program is
similar but not identical to the program we wrote together in class.
- The Really Evil Simpsons Program
(Concepts: pass-by-reference vs. pass-by-value, functions calling other
functions, scope of local variables and pass-by-value variables, why
not to use global variables) This is the example we did in class.
Chapter 5
Some sample programs that demonstrate material from Ch. 5:
- Making a Grid of Numbers (New concepts:
opening files, checking that files were opened sucessfully, closing files,
formatting output)
- Copying Files (New concepts: using get
and put for character I/O, using the eof function)
Chapter 7
Some sample programs that demonstrate material from Ch. 7:
- Voting (New concepts: switch
statements, width output manipulator inside of an output stream) This
is a fleshed out version of an example I went through in class.
- Rock, Paper, Scissors (New concepts:
enum for enumerated types, for loops, nested
switch statements)
Chapter 6
Some sample programs that demonstrate material from Ch. 6:
These two programs do the exact same thing.
The first example uses
a struct, the second example uses a class.
- Increment the Date with a Struct (New
concepts: declaring & initializing structs, passing
structs as arguments to functions and using them as return types
from functions, using an enum type like an integer) This
is a fleshed out version of an example I went through in class
- Increment the Date with a Class
(New concepts: declaring a class,
writing member functions for a class, initializing a class with a
constructor) This is a fleshed out version of an example I went
through in class
- The Electric Company (New concepts:
overloading constructor functions, Abstract Data Types) This is a
fleshed out version of an example I went through in class
Chapter 9
Some sample programs that demonstrate material from Ch. 6:
- Points Per Game (New concepts:
declaring, initializing, and using an array, using a partially
filled array, passing an entire array as an argument to a function)
- Coming soon... the Library Class example...
Make sure you also understand the searching and sorting
examples in the text book.
Click here to
return to the CS 302 section 10 homepage
Last modified: Wed Nov 6, 1996 by Mike Steele