cosc1315_l6_lab_9_1

.docx

School

Central Texas College *

*We aren’t endorsed by this school

Course

1315

Subject

Computer Science

Date

May 12, 2024

Type

docx

Pages

4

Uploaded by MinisterFalconPerson641 on coursehero.com

Lesson 6 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 0 1 2 3 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. //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. 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
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help