COS220: INTRO TO COMPUTER SCIENCE I HOMEWORK 5 Splodges and Other Stuff Part 1 (2 points) (One or more programs to be modified and run from the online database of text programs) a) Modify program F6-2 to handle pass, fail, AND pass with honors. Run it with your own test data. b) Run program F5-CBR (the data is included at the end of the file). c) Modify program F5-CBR to print a university heading before any data is printed, and a college heading before each set of college data is printed. Part 2 (7 points) (A program to be designed and implemented based upon specifications provided by the instructor) PROBLEM: SPLODGE POPULATION EXPERIMENTS A team of scientists is conducting experiments on Splodges, microorganisms that double in population every 3 minutes unless treated with the inhibiting agent TBA. Specifically, every three minutes the splodge population is known to grow according to the following formula: POP := 2 * POP - TBA where TBA represents the number of drops of TBA applied during the period. Obviously if no TBA is ever applied, then a splodge population will double in size until it overruns the laboratory. On the other hand, if a "bucket" of TBA is applied, we can "drown" a splodge population before it causes problems. You are to design a Pascal program to process an arbitrary number of splodge growth experiments. EXPERIMENT INPUT: The input data consists of zero or more "experiments", with a negative integer marking the end of the "file". Each experiment begins on a new line with an initial splodge population, followed by zero or more applications of TBA (to be applied in 3 minute intervals), FOLLOWED BY A NEGATIVE INTEGER MARKING THE END OF THE EXPERIMENT. The experiment ends when either the TBA runs out or the population becomes zero or negative. Note that there may be leftover TBA after the completion of an experiment, and that it must be accounted for. Use the following input data to test your program. You need Page 1 COS220: INTRO TO COMPUTER SCIENCE I HOMEWORK 5 not type this data into your program file. Just copy this homework file to a temporary file, delete every line in that temporary file except the data below, and then use the XEdit "get" command to insert the data into your program file. 10 3 30 7 3 4 5 0 -1 1 1 1 1 1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 -1 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 2 3 2 3 -1 20 -1 -99 Notice that the first experiment begins with a splodge population on a new line, continues with 7 applications of TBA, and ends with a -1. There are six experiments in total, and the entire "file" is ended with a -99. OUTPUT: A report must be printed as follows: SPLODGE EXPERIMENTS Initial Final Elapsed Experiment Splodge Splodge Time of Used Unused Number Population Population Experiment TBA TBA ---------- ---------- ---------- ---------- --- --- 1 2 . . . n -------------------------------------------------------- Total TBA Used : Total TBA Unused: Note that the calculated final splodge population may be negative for a particular experiment. Simply report that negative value (even if it makes a bit more sense to report a zero). Note also that the elapsed time of an experiment is simply 3 times the number of applications of TBA. For example, if an initial splodge population of 10 is "drowned" by 1 application of 10000 drops of TBA, then the elapsed time of the experiment is 3 seconds. Page 2 COS220: INTRO TO COMPUTER SCIENCE I HOMEWORK 5 IMPORTANT: The purpose of this homework assignment is to demonstrate the power of the while statement. Therefore, NO IF STATEMENTS ARE ALLOWED IN YOUR PROGRAM. Part 3 (1 point) (A set of questions to be answered based upon the readings and programs from parts 1 and 2) a) We can classify the splodge program as another example of the "control break" problem. Why? b) What properties of while statements allow us to write complex programs without IF statements? Part 4 (0 points, but highly recommended) Make lots of controlled changes to your programs and observe their effects. DON'T HAND ANY OF THIS IN, but you may come to my office and discuss them with me. Page 3