The program shows a tree. By and by, birds appear in the tree, they look left and right, or disappear at random. Suddenly an evil cat shows up! The birds are scared and fly away. Then, new birds start to appear. The tree is printed as ASCII graphics on the console. There are 8 spaces in the tree, where birds can appear. Every space can show (1) a bird looking to the left or (2) a bird looking to the right, or (3) nothing. A space on the ground is reserved for the cat
The program proceeds in the following steps: 1. Initialisation: The tree is empty and the cat has not been here for one minute. 2. Optional: The screen is cleared using the instruction system( “cls” ) from the library cstdlib. 3. Display of a title message. 4. Display of the time since the last appearance of the cat. 5. Preparation of the tree and birds a. Random selection of one of the spaces in the tree. If the space is empty, a new bird appears in this space. A new bird is always looking to the left. b. Random selection of one of the spaces in the tree. If there is a bird, it disappears. c. All birds turn their heads in the opposite direction. d. If a cat was here one minute ago, then the tree is empty (no birds).
6. Display of the tree and animals. 7. Display of one-letter-commands available to the user (n=next, c=cat, q=quit). 8. The user enters a command. 9. The time since the cat is incremented by one minute. The time is just a number. It does not mean that the user waits for one minute in real-time (that would be really boring). 10. Preparation of the next step: If there was a cat, it goes away. If the user calls the cat, then it should appear in the next step and the time is set to zero. 11. If the user did not enter ‘q’, then the program repeats from step 2. 12. Otherwise the program ends.
Examples of using the program are shown in the end of this document. It is recommended to develop the program in small steps. Start from something simple and add functionality once the simple things work, for example: 1. Start with a program that shows an empty tree 2. Add one bird. A variable determines the state of the bird (absent, looking left, looking right). No randomness. No user input, just one picture. The bird is always in the same space. 3. A tree with eight birds. Birds don’t “change places”, each bird is assigned its own branch in the tree. There are variables for the states of the birds, all set by the programmer. Programmer can “turn on/off” birds. No randomness. No user input, just one picture. 4. Add a loop where the user can repeat printing the picture by selecting ‘n’ or ‘q’. 5. Add a number that counts how often the user typed ‘n’. This will be the “time since the cat”. 6. Add code to turn on/off birds randomly, or let them change the direction. 7. Add code to show a cat.
2 8. Add a variable to control if the cat can be seen or not. 9. Add code to let the user “switch on” the cat. Reset “time since the cat”. 10. Add code to “switch off” all birds after the cat has been shown.
If you find the program too difficult, you can simplify it (e.g. by getting rid of the cat). Consult the marking scheme to estimate how many marks you might lose by not implementing the full functionality. Difficulty of the Assignment: Correct solutions for this assignment can be vastly different. The example solution has 116 lines of code including comments and empty lines, 2 functions (main plus a function for printing the tree), 8 rather short arrays, 2 loops and 5 if-statements.