COM 1100 Foundations of Computer Science
Preparation Notes for QUIZ #3 -- Tuesday, Oct. 17th
Fall 2000 -- Professor Futrelle
College of Computer Science, Northeastern U., Boston, MA
Notes posted 10/15/2000.
The quiz will be 20 minutes long and based primarily on Chapter 3 (it does also assume that
you have mastered the material from Chapter 2). The quiz will involve writing a program
that will be described to you in English in your instructions. You will write the program out
by hand on paper and hand it in.
The most important points in writing your program are, in order of importance:
- #1: The correctness of your syntax -- your program should be written so that it
would compile without error.
- #2: The program should be written so that it would produce the correct results.
- #3: The program should be written in the appropriate style, with proper indentation,
white space, naming of identifiers, etc.
- #4: Your program should be commented. Don't write many comments, since you have
to focus primarily on #1 and #2 above, as well as #3.
NOTE: There are about four or five important pieces of information from Chapter 3 that I
have deliberately omitted below, some or all of which will be on the Quiz.
If you read the chapter carefully, you will discover what they are. This is to avoid having
you think that the material below is all you have to study.
So consider the material below to be a useful checklist, but not a complete one.
You might want to print it out and then add items to it as you study.
It is always important to read
and re-read your textbook. It is also important to write out examples as you read, so you'll
be ready to write on your quizzes and exams and develop programs more easily. In general, in
all your C++ work in this course, try to follow the book's recommendations, e.g., that
identifiers for constants are all caps.
- Punctuation: Know where to use semicolons (statements) and where not to
(#include and {....} blocks).
- Variables
- Variable types (int, float, char) (not string types on Quiz 3, but in Lab 4)
- The common terms for ints and floats are "integers" and "real numbers".
- May be initialized.
- Understand floating point notation, e.g., 2.3e-2 = 0.023, not 2.3^-2
- Rules for properly formed (spelled) identifiers.
- Style: Choosing names and multiPart names.
- Constants
- Must be initialized when declared.
- Style: Normally all caps.
- Functions
- Have a return type (may be void).
- Need proper and meaningful identifier names.
- Have an argument list.
- Expressions and statements
- Simplest are expressions -- things that have a value, such as 42 or sqrt(99)
- Statements are the executable units of C++ code, e.g.,
an output or assignment statement.
- Assignments can be of mixed type, e.g., assigning an integer to a float.
- Arithmetic expressions involve operators you should know as well as precedence
of operators which can be made explicit or overridden by parentheses.
- Three types of constructs involving functions
- Function prototypes (declarations) with return type and argument list with
type identifiers and optional identifiers. End in semicolon.
- Definitions with return type and argument types and required formal argument identifiers.
There is no semicolon after the argument list or the function body in braces {....}.
- Function expressions which may or may not return a value.
Do not end in a semicolon
unless they end a statement, e.g., cout << sqrt(5) << endl;
Function expressions have no
argument type specifications, only the actual arguments and these must be expressions.
- Putting things in order. Ask your self: What does the compiler know,
and when/where did it know it?
- Function prototypes (declarations) are not required, but strongly recommended.
- Function prototypes must come before use of functions.
- Function definitions can be placed after main().
- Function execution order is controlled entirely their appearance in code bodies,
not by the order of appearance of prototypes or definitions.
- Topics not covered on this quiz,
(but which you will be using this week in Lab 4).
- Sec. 3.6 on scope
- Sec. 3.7 on strings
- Header and imported files for user-defined classes, pg. 153