computer Science HW
CS111 Kazumi Slott Assignment 1 on flowcharts No late submissions will be accepted. Reminder The while loop should have the following structure. The entrance of a while loop has to have a condition. Get input (the first input is entered here) Check False condition on input True
………….. …………. The loop body Get input Out of loop BAD – The following cannot be converted to C++ Get input The entrance of the loop is an input à It doesn’t work. Check False condition on input True
………….. …………. Out of loop
A condition (if/else) has the following structure. True coming out of the right and False coming out of the left. False average >= 75 True Output “Proceed to the next class”
The while loop has True coming out of the bottom and False coming out of the right. Get input (the first input is entered here) Check False condition on input True
………….. …………. The loop body Get input Out of loop
Start Enter an age à Age Check F Age > 0 T T F Age >= 100 F T Output “Century” Age >= 55 Output “Chichen” Output “AARP” Enter an age à Age End
You are going to draw 3 flowcharts. You may type or handwrite your flowcharts and tests. If you have any questions, come see me during my office hours or talk to me before or after lecture or lab. HINT: You will not use the do-while loop for this assignment. <Problem 1: 20> Draw a flowchart for the program that will calculate BMI from a height (in inches) and a weight (in pounds). The program will tell the BMI along with advice. BMI is calculated in the following way. BMI = weight in pounds x 703 height in inches x height in inches Give the following advice. BMI 25.0 and above Exercise more Less than 25.0 You have a healthy weight Test your algorithm using the following 2 cases. <Test1> height: 67 weight: 120 Outputs are 19.79 You have a healthy weight <Test2> height: 67 weight: 200 Outputs are 31.32 Exercise more
<Problem 2: 40 points> Draw a flowchart for the program that will read an unknown number of ages. (0 is a valid age used for a baby.) The user will enter a negative number if there are no more ages to enter. The program will output the average age and youngest and oldest ages. If no ages were entered, display “No ages were entered” (see <Test 4> below).
Hint: Use 2 boxes to store the youngest and oldest ages. What would you put in these boxes at the beginning?
Test your algorithm using a table with the following 4 cases. Make one table for each test. You will have 4 separate tables. Age Age ≥ 0 Num Total + Age à Total Youngest Oldest Avg <Test 1> 20, 0, 10, 5, -1 Outputs should be 8.75 (average age) 20 (oldest) 0 (youngest) <Test 2> 100, 105, -5 Outputs should be 102.5 (average age) 105 (oldest) 100 (youngest) <Test 3> 50, -7 Outputs should be 50 (average age) 50 (oldest) 50 (youngest) <Test 4> -1 Outputs should be No ages were entered
<Problem 3: 40 points> Draw a flowchart for the program that will let a teacher enter exactly 5 scores (each score needs to be greater than or equal to zero). The program will output the total and average score. Reject bad inputs from the user. If she enters a negative number, tell her “Invalid score. Enter a score again”. Test your algorithm using a table with the following 2 cases. Make one table for each test. You will have 2 separate tables. Repetition# Score Score < 0 Total + Score à Total Avg <Test 1> Enter a score: -10 Invalid score. Enter a score: -50 Invalid score. Enter a score: -35 Invalid score. Enter a score: 20 Enter a score: -30 Invalid score. Enter a score: 60 Enter a score: -40 Invalid score. Enter a score: 40 Enter a score: 30 Enter a score: 15 The total score is 165 The average is 33 <Test 2> Enter a score: 25 Enter a score: 55 Enter a score: 0 Enter a score: 80 Enter a score: 30 The total score is 190 The average is 38 <HINT> Use a while loop to reject negative inputs. Refer to page 12 in “Lecture Notes: Algorithms – repetition”.