|
| |
Exercise 4-2-2
This assignment will be handed in by the due date listed on the term outline.
(13 marks)
You may create the code in JCreator but you MUST write out the answers by
hand and submit them for grading. Label your work carefully for parts a, b,
c, and d.
Note: Declare any 'new' variables that are required in the
section of code that they pertain to. Variables and objects declared or created
in a previous section of the question do not have to be declared or created
again (you can still use them).
If a particular section requires a loop you must give the code for the loop.
In other words, you cannot say "this code goes inside the loop from
part b" and get full marks.
- For an array named diceRolls:
- Declare and allocate memory for the array. It has 1000 elements and
must be suitable for the items described in part (b) below. (1
mark)
- Assume that the above item has been completed in another section of
code.
Initialize each element of diceRolls with a random number
representing the roll a die. The die has the possible rolls of 1, 2, 3,
4, 5, or 6. (2 marks)
- Assume that the above items have been completed in other sections of
code.
Find and display the value of the average roll. The answer should be
without decimals. (2 marks)
- Assume that the above items have been completed in other sections of
code.
Count how many of each possible roll are contained in the array. That
is, how many 1s are in the array?, how many 2s? etc. Display the answers
in a table format. (2 marks)
- For an array named life:
- Initialize, using a list, an array named life with these values:
true, false, false, true (1 mark)
- Assume that the above item has been completed in another section of
code.
Declare and allocate memory for another array named death of the same type and size
as life. (1 mark)
- Assume that the above items have been completed in other sections of
code.
Use a for loop to set the values in death to be the
opposite of the values in life. For example life[0] = true
therefore set death[0] = false, etc. (2
marks)
- Assume that the above items have been completed in other sections of
code.
Display the values of both arrays in a nicely titled table:
(2
marks)
Check the Late
Submissions policy.
|