Chapter13programming&Data Representation
Chapter13programming&Data Representation
COMPUTER SCIENCE
9608
For examination in May 2019
CAMBRIDGE INTERNATIONAL AS & A2 LEVEL
COMPUTER SCIENCE 9608
CAMBRIDGE INTERNATIONAL AS & A2 LEVEL
COMPUTER SCIENCE 9608
CAMBRIDGE INTERNATIONAL AS & A2 LEVEL
COMPUTER SCIENCE 9608
?
The maximum number of marks is 75 for each paper.
CIC
Computer
Science 9608
Flair
Flair
Discipline
Flair
Discipline
Academic Rigour
Task12.01
Paper ESQ P172-175 Exam-style Question P211
P158
Python
VB.NET
Pascal
It fully supports:
Objective-oriented programming
Structured programming
and so on …
Key
characteristics:
Page 177
Key
characteristics:
1. Every statement must be on a separate line.
Page 177
Key
characteristics:
1. Every statement must be on a separate line.
Page 177
Key
characteristics:
1. Every statement must be on a separate line.
Page 177
Key
characteristics:
1. Every statement must be on a separate line.
Page 177
Key
characteristics:
1. Every statement must be on a separate line.
27).
Page 177
封装性 | Encapsulation
继承性 | Inheritance
多态性 | Polymorphism
Key
characteristics:
1. Every statement must be on a separate line.
4. Case sensitive
27).
6. Code makes extensive use of a concept [0] [1] [2] [3] [4] [5] [6]
# C Addition
Assign 1 to a
Assign 2 to b
Key call binary_add(a, b)
Assign the result to c
For Python, here the interpreter knows only that 1 and 2 are objects, but not what type
of object they are. So the The interpreter must inspect PyObject_HEAD for each
characteristics: variable to find the type information, and then call the appropriate summation routine
for the two types. Finally it must create and initialize a new Python object to hold the
1. Every statement must be on a separate line. return value. The sequence of events looks roughly like this:
# Python Addition
2. Indentation is significant: 'off-side rule'.
# Assign 1 to a
1.1 Set a->PyObject_HEAD->typecode to integer
3. Keywords are written in lower case.
1.2 Set a->val = 1
A whole number
Code A ← 34 A = 34
Example B ← B + 1 B += 1
An operator claims: B = B + 1
# comment
Syntax // comment '''multi-line
Definition comment'''
# this is a comment
Code // this is a comment '''this is a multi-line
Example comment'''
Not available
A single alphanumeric character CHAR
Represented as a string of length 1
OR (logical inclusion) OR or
IF x < 0
Code THEN if x < 0:
Example ENDIF
OUTPUT "Negative" print ("Negative")
13.05 Selection
FLAIR
DISCIPLINE
ACADEMIC RIGOUR
IF…
THEN… Pseudocode Flowchart Python
ELSE
The else keyword must line up
with the corresponding if keyword
IF <Boolean expression>
THEN if <Boolean expression>:
Syntax <statement(s)> <statement(s)>
Definition ELSE
<statement(s)>
else:
<statement(s)>
Indentation is used to show which statements
ENDIF form part of the conditional statement
IF x < 0
THEN if x < 0:
Code OUTPUT "Negative" print ("Negative")
Example ELSE
OUTPUT "Positive"
else:
print ("Positive")
ENDIF
13.05 Selection
FLAIR
DISCIPLINE
ACADEMIC RIGOUR
Nested IF Pseudocode Flowchart Python
elif (an abbreviation of else if)
IF <Boolean expression> must line up with the corresponding if
THEN
<statement(s)> if <Boolean expression>:
ELSE <statement(s)>
Syntax IF <Boolean expression>
THEN
elif <Boolean expression>:
Definition <statement(s)> <statement(s)>
else:
ELSE
<statement(s)> <statement(s)>
ENDIF
There can be as many elif
ENDIF
parts to this construct as required
IF x < 0
THEN
OUTPUT "Negative" if x < 0:
ELSE print ("Negative")
Code IF x = 0
THEN
elif x = 0:
Example ELSE
OUTPUT "Zero" print ("Zero")
else:
OUTPUT "Positive" print ("Positive")
ENDIF
ENDIF
13.05 Selection
FLAIR
DISCIPLINE
ACADEMIC RIGOUR