CSE113 * EXAM3, VERSION 2

advertisement
[ CSE113 – EXAM3, VERSION 2]
Fall 2014
1. (20 points: 4 points each) Array definition and processing:
(i)
(ii)
(iii)
(iv)
(v)
Define an array Array1 that is initialized to 231, 145, 178, 122, 134, 189, 314,
110, 330, 450
Define another array Arry2 that can hold 10 integers. Create space for it.
Generate 10 random numbers in the range 1-100 to store in the second array,
Arry2. Use a “for loop”
Define another array Arry3 that can hold 10 integers; Create space for it; Add
Arry1 and Arry2 and store it in Arry3.
Determine the min and max values of the Array1 and print them out.
2. (20 points) Switch/decision statement: Write a switch statement to do that following:
Transforms the numbered day of the week into the day of the week in words. {1 – Monday,
2 – Tuesday, etc.}; input to switch statement is integer, output is a string printed out.
3. (20 points: 4 points each) Functions: Write a complete Processing function circle that
does the following: Assume floating (float) as the type for numerical values.
(i)
Inputs as parameters: fill color col, radius r; Use appropriate types when
specifying parameters.
(ii)
It then computes area of the circle using the formula: 𝒂𝒓𝒆𝒂 = 𝝅 ∗ 𝒓𝟐 where 𝜋 is
equal to 3.14.
(iii)
It draws the circle of radius r with fill color specified by col.
(iv)
It returns the value of computed area;
(v)
Show how you will call the function circle with values for radius as 14 and green
color and assign the result to circle1.
4. (20 points) Class definition: Design a class Student by specifying its name, at least 4
data attributes with appropriate types, and 4 functions including the constructor.
5. (10 points) Non-deterministic loop:
We want to determine the sum of n random numbers between 1 and 200 including 200.
When the sum exceeds 20000 we want to exit the loop.
(i)
Initialize a variable sum
(ii)
Write a while loop with the termination condition stated above
(iii)
Inside the loop generate random number num (between 1 and 200) and add this
to sum.
(iv)
Print the sum and num from inside the loop and after the loop.
6. (10 points) Moving shapes:
a. Draw a house as shown below within draw function.
b. Add movements so that it moves in increments in X-direction of +10 and Ydirection of +10. (Use appropriate functions.) Use translate function.
0
Download