Calculations Worksheet

advertisement
Programming Logic - Beginning
152-101
Name
Score
Unit 4: Sequential Processing
Update Value
- ¼ point for each incorrect answer.
1.
True or False. The following are valid variable names.
If the answer is false, write why the name is not valid.
a.
T
F
RS6S6
b.
T
F
MIX-UP
c.
T
F
STOP!
d.
T
F
exam1
e.
T
F
September1Lecture
f.
T
F
2May
g.
T
F
Mike’s
h.
T
F
First Exam
i.
T
F
J
j.
T
F
Three
/ 10
Unit 4: Sequential Processing
2.
Circle the BEST answer (only one)
a.
b.
c.
The value of 15 / 2 is:
(i) 7
(ii) 7.5
(iii) 7 ½
(iv) 0.75
The value of 18 / 3 is:
(i) 6
(ii) 0.167 (iii) 6.0
(iv) none of these
The value of 21 \ 6 is:
(i) 3
(ii) 3.5
(iii) 4
(iv) 4.5
(v) none of these
d.
The value of 22 mod 7 is:
(i) 3
(ii) 1
(iii) 3.142 (iv) 22/7
e.
The value of 5 mod 7 is:
(i) 0
(ii) 2
(iii) 5
(iv) undefined
The value of 5 – 3.0 + 2 is:
(i) 0
(ii) 0.0
(iii) 4
(iv) 4.0
The value of 7 – 5 * 2 + 1
(i) -2
(ii) 5
(iii) -4
(iv) none of these
f.
g.
3.
Page 2
Determine the result of each of the following expressions.
x=5; y=6; z=4; w=3.5
a.
(x + z) mod y
b.
(x + y) mod z
c.
(x + y) * w
d.
x mod y ^ 3 \ z
e.
(y mod z) mod x
f.
(x * z) mod y
g.
((x * y) * w) * z
(All variables are integers)
a = 3
4.
Do a walkthrough of the code to the right to determine the
value of e.
Value of e is: _________________
b = 4
c = (a mod b) * 6
d = CInt(c / b)
e = (a + b + c + d) \ 4
Unit 4: Sequential Processing
5.
Page 3
Write Visual Basic statements to accomplish the following:
a.
Declares integer variables x and y.
statement: _________________________________________________________
b.
Initializes string variable grade to B
statement: _________________________________________________________
c.
Update the value of the integer x by adding 5 to it.
statement: _________________________________________________________
d.
Declares a double variable z and initializes its value to 25.3
statement: _________________________________________________________
e.
Copies the content of an integer variable y into an integer variable z
statement: _________________________________________________________
f.
Declares a Date variable Christmas and initializes it to December 25, 2006
statement: _________________________________________________________
6.
Write the following as Visual Basic expressions
a.
b equals 10 times a
expression: ________________________________________________________
b.
The string that represents 8
expression: ________________________________________________________
c.
b2 – 4ac
2a
expression: ________________________________________________________
d.
dueDate equals Today’s date plus 30 days
expression: ________________________________________________________
7.
What are the values for these variables after the statements in the box are executed?
(w, x, y and z are integers)
x value: ______
y value: ______
z value: ______
w value: ______
x = 5
z = 3
y = x
z = 2
w = x
z = w
w+=1
–
*
–
–
z
y + 3
2 * y + z
x
Unit 4: Sequential Processing
8.
Page 4
What are the values for these variables after the statements in the box are executed?
(x, y and z are integers
w and t are doubles)
x value: ______
y value: ______
z value: ______
w value: _____
t value: ______
x
y
x
z
w
t
=
=
=
=
=
=
17
15
x + y \ 4
x mod 3 + 4
17 \ 3 + 6.5
x / 4.0 + 15 mod 4 – 3.5
Download