Академический Документы
Профессиональный Документы
Культура Документы
"There is a division in the student population between those who go to college to learn and those who go to college to earn a diploma." Blau "Computer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter." Eric Raymond
Pseudocode
Artificial, informal language used to
Sequential execution Statements executed in order Transfer of control Next statement executed not next one in sequence 3 control structures Sequence structure
Programs executed sequentially by default
Selection structures if, if/else, switch Repetition structures while, do/while, for
6
++seniorFemales;
|| (logical OR)
true if either of condition is true
if ( semesterAverage >= 90 || finalExam >= 90 ) cout << "Student grade is A" << endl;
7
vice versa
if ( !( grade == sentinelValue ) ) cout << "The next grade is " << grade << endl;
Alternative:
if ( grade != sentinelValue ) cout << "The next grade is " << grade << endl;
Rhombus symbol (decision symbol) Indicates decision is to be made Contains an expression that can be true or false
if structure Single-entry/single-exit
Test condition, follow path
10
grade >= 60
true
print Passed
false
11
if Performs action if condition true if/else Different actions if conditions true or false Pseudocode
if students grade is greater than or equal to 60 print Passed else print Failed
if ( grade >= 50 ) cout << "Passed"; else cout << "Failed";
15
C++ code
Condition
Value if true
Value if false
false
grade >= 60
true
print Failed
print Passed
22
23
24
Without braces,
cout << "You must take this course again.\n";
always executed
Block Set of statements within braces
25
In logical disjunction result is true whenever one or more of its operands are true. In logical conjunction result is true if both of its operands are true, otherwise the result is false.
can be rewritten as
variable operator= expression;
34
Example
if ( payCode == 4 ) cout << "You get a bonus!" << endl; If paycode is 4, bonus given
35
36
Preincrement
Variable changed before used in expression Operator before variable (++c or --c)
Postincrement
Incremented changed after expression Operator after variable (c++, c--)
37
If c == 5, then
cout << ++c;
c is changed to 6, then printed out
38
When variable not in expression Preincrementing and postincrementing have same effect
++c; cout << c;
and
c++; cout << c;
39
40
41
42
Operators.
Chapter