I need help writting the pseudocode and the raptor for this problem. The America
ID: 3539479 • Letter: I
Question
I need help writting the pseudocode and the raptor for this problem.
The American Red Cross wants you to write a program that will calculate the average pints of blood donated during a blood drive. The program should take in the number of pints donated during the drive, based on a seven hour drive period. The average pints donated during that period should be calculated and displayed. Additionally, the highest and the lowest number of pints donated should be determined and displayed. Write a loop around the program to run multiple times.
Explanation / Answer
This lab examines the various ways of working with arrays by writing pseudocode. Read the following programming problem prior to completing the lab.
The American Red Cross wants you to write a program that will calculate the average pints of blood donated during a blood drive. The program should take in the number of pints donated during the drive, based on a seven hour drive period. The average pints donated during that period should be calculated and displayed. Additionally, the highest and the lowest number of pints donated should be determined and displayed. Write a loop around the program to run multiple times.
Step 1: Declare the following CONSTANT and variables:
A constant names SIZE that represents the size of the array (7).
An array named pints of the data type Real of size SIZE
A variable named totalPints of the data type Real
A variable named averagePints of the data type Real, initialized to 0
A variable named highPints of the data type Real
A variable named lowPints of the data type Real
Module main()
//Declare local variables
Declare String again = %u201Cno%u201D
Declarations here.
While again == %u201Cno%u201D
//module calls below
Display %u201CDo you want to run again: yes or no%u201D
Input again
End While
End Module
Step 2: Write a module call to a module named getPints that passes the pints array. This module reads in the number of pints for each hour. Additionally, write a module header named getPints that accepts the pints array and its size. (Reference: Passing an Array as an Argument to a Function, page 292).
//Module call
Call ________________(______________, SIZE)
//Module header
Module ___________(Real ______________[ ], Integer sizeOfArray)
Step 3: Write a for loop that runs enough times to read in all 7 values into the array using the counter variable. Inside the for loop, allow the user to enter values. (Reference: Using a Loop to Step Through an Array, page 274).
Declare Integer counter
For __________________ = 0 to _______________
Display %u201CEnter pints collected:%u201D
Input ___________[_________]
End For
Step 4: Write a function call to a module named getTotal that passes the pints array and its size. Additionally, write a function header for the module getTotal.
//Function call
totalPints = getTotal (_______________, _______________)
//Function header
Function Real getTotal (__________ [], ________________)
Step 5: Write a for loop for the body of getTotal. It will total up up the values of the array and store it in the variable totalPints. Also, return the correct value from the function. (Reference: Totaling the Values in an Array, page 286).
Declare totalPints = 0
Declare Integer counter
For __________________ = 0 to _______________
Set _________ = ________ + ______________[________]
End For
Return _________________
Step 6: Write a function call to a module named getAverage that passes the totalPints variable and the size of the array. Additionally, write a function header for the function getAverage that accepts the totalPints variable and the size of the array.
//Function call
averagePints = getAverage(totalPints,SIZE)
//Function header
Function _________(Real ____________, Integer ___________)
Step 7: Write a body of the function getAverage, which will return the value of the average pints of blood taken over the drive period. (Reference: Averaging the Values in an Array, page 287).
Step 8: Write a function call to a module named getHigh that passes the pints array and the array size. Additionally, write a function header named getHigh that accepts the pints array and the array size.
//Function call
highPints = ____________(______________, ___________)
//Function header
Function _________(Real _____________, Real ___________[ ])
Step 9: Write the code that will determine the highest value in an array. Also, return the correct value from the function. Note that it initially sets the highPints to the first number in the pints array. (Reference: Finding the Highest Value in an Array, page 288).
Declare Real highPints
Set highpoints = pints[________]
Declare Integer index
For index = 1 to 6
If _______________[_______] > highPints Then
Set ____________ = __________[_______]
End If
End For
Return ______________________
Step 10: Write a function call to a module named getLow that passes the pints array and the size of the array. Additionally, write the function header for getLow that accepts the pints array and the size of the array.
//Function call
lowPints = ____________(______________, ___________)
//Function header
Function _________(Real _____________[ ], Integer ___________)
Step 11: Write the code that will determine the lowest value in an array. Also, return the correct value from the function. Notice the lowPints is initially set to the very first number in the pints array. (Reference: Finding the Lowest Value in an Array, page 290).
Declare Real lowPints
Set lowPints = pints[________]
Declare Integer index
For index = 1 to 6
If _______________[_______] < lowPints Then
Set ____________ = __________[_______]
End If
End For
Return ______________________
Step 12: Write a module call to a module named displayInfo. Pass the necessary variable to the functions that are needed to display the averagePints, the highPints, and the lowPints. Also, write the module header that accepts the same variables.
//Module call
Call ____________(______________, ___________, ___________)
//Module header
Module ________(Real ________, Real ________, Real _______)
Lab 7.2 %u2013 Checking the Work
Using the program from Lab 7.1, complete the following checks for a better understanding of your work.
Step 1: Imagine the following number of pints were entered into the array.
Element
34
39
25
18
43
31
12
Index
0
1
2
3
4
5
6
Step 2: Recall Step 5 of Lab 7.1 that accumulates the pints collected.
Declare Real totalPints
Declare Integer counter
Set totalPints = 0
For counter = 0 to 6
Set totalPints = totalPints + pints[counter]
End For
Step 3: Complete the following chart by writing what the counter and the totalPints value stores on each iteration of the loop.
Counter
totalPints
0
34
1
73
2
Step 4: Recall Step 9 from Lab 7.1 that determines the high value.
Declare Real highPints
Set highPints = pints[0]
Declare Integer index
For index = 1 to 6
If pints[index] > highPints Then
Set highPints = pints[index]
End If
End For
Step 5: Complete the following chart by writing what the highPints and the pints array value stores on each iteration of the loop. Also conclude whether it will be True or False.
Pints
highPints
True or False
39
34
TRUE
25
39
FALSE
18
Step 6: Recall Step 11 from Lab 7.1 that determines the low value.
Declare Real lowPints
Set lowPints = pints[0]
Declare Integer index
For index = 1 to 6
If pints[index] < lowPints Then
Set lowPints = pints[index]
End If
End For
Step 7: Complete the following chart by writing what the lowPints and the pints array value stores on each iteration of the loop. Also conclude whether it will be True or False.
Pints
lowPints
True or False
39
34
FALSE
25
34
TRUE
18
25
Element
34
39
25
18
43
31
12
Index
0
1
2
3
4
5
6