CS 117, Introduction to Computer Science

Project 3: Coconuts, due Friday 9/29/00

The Story

Once upon a time, there were five people and a monkey on a ship bound for the Sydney Olympics. They didn't make it, however, and were shipwrecked on a desert island. All five people spent the first night on the island gathering coconuts, and they placed them in a big pile in the center of the camp. During the night, one person woke up and decided to take his share of the coconuts. He divided them evenly into one pile for each person (five piles), and gave the remainder to the monkey. He then took his pile out, buried it, and combined the remaining coconuts back together.

Soon a second person woke up and did the same thing. She divided her coconuts into a pile for each person (five piles), and gave the remainder to the monkey. She then hid her share and went back to bed. The third, fourth, and fifth people followed exactly the same procedure. Later on during the night, all the buried coconuts were eaten by a desert island beast. The main pile that was left in the camp was safe since the monkey was guarding it.

The next morning, after they all woke up, they divided the remaining coconuts into five equal shares. Any remaining coconuts were given to the monkey.

Your Mission

You should write a function called morning_coconuts that determines how many coconuts each person and the monkey ultimately receive.
  Here is the prototype you should use:

void morning_coconuts(int num_people, int init_coconuts, int &coconuts_per_person, int &coconuts_for_monkey);

Some notes:

  1. You will need to test your function using a main program of your own devising, but you should hand in a source file that contains only the function itself, along with any #include statements it requires. Do not include a main() in the file you hand in.
  2. Your function is more likely to be correct if is works with a friend's independently written main() as well as your own main(). You should feel free to swap main programs for testing purposes.
  3. Note that your function should not communicate directly with the user. That is, it should not have any input (cin) or output (cout) statements in it. The main program(s) you use to test your function will certainly need to talk to the user, but the function itself should remain silent.
(Some of the ideas in this problem, and some of the text, is taken from the 1997-98 ACM North Central Regionals programming contest).