Details of this Paper

Lab 9 Student

Description

solution


Question

;;Lab 9: Arrays;This lab accompanies Chapter 8 of Starting Out with Programming Logic & Design.;Name;Lab 9.1 ? Arrays and Pseudocode;Critical Review;An array allows you to store a group of items of the same data type together in memory.;A variable stores just a single value, and oftentimes can be cumbersome to work with when your program has similar values.;Values stored in an array are called elements. Each element has a subscript that makes it unique.;An array is defined as follows;Declare Integer numbers[10];Integer defines the type of numbers that can be stored, numbers is the name of the array, and [10] is how many numbers can be stored.;In most languages, the first element is assigned the subscript of 0, so the above array actually runs from 0 to 9.;Constant variables can also be used to declare the size of an array.;Constant Integer SIZE = 5;Declare Integer numbers[SIZE] = 847, 1238, 48, 123, 840;Elements in the array;847;1238;48;123;840;0;1;2;3;4;Subscript or Index starting a 0;Loops are generally used to step through an array. This can be done using any type of loop and for any process such as filling, calculating, searching, sorting, or outputting elements of the array.;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 variables;An array named pints of the data type Real of size 7;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 initialized to 0;A variable named lowPints of the data type Real initialized to 0;Module main();//Declare local variables;Declare String again = ?no?;While again == ?no?;//module calls below;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. Additionally, write a module header named getPints that accepts the pints array. (Reference: Passing an Array as an Argument to a Function, page 295).;//Module call;Call ________________(______________);//Module header;Module ___________(Real ______________[ ]);Step 3: Write a for loop that runs 7 times using the counter variable. Inside the for loop, allow the user to enter values into the array. (Reference: Using a Loop to Step Through an Array, page 273).;Declare Integer counter = 0;For __________________ = 0 to;Display ?Enter pints collected:?;Input ___________[_________];End For;Step 4: Write a function call to a module named getTotal that passes the pints array and the totalPints variable. Additionally, write a function header named getTotal that accepts the pints array and the totalPints variable.;//Function call;totalPints = ______________(______________, ___________);//Function header;Function _________(Real ______________[ ], Real __________);Step 5: Write a for loop that runs 7 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. (Reference: Totaling the Values in an Array, page 289).;Declare Integer counter = 0;Set totalPints = 0;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 averagePints variable. Additionally, write a function header named getAverage that accepts the totalPints variable and the averagePints variable.;//Function call;averagePints = ____________(______________, ___________);//Function header;Function _________(Real ______________, Real ___________);Step 7: Write a statement that will calculate the average pints donated over the drive period. Also, return the correct variable from the function. (Reference: Averaging the Values in an Array, page 290).;averagePints = ________________ /;Return;Step 8: Write a function call to a module named getHigh that passes the highPints variable and the pints array. Additionally, write a function header named getHigh that accepts the highPints variable and the pints array.;//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 variable from the function. (Reference: Finding the Highest Value in an Array, page 291).;Set highPints = pints[________];Set index = 1;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 lowPints variable and the pints array. Additionally, write a function header named getLow that accepts the lowPints variable and the pints array.;//Function call;lowPints = ____________(______________, ___________);//Function header;Function _________(Real _____________, Real ___________[ ]);Step 11: Write the code that will determine the highest value in an array. Also, return the correct variable from the function. (Reference: Finding the Lowest Value in an Array, page 293).;Set lowPints = pints[________];Set index = 1;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 9.2 ? Checking the Work;Using the program from Lab 9.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 9.1 that accumulates the pints collected.;Declare Integer counter = 0;Set totalPints = 0;For counter = 0 to 6;Set totalPints = totalPints + pints[counter];End For

 

Paper#68074 | Written in 18-Jul-2015

Price : $47
SiteLock