In: Computer Science
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:
// Declare global named constant below
____________________________________
Module main()
//Declare local variables
Declare String again = “yes”
____________________________________
____________________________________
____________________________________
____________________________________
While again == “yes”
// module calls below to be completed
// in the next few steps
Display “Do you want to run again (yes or no)? ”
Input again
End While
End Module
Step 2: Write a module call to a module named getPints that passes the pints array and the number of hours. Additionally, write a module header named getPints that accepts the pints array and number of hours.
//Module call
Call ______________(______________, MAX_HOURS)
//Module header
Module __________(Real __________[ ] , Integer hours)
Step 3: Write a for loop inside module getPints that runs specified times using the counter variable and the two parameters. Inside the for loop, allow the user to enter values into the array.
Declare Integer counter = 0
For __________________ = 0 to hours - 1
Display “Enter pints collected:”
Input ___________[_________]
End For
Step 4: Write a function call to a module named getAverage that passes the pints array and the number of hours. Additionally, write a function header named getAverage that accepts the pints array and the hours variable.
//Function call
Set averagePints = _____________(_____________, MAX_HOURS)
//Function header
Function _________(Real ______________[ ], Integer hours)
Step 5: Write a for loop inside function getAverage that runs hours times using the counter variable. Inside the for loop, total up the values of the array and store in the variable totalPints. Also, return the correct variable from the function.
Declare Integer counter
Declare Real totalPints = 0
Declare Real averagePints
For __________________ = 0 to _______________
Set _________ = ________ + ______________[________]
End For
Set averagePints = ________________ / _________________
Return _________________
Step 6: Write a function call to a module named getHigh that passes the pints array and the number of hours. Additionally, write a function header named getHigh that accepts the pints array and the hours variable.
//Function call
Set highPints = ____________(______________, ___________)
//Function header
Function ______ _______( Real ________[ ], Integer _____)
Step 7: Write the code that will determine the highest value in an array. Also, return the correct variable from the function.
Declare Integer index
Declare Real highest = pints[________]
For index = 1 to _____________
If _______________[_______] > highest Then
Set ____________ = __________[_______]
End If
End For
Return ______________________
Step 8: Write a function call to a module named getLow that passes the pints array and the number of hours. Additionally, write a function header named getLow that accepts the pints array and the hours variable.
//Function call
Set lowPints = ____________(______________, ___________)
//Function header
Function ______ _______( Real ________[ ], Integer _____)
Step 9: Write the code that will determine the lowest value in an array. Also, return the correct variable from the function. This function is very similar to getHigh function.
_______________________________________________________
_______________________________________________________
_______________________________________________________
_______________________________________________________
_______________________________________________________
_______________________________________________________
Step 10: 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. Although pseudocode for this module is not required, but feel free to set it up.
//Module call
Call displayInfo(______________, ___________, ___________)
//Module header
Module ________(Real ________, Real ________, Real _______)
Ans:
/*
The above program which is required to be developed is to be specified in an abstract psuedo-code format, filling the blanks being given in various steps:
*/
Step 1 (ans.)
Declare Const MAX_HOURS = 7
Module main()
Declare String again = "yes"
Declare Real pints[MAX_HOURS]
Declare Real averagePints
Declare Real highPints
Declare Real lowPoints
While again == “yes”
// module calls below to be
completed
// in the next few
steps
Display “Do you want to run again (yes or
no)? ”
Input again
End While
End Module
Step 2:
//Module call
Call getPints(Real pints[], MAX_HOURS)
//Module header
Module getPints(Real pints[ ] , Integer hours)
Step 3 :
Declare Integer counter = 0
For counter = 0 to hours - 1
Display “Enter pints collected:”
Input pints[counter]
End For
Step 4:
//Function call
Set averagePints = getAverage(Real pints[], MAX_HOURS)
//Function header
Function getAverage(Real pints[ ], Integer hours)
Step 5:
//Function call
Set averagePints = getAverage(Real pints[], MAX_HOURS)
//Function header
Function getAverage(Real pints[ ], Integer hours)
Step 6:
//Function call
Set highPints = getHigh(Real pints[], MAX_HOURS)
//Function header
Function getHigh( Real pints[ ], Integer hours)
Step 7 :
Declare Integer index
Declare Real highest = pints[0]
For index = 1 to hours
If pints[index] > highest Then
Set highest = pints[index]
End If
End For
Return highest
Step 8:
//Function call
Set lowPints = getLow(Real pints[], MAX_HOURS)
//Function header
Function getLow( Real pints[ ], Integer hours)
Step 9:
Declare Integer index
Declare Real lowest = pints[0]
For index = 1 to hours
If pints[index] < lowest Then
Set lowest = pints[index]
End If
End For
Return lowest
Step 10:
//Module call
Call displayInfo(Real averagePints, Real highPints, Real lowPints)
//Module header
Module displayInfo(Real averagePints, Real highPints, Real lowPints)
/*
The above functions and modules in the steps contains all the required completed psuedo-code at all the blanks which were given in the question. All the bold highlighted parts are the answers
*/
/* Please do like and upvote if this was helpful! */
/* Thank you so much in advance! */