7.3 Robots |
This program will probably use the while
loop.
You are in charge of a moon colonization program. It has been determined that the only way to do the project is with robots. The robots know how to build more robots. After there are enough robots people can also be sent to the moon.
Each robot collects materials for two (2) months. During this time it has collected enough materials to build three (3) robots. It takes one month to build a robot. As soon as it is built (and running) it starts collecting materials to build robots its self.
The robot that just finished building the three(3) robots will normally start collecting materials again too.
Stop collecting new material for robots when you have 200 or more robots. Some robots will move directly from being built to being idle. So if the total number of robots at the end of one month equals or exceeds 200, no robots should start collecting the following month. If a robot had started collecting material, let the robot complete its cycle.
Start with one(1) robot, but use a preprocessor #define
statement to set this value.
Write a program that computes the number of robots and keeps track of what they are doing each month.
Print out the number of robots at the beginning of each month. The total should include both old robots and the robots that have just been built and their assignments.
This means that the first month that shows the total number of robots greater than or equal to 200 robots should also show a decline in the number of collecting robots.
Your program need to print the following:
Other requirements:
#define
for the initial number of robots
and the end point constants.
printf
format string of" %3d %8d %8d %8d %8d\n"
Hints:
c1=1; while( c1+c2+b1+b2+b3 ) { ... }
Study areas:
while
statement. Hanly & Koffman page 212.
Kernighan p10 & p60.
Harbison p241-242.
printf()
function. Hanly & Koffman pages 48-50 and pages 612-615.
Kernighan p7, p11, & p153.
Harbison p366+.
#define
preprocessor command. Hanly & Koffman page 37.
Kernighan p14.
Harbison p42-43.
?:
Hanly & Koffman Appendix C, page 862.
Kernighan p51.
Harbison p218.
Extra credit:
#define
for the collecting and building days.
Mark your output with:
Please turn your lab in to me, Louis Taber, during class, or slide it under the door of Santa Rita Building room A-115 (my office).
7.3 Robots |