Read each question carefully.  Answer the questions below on these sheets of paper.  Use the back if
6 pages
English

Read each question carefully. Answer the questions below on these sheets of paper. Use the back if

-

Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres
6 pages
English
Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres

Description

COP 2000 Introduction to Computer Programming Exam II Review The exam format will be similar to the first one with answers written following the questions on the test paper. The exam will be closed book, but students can use one 8.5’x11” sheet of notes in any size type front and back. Key Terms & Concepts: ( See also http://www.gibson.vero-beach.fl.us/classes/cop2000/glos45.html ) • Boolean data is a logical type of data with only two values: True and False • Ordinal data is a type of data in which all of the values within the set are known and in a predictable order. Ordinal data types include: all integer data types, char and bool, but not float. • Relational operators are those used to evaluate the relationships between items of data, including: • == - Equal to, the opposite of which is written in C as != (or not equal to). • > - Greater than<= (less than or equal to). • < - Less than>= (greater than or equal to). • Relational expressions are formulae such as X==A+B that compare items of data (including constants, symbolic constants, variables, or expressions) and produce an integer (1 for true, 0 for false) result. • Boolean (logical) operators such as && (and), || (or) and ! (not) are those used to combine Boolean operands into Boolean (logical) expressions such as (X==0 && Y>10) to produce a single Boolean result. • A condition is any expression that produces a Boolean result. • Branching is the act of breaking out of the normal ...

Informations

Publié par
Nombre de lectures 10
Langue English

Extrait

COP 2000 Introduction to Computer Programming Exam II Review
The exam format will be similar to the first one with answers written following the questions on the test paper.
The exam will be closed book, but students can use one 8.5’x11” sheet of notes in any size type front and back.

Key Terms & Concepts: ( See also http://www.gibson.vero-beach.fl.us/classes/cop2000/glos45.html )
• Boolean data is a logical type of data with only two values: True and False
• Ordinal data is a type of data in which all of the values within the set are known and in a predictable order. Ordinal
data types include: all integer data types, char and bool, but not float.
• Relational operators are those used to evaluate the relationships between items of data, including:
• == - Equal to, the opposite of which is written in C as != (or not equal to).
• > - Greater than<= (less than or equal to).
• < - Less than>= (greater than or equal to).
• Relational expressions are formulae such as X==A+B that compare items of data (including constants, symbolic
constants, variables, or expressions) and produce an integer (1 for true, 0 for false) result.
• Boolean (logical) operators such as && (and), || (or) and ! (not) are those used to combine Boolean operands into
Boolean (logical) expressions such as (X==0 && Y>10) to produce a single Boolean result.
• A condition is any expression that produces a Boolean result.
• Branching is the act of breaking out of the normal sequence of steps in an algorithm to allow an alternative process to
be performed or to allow the repetition of process(es).
• Control Structures are organized groups of statements that are followed in a specific order, including:
• Sequence in which the flow follows only one path from one step to another without branching. The use of the
sequential control structure is indicated in C by the use of a compound statement in which a series of statements
is enclosed (or "blocked") between the braces { and }.
• Selection in which alternative paths (legs) may be followed based on the result of a condition. When any leg is
completed, flow of control must branch forward to the end of the structure. When only two options are involved,
the appropriate C command to provide two legs would be
if condition { statement(s)-to-perform-if-true;} else { statement(s)-to-perform-if-false;}
When multiple options are required, you may place one selection structure inside the leg of another in a practice
called nesting. In the special situation that you are testing for many possible values in a single storage location
you may use the case structure (read below for more information).
• Repetition (also known as "loops") in which statements may be repeated based on the result of a condition. In
situations where you want to first perform a step and then test a condition to see if you should branch back to
repeat it, use the trailing decision structure (more below). In situations where you want to first test a condition to
see if you should perform a step and then perform it and branch back to repeat the test, use the leading decision
structure (more below). Each execution of the steps in a loop is called a pass. The variable that is used to control
loop passage/exit is called the control variable.
• Accumulation is the process of building a running sub-total through repeated adjustments to a variable.
• A variable used to indicate a specific situation or status within a program is called a flag.

Revised Order of Precedence Table (including arithmetic, relational and Boolean operators):
() Highest / First
postfix ++ postfix -- ^
! prefix ++ prefix -- |
unary + unary - unary & casts |
* / % |
+ - |
< > <= >= |
== != |
&& |
|| Lowest / Last

Truth Tables for Boolean Operators: (Op = Operand, a relational expression or Boolean value)
Op.A Op.B Op.A && Op.B Op.A Op.B Op.A || Op.B Op.A ! ( Op.A )
F F F F F F F T F T F T T T F
T F F T F T T T T T T
Page 1 Revision 2007-2 COP 2000 Introduction to Computer Programming Exam II Review

SELECTION STRUCTURES:
Structures such as the one on the left are coded in
C using the reserved word if.

The diamond shape encloses the condition that is
being tested (in this example, a Boolean
F T A > 0 expression). Remember that the C if statement
and can only execute one statement on each leg (T or
F), so the pair of steps on the False leg must be A < 9
coded inside of a { and } pair to make them a
single compound statement. Thus the C code Set X to 1 Replace X
would be: with triple
its original
if (A>0 && A<9)
value. Set A to 0 X=X*3;
else
{
X=1; A=0;
}

Note the use of the parentheses around the condition in the code above. Additional parentheses are often
necessary because of the order of precedence of operators in C (see the table on the previous page).

Remember also that the False leg may be empty, but not the True leg. If your flowchart shows the opposite,
then reverse the labeling of the True and False legs and reverse the logic of the condition inside the diamond. If
you can't determine what the logical opposite of the condition would be, simply use the NOT operator like this:
! ( A>0 && A<9 )

CASE Selection

C's switch statement can be used in the special situation that you are testing for many possible values in a
single ordinal storage location. In the example below, five possible paths might be followed depending on the
value stored in the character storage location X. Each path (leg) is selected based on the individual value(s) that
might be stored in X. The C code would be:
switch (X)
X {
case 'A': A=1; break;
A"" B"" C"" D","E" else'B': A=2; Y=1; break; "
case 'C': A=3 A ←1 A ←2 A ←3 A ←4 A ←0
case 'D': Y ←1 'E': A=4; break;
default: A=0; break;
}

Notice:
(1) the parentheses around the character expression (X)
(2) the inclusion of "break;" after each option serving to brace any multiple statements on each leg
(3) the braces used to enclose the full list of options.

The use of indentation and the positions of the carriage returns in the code are irrelevant.
Page 2 Revision 2007-2 COP 2000 Introduction to Computer Programming Exam II Review
REPETITION STRUCTURES:
Structure:
We studied two repetition structures (loops); one known as leading decision (a.k.a. while-do) and another
known as trailing decision (a.k.a. do-while). The primary difference between them is in where the test that
controls the loop is performed. Leading decision loops test before each pass and are coded in C using
while (condition) { body_statements; }
Trailing decision loops test after each pass and are coded in C using
do { body_statements; } while (condition);
We can design a loop that test somewhere in the middle, but that is consider very poor programming practice.
Control:
We studied two methods of controlling loop passage and exit. Counting control is based on the
testing of values that have been set and altered by the programmer. Programmers know in advance
how many times any counting loop will pass (execute its body) because all values of its control
variable are predictable. Sentinel control is based on the testing of external values that have been
read into the program. Programmers do not know in advance how many times a sentinel loop will pass
(execute its body) because the values of its control variable are unpredictable.
Boundary Values:
The values of variables just prior to the entry into a loop and just after the exit from a loop are called
boundary values. Steps inside a loop can be organized so that the value of a variable is changed after it
is displayed, so don't expect that variables will always contain the last value that you saw displayed.
Counting Loops:
All counting loops have at least four parts:
• initialization - prior to the loop entry, a first value of the control variable is set
• body - where the step(s) to be repeated belong
• increment (or decrement) - where the control variable is increased (or decreased)
• test - where the control variable is tested to determine whether the loop should pass or exit.
The bottom three steps are not always in the order listed above. The order of the steps will effect the
boundary values of the control variable.

The two examples below show loops that will count from 1 to 9 and display the value of the control
variable (also called a counter in a counting loop). Notice the exit value on N will be 10.



N ←1 N=1; N ←1 N=1;
while (N<=9) do
{ {
F N ↵ printf ("%d\n",N); printf ("%d\n",N); N<=9
T N = N+1; N = N+1; N ←N+1
N ↵ }}

while (N<=9);
N <= 9 N ←N+1
T F
Page 3 Revision 2007-2 COP 2000 Introduction to Computer Programming Exam II Review
If a loop: (1) uses the Leading Decision structure, (2) uses counting control, and (3) increments as the

  • Univers Univers
  • Ebooks Ebooks
  • Livres audio Livres audio
  • Presse Presse
  • Podcasts Podcasts
  • BD BD
  • Documents Documents