computer Science HW

profilehd-zd22

3 questions:

 

 

<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

page4image11280 page4image11440

<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

page5image12064 page5image12384

 

<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.

page6image4816

Repetition# Score Score < 0

<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

 

 

Due in 12 hours 

  • 9 years ago
  • 3
Answer(0)
Bids(1)