Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This lab examines the various ways of working with arrays by uriting pseudocode.

ID: 3601924 • Letter: T

Question

This lab examines the various ways of working with arrays by uriting pseudocode. Read the following programming problem prior to completing the lab. The American Red Cros rants will calculate the average pints of blood donated during a blood drive The pints donated during the driver based on a aven hour drive period. The should be calculated and displayed. Additionallyr the highest and the loweat nunber of pints donated should be determined and displayed. Write loop around the program to run multiple times you to rrite a program that program should take in the number of average pints donated dur ing that period Step 1: Declare the following variables: An array named pints of the data type Real of size7 . A variable named totalPints of the data type Real · A variable named average Pint ofthe 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 3tring again F "no While again = "no //module ca11 below Display "Do you vant to run again: yes or no" Input again End Thile 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 pint: array. Reference: Passing an Arayas an Argument to a Function, page 308) /Module call Call /Module header Module

Explanation / Answer

#include <stdio.h>
#include<string.h> // used for function 'strcmp'

//step 2 - module header
void getPints(double pints[]);

//step 4 - function header
double getTotal(double numPints[], double totalPints);

//step 6 - function header
double getAverage(double totalPints, double averagePints);

//step 8 - function header
double getHigh(double highPints, double pints[]);

//step 10 - function header
double getLow(double lowPints, double pints[]);

//step 12 - module header
void displayInfo(double averagePints, double highPints, double lowPints);

int main(void)
{
//step 1 begins here
double pints[7];
int totalPints=0;
double averagePints=0;
double highPints=0, lowPints=0;
char again[]="yes"; // store maximum of 'yes'(3 chars) or 'no'(2 chars)

do{

// reset the totalPints for next iteration
totalPints = 0;

//step 2 - module call
getPints(pints);

//step 4 - function call
totalPints = getTotal(pints, totalPints);

//step 6 - function call
averagePints = getAverage(totalPints, averagePints);

//step 8 - function call
highPints = getHigh(highPints, pints);

//step 10 - function call
lowPints = getLow(lowPints, pints);

//step 12 - module call
displayInfo(averagePints, highPints, lowPints);

printf("Do you want to run again: yes or no ");
scanf("%s",again);

}while(strcmp(again,"no"));

//step 1 - ends here
return 0;
}

void getPints(double pints[])
{
//step 3 - begins here
int counter = 0;
for(counter = 0; counter < 7; counter++) {
printf("Enter pints collected: ");
scanf("%lf",&pints[counter]);

}
//step 3 - ends here
}

double getTotal(double pints[], double totalPints)
{
// step 5 - begins here
int counter = 0;
for(counter = 0; counter < 7; counter++) {
totalPints = totalPints + pints[counter];
}
return totalPints;
// step 5 - ends here

}

double getAverage(double totalPints, double averagePints)
{
// step 7 - begines here
averagePints = totalPints / 7;

return averagePints;
// step 7 - ends here
}

double getHigh(double highPints, double pints[])
{
// step 9 - begins here
int index;
highPints = pints[0];
for(index = 1; index <= 6; index++) {
if (pints[index] > highPints) {
highPints = pints[index];
}
}
return highPints;
// step 9 - ends here
}

double getLow(double lowPints, double pints[])
{
//step 11 - begins here
int index;
lowPints = pints[0];
for(index = 1; index <= 6; index++) {
if (pints[index] < lowPints) {
lowPints = pints[index];
}
}
return lowPints;
//step 11 - ends here
}

// step 12 - module description
void displayInfo(double averagePints, double highPints, double lowPints)
{
//Print upto 2 after decimal points
printf("Average Pints: %.2lf ", averagePints);
printf("High Pints: %.2lf ", highPints);
printf("Low Pints: %.2lf ", lowPints);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote