Please staple the assignment together. At the top of the first page print, in this order: your first name, your last name, CIS33A, and the assignment letter. Print the exercise or problem number at the beginning of each exercise and problem. Assignments are due at the beginning of class, and will be marked down if turned in later.
Authorship note: These assignments have been adapted from assignments given by Clare Nguyen, who adapted them from the work of Behrouz Forouzan.
There are 2 types of problems.
Show the actual list in each case.
What is the value of the variable?
What is the value of each variable?
(This is an interesting example, but is poor code.)
Show the value of variables and the array.
(This is an interesting example, but is poor code.)
Show the array.
Show the value of the array after the execution of the following program segment:
Show the value of the arrays after the execution of the following program segment:
What would be printed from the following program segment?
$\ = "##" ; $, = "?" ; @x = (2, 3, 4, 5, 6, 7) ; print ("@x" , "@x") ;
What would he printed from the following program segment?
while ( (2, 5, 1) - 1) { print ("hello\n") ; }
What would he printed from the following program segment?
@x = (3, 4, 8, 10) ; foreach (@x) { print ("hello\n") ; }
What would he printed from the following program segment?
foreach (2 , 4 , 6 , 8 , 10 , 12 , 14) { if($_ > 10 ) { print ("$_\n") ; } last ; }
What would he printed from the following program segment?
foreach (2 , 4 , 6 , 8 , 10 , 12 , 9 , 14) { if($_ > 10 ) { next ; } print ("$_\n") ; }
What would he printed from the following program segment?
$x = 1 ; { print ("$x\n") ; $x++ ; if ($x > 7) { last ; } redo ; }
What would he printed from the following program segment?
@x = (1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10) ; foreach (@x) { $x = pop (@x) ; $y = shift (@x) ; print ("$x $y \n") ; }
What would he printed from the following program segment?
@x = (1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10) ; foreach (@x) { $x = pop (@x) ; $x = shift (@x) ; push (@x, $x) ; } print ("@x\n") ;
Write the following problem, with the following restrictions:
Write the following problem, with the following restrictions:
The problem to be done twice as problem B16 and problem B17 follows:
Prompt the user to enter a sequence of numbers (between 1 and 20) and/or letters (lower or uppercase), each number or letter is separated by a space, and the length of the sequence can vary. The user ends the sequence with a "q" or "Q", followed by a space. (Assume that the user always enters a "q" or "Q" followed by a space.)
An example of user input is:
1 12 a 2 5 P Q
After reading in the input, the script will:
Your script output for the example above should be:
1+12+2+5 = 20
Test your script with the following input (6 different test cases):
1 12 a 2 5 P Q | output should be: | 1+12+2+5 = 20 |
1 3 A t 4 q | output should be: | 1+3+4 = 8 |
c 1 Q | output should be: | 1 = 1 |
a b c d Q | output should be: | no valid number entered (or some similar error statement) |
1 2 34 q 4 5 6 | output should be: | 1+2 = 3 |
22 q 5 6 | output should be: | no valid number entered (or some similar error statement) |