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

Create a program to store temperatures recorded over a period of time. The progr

ID: 3681257 • Letter: C

Question

Create a program to store temperatures recorded over a period of time. The program should store the temperatures in a global array variable. Assume that the maximum number of temperatures that may be stored is 500. Add the following function to your program: A function that finds the average of all temperatures stored A function that finds the average of the last 5 recorded temperatures. If there are less than 5 temperatures recorded, return the average of all recorded temperatures. A function that records a new temperature. It must check if there is still space in the array. A function that prints the number of temperatures recorded A function that prints all the temperatures recorded Organize the program so the function prototypes are presented first, and the definitions after the main function. Your program should keep asking the user to select an option from the following:

Explanation / Answer

#include <stdio.h>
#include <stdlib.h>
//to hold the temperatures
double temperatures[500];
//to hold the index of temperatures array
int size=0;

//add new temperature
void recordNewTemp(double newTemp)
{

if(size<500)
{

temperatures[size]=newTemp;
size++;
}

}
//caliculate average of all temperatures
double getAverageTempOfAll()
{
int i;
double avgTemperatures=0;
for(i=0; i<size; i++)
{
avgTemperatures+=temperatures[i];

}
avgTemperatures=avgTemperatures/(double)(i);
return avgTemperatures;

}
//caliculate average of last 5 temperatures
double getAverageTempOfFive()
{
int i;
double avgTemperatures=0;
int minSize=0;
if(size>5)
{
minSize=size-5;

}
else
{
minSize=0;
}

for(i=minSize; i<size; i++)
{
avgTemperatures+=temperatures[i];


}
avgTemperatures=avgTemperatures/(double)i;
return avgTemperatures;

}
//return number of temperatures recorded
int getNoOfTempsRecorded()
{
return size;
}
//print the temperatures recorded
void printTemps()
{
printf(" ***Temperatures*** ");
int i;
for(i=0; i<size; i++)
{
printf("%d. %.2f ",(i+1),temperatures[i]);

}
}
int main()
{
char choice;
double temperature;
do
{
printf(" (A) computed average of all temperatures, (B) computed average of all last five (C) add a new temperatures (D) print the number of temperatures recorded (E) print the temperatures recorded (F) exit the program ");

printf(" Enter your Choice:");
scanf(" %c", &choice);

switch (choice)
{
case 'A':
printf(" Average Of All Temperature :%f ",getAverageTempOfAll());
break;
case 'B':
printf(" Average Of Last 5 Temperature %f ",getAverageTempOfFive());
break;
case 'C':
printf(" Entet the new Temperature:");
scanf("%lf",&temperature);
recordNewTemp(temperature);
break;
case 'D':
printf(" Number of temperatures recorded :%d",getNoOfTempsRecorded());
break;
case 'E':
printTemps();
break;
case 'F':
exit(0);
default:
printf(" Invalid Choice");
break;
}

}
while(1);

return 0;
}

OUTPUT:


(A) computed average of all temperatures,
(B) computed average of all last five
(C) add a new temperatures
(D) print the number of temperatures recorded
(E) print the temperatures recorded
(F) exit the program

Enter your Choice:C

Entet the new Temperature:34.66

(A) computed average of all temperatures,
(B) computed average of all last five
(C) add a new temperatures
(D) print the number of temperatures recorded
(E) print the temperatures recorded
(F) exit the program

Enter your Choice:C

Entet the new Temperature:35.32

(A) computed average of all temperatures,
(B) computed average of all last five
(C) add a new temperatures
(D) print the number of temperatures recorded
(E) print the temperatures recorded
(F) exit the program

Enter your Choice:C

Entet the new Temperature:34.21

(A) computed average of all temperatures,
(B) computed average of all last five
(C) add a new temperatures
(D) print the number of temperatures recorded
(E) print the temperatures recorded
(F) exit the program

Enter your Choice:D

Number of temperatures recorded :3
(A) computed average of all temperatures,
(B) computed average of all last five
(C) add a new temperatures
(D) print the number of temperatures recorded
(E) print the temperatures recorded
(F) exit the program

Enter your Choice:E

***Temperatures***
1. 34.66
2. 35.32
3. 34.21

(A) computed average of all temperatures,
(B) computed average of all last five
(C) add a new temperatures
(D) print the number of temperatures recorded
(E) print the temperatures recorded
(F) exit the program

Enter your Choice:C

Entet the new Temperature:32.54

(A) computed average of all temperatures,
(B) computed average of all last five
(C) add a new temperatures
(D) print the number of temperatures recorded
(E) print the temperatures recorded
(F) exit the program

Enter your Choice:A

Average Of All Temperature :34.182500

(A) computed average of all temperatures,
(B) computed average of all last five
(C) add a new temperatures
(D) print the number of temperatures recorded
(E) print the temperatures recorded
(F) exit the program

Enter your Choice:B

Average Of Last 5 Temperature 34.182500

(A) computed average of all temperatures,
(B) computed average of all last five
(C) add a new temperatures
(D) print the number of temperatures recorded
(E) print the temperatures recorded
(F) exit the program

Enter your Choice:C

Entet the new Temperature:43.54

(A) computed average of all temperatures,
(B) computed average of all last five
(C) add a new temperatures
(D) print the number of temperatures recorded
(E) print the temperatures recorded
(F) exit the program

Enter your Choice:C

Entet the new Temperature:34.22

(A) computed average of all temperatures,
(B) computed average of all last five
(C) add a new temperatures
(D) print the number of temperatures recorded
(E) print the temperatures recorded
(F) exit the program

Enter your Choice:C

Entet the new Temperature:56.32

(A) computed average of all temperatures,
(B) computed average of all last five
(C) add a new temperatures
(D) print the number of temperatures recorded
(E) print the temperatures recorded
(F) exit the program

Enter your Choice:E

***Temperatures***
1. 34.66
2. 35.32
3. 34.21
4. 32.54
5. 43.54
6. 34.22
7. 56.32

(A) computed average of all temperatures,
(B) computed average of all last five
(C) add a new temperatures
(D) print the number of temperatures recorded
(E) print the temperatures recorded
(F) exit the program

Enter your Choice:D

Number of temperatures recorded :7
(A) computed average of all temperatures,
(B) computed average of all last five
(C) add a new temperatures
(D) print the number of temperatures recorded
(E) print the temperatures recorded
(F) exit the program

Enter your Choice:A

Average Of All Temperature :38.687143

(A) computed average of all temperatures,
(B) computed average of all last five
(C) add a new temperatures
(D) print the number of temperatures recorded
(E) print the temperatures recorded
(F) exit the program

Enter your Choice:B

Average Of Last 5 Temperature 28.690000

(A) computed average of all temperatures,
(B) computed average of all last five
(C) add a new temperatures
(D) print the number of temperatures recorded
(E) print the temperatures recorded
(F) exit the program

Enter your Choice:F

Process returned 0 (0x0) execution time : 228.602 s
Press any key to continue.

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