Question

In: Computer Science

This lab examines the various ways of working with arrays by writing pseudocode. Read the following...

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:

  • A global named constant MAX_HOURS with a value 7
  • A local array named pints of the data type Real of size MAX_HOURS
  • A local variable named averagePints of the data type Real
  • A local variable named highPints of the data type Real
  • A local variable named lowPints of the data type Real

// 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 _______)

Solutions

Expert Solution

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! */


Related Solutions

a.     What are the various ways that the American working class coped with the stagnation of real...
a.     What are the various ways that the American working class coped with the stagnation of real wages during the 1970's - 2007? b.     What were the various ways that the American business community responded to the growth in productivity during the 1970's - 2007?
Before working this pre-lab exercise read the theory, experimental precedures and sample calculations outlined in the...
Before working this pre-lab exercise read the theory, experimental precedures and sample calculations outlined in the laboratory manual. Suppose that a student collects the following spectrophotometric data to determine the relative concentrations of HMR and MR in solution: The abosorbance at 425 nm was measured to be 0.310 and at 520 nm was 0.770, the slopes corresponding to standard Beer's Law plots were as follows: αIA = 0.072 αIB = 0.306 αIIA = 0.760 αIIB = 0.036 Using this data,...
write pseudocode for the following problems using if while conditions A student buys various books at...
write pseudocode for the following problems using if while conditions A student buys various books at the start of the semester from a bookshop. Write pseudocode for a program which takes the total amount spent on books and the total number of books as input and outputs the average cost per book. Write pseudocode for a program which takes a year as input (e.g. 2014) and determines whether or not it is a leap year. A leap year is a...
c++ //Tic tac toe lab. Topics: 2D arrays, classes. // Part 1 //Implement the following specifications...
c++ //Tic tac toe lab. Topics: 2D arrays, classes. // Part 1 //Implement the following specifications for a tic tac toe game object: class tictactoeGame { public: char boardConfig[3][3]; // two dimensional array stores current board configuration // Constructor: // set boardConfig[i][j] to be ' ' (the space character) // for 0<= i <= 2, 0<= j <= 2 tictactoeGame() { //fill this in } //put an 'X' character at the given location bool placeX(int x, int y) { //fill...
c++ //Tic tac toe lab. Topics: 2D arrays, classes. // Part 1 //Implement the following specifications...
c++ //Tic tac toe lab. Topics: 2D arrays, classes. // Part 1 //Implement the following specifications for a tic tac toe game object: class tictactoeGame { public: char boardConfig[3][3]; // two dimensional array stores current board configuration // Constructor: // set boardConfig[i][j] to be ' ' (the space character) // for 0<= i <= 2, 0<= j <= 2 tictactoeGame() { //fill this in } //put an 'X' character at the given location bool placeX(int x, int y) { //fill...
You will be writing a 5-paragraph essay on one of the following topics: o Working remotely...
You will be writing a 5-paragraph essay on one of the following topics: o Working remotely and its effects on business o The Short and Long-term effects of Covid-19 on business and commerce o The future of work and jobs Your essay must include a clear thesis statement. Your essay must be accompanied by a detailed outline. Write between 1000-1500 words
Read the following sentence taken from an adapted sample of a student's writing. I have highlighted...
Read the following sentence taken from an adapted sample of a student's writing. I have highlighted the errors, in the spaces A - J write down what each error is and how to correct it. Generally, when TheA COVID-19 spread betweenBthe world there are muchC positive things which will change in the supply chain in the world, for example, the worker will ↓D focusing carefullyE when they deliver the goods with full safety equipment ,F another positive thing is that...
Aristotle and Kant - then read the following question completely before you begin writing your reply:...
Aristotle and Kant - then read the following question completely before you begin writing your reply: You have been on vacation in Bali with your wife and 18-year-old son. You’re now at the airport ready to return home. The three of you are getting ready to board your plane when an armed officer approaches with a drug-sniffing dog. You have all the suitcases with you and your wife - and the dog sniffs at your bag and then your wife’s...
Lab Instructions Class Activity: Read the following scenarios below, then decide based on the situation whether...
Lab Instructions Class Activity: Read the following scenarios below, then decide based on the situation whether each instance is a ROBBERY, BURGLARY, THEFT (petty or grand) or NOT ANY OF THESE CRIMES. Use your textbook and the internet to research and determine what charges if any may be filed. 1. A man borrows his neighbors’ car with permission. While he has the car out he accidentally locks the keys in the car. Being in a hurry, while trying to get...
Lab Activity 4: Identifying APA Style in Journals For this activity, please read the following question...
Lab Activity 4: Identifying APA Style in Journals For this activity, please read the following question that are answer at the bottom and answer the following questions at the top. ( Note: At the bottom there already answer there that you can use to help you out with solving the answer) Lee, K., Talwar, V., McCarthy, A., Ross, I., Evans, A., & Arruda, C. (2014). Can classic moral stories promote honesty in children? Psychological Science, 25, 1630-1636. 1. After reading...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT