Sample Final
- Functions
- Write a recursive function that multiplies two positive integers
using only addition, not multiplication
- Write a Stack destructor
- Write a function that takes an integer pointer as an argument and
squares the value pointed to
- Write the code for a linked list. Assume we have our standard node
class. Write a push_front and push_back function, and a get_value function
which takes an integer, the index of the element (the number of the
element in the list) and returns the value stored there
- Definitions. Define the following and give a short (2 or 3 line) code
example of each
- Constructor
- New
- template
- recursion
- data abstraction (no code example for this one)
- inheritance
- accessor
- stack(no code)
- heap (no code)
- Thinking problem
Assume we have a function int random(int n) which returns a randomly
generated integer between 0 and n-1.
Yatzee is played with six dice. All six are rolled. There are many ways
to get points. In descending order, our limited combinations and point
values are as follows:
yatzee (6 of a kind) - 100 points
5 of a kind - 75 points
4 of a kind - 50 points
and "numbers". This latter one is the value of a face up (ie a 6) times
the number of those faces showing. So, if we had "sixes" and there were
three sixes rolled, the score woud be 3 * 6 = 18.
You should write a program to automatically play our limited Yatzee
1. Write a die-roll function. It should return a random number between
1 and 6
2. Produce an array which has 6 die rolls in it (stores the value of
die-roll called 6 times)
3. Check for points
-
Check from highest possible score to lowest.
-
Check for a Yatzee. If there is one, output 100 points, otherwise, check
for 5 of a kind.
-
If there are 5 of a kind, print out 75 points, otherwise, check for 4 of
a kind.
-
If there are 4 of a kind, print 50 points, otherwise, check for
"numbers".
-
Print numbers based on whichever value has the most faces showing (ie if
there are 5 twos and a six, you will choose twos). Print the number
you selected (show "sixes" if that's what you choose) and the score (the
value of the die times the number of dies showing: for 3 sixes, the score
is 18).
|