This is a C program. Please avoid using break or for. Thank you. Exercise 2 (55
ID: 3740699 • Letter: T
Question
This is a C program.
Please avoid using break or for. Thank you.
Exercise 2 (55 points): Write a program that gets the temperature readings recorded six times a day for a week from the user. The program will display a table showing all the temperatures, the average of readings taken at the same time each day, the high and low temperature for cach day, and the maximum arnd minimum temperature for the period inclucding the day and time the maximum and minimum were recorded. Store the input temperatures in an array defined as follows with READINGS#defined to have the value 6 and DAYS tdefined to have the value7 double teaparzay [ADIGS IDAYE) Break your program down into meaningful functions. I want to practice passing arrays to functions In addition to main, you must have the folowing functions: A function called geTempReadings that gets the temperatures recorded for each day of the week and stores them in the double array that is its first argument. The second argument is the number of readings taken for each day which is also the number of elements in the first dimension of the input array. The prototype for this function is: A function called findAvgReading that finds and returns the mcan of a one dimensional array of doubles. The array of doubles is its first argument and the number of elements in the array is its second argument. The prototype for this function is: deuble findkvgReading Ieeast double teapBeadings size t aurDays): Hint The name of a two dimensional array followed by the subscript in the first dimension is the address of a one-dimensional array that coresponds to a row of the two-dimensional array. For example tempArra is the address of the second row af fempArray delined above. (This one dimensional array contains the readings taken at 4 AM for each day of the week. Likewise dayNamesN] is the address of the one dimensional array containing the null terminated string Monday in the array dayNames defined below. This is because multi-dimensional arrays are stored linearly in memory. For a two-dimensional array, row after row. You may should have other functions, but yau must have these. (ln my solution I have six called functions.) You may find it useful to have a constant array like the following and maybe others. Note: Since it is a constant array it can be defined globally.): Saturday Hint: Rather than having to enter forty-two temperatures when you are initially testing your function you might use an initialzed array for testing. double t?pArray[READINGS ] [DAXS? 4168, 69.8' ST . 22, 55.4, 46.4. ST.2, 62.2) · 62.6, 9., 41, .46.4, 1 B, 64.. 64.4,66.24, 62.6, 50, 57.2, 66.2, 71-61, 169.8, 69.8, 66.2. 59, 8. 75.2, 82.94) 71.6, 2.,0.B. 55-4. 64.4, 71.*. 80.61 Sample Output 1: ridNy aturdsy the rintsxon berperoture for the period 5 41.0 A sanple so you can get the idea of what the input should be like. The use entered the values in blue. Sample Output 2: Enter the tarperature fer Sunday at 12 AM: 44.3 Int.ar tha tnpnratuse" for Sunday at ? AM : 30. 1 Enter the terperature for Sunday12 PN: 526 Entor the torperature tor undsy ER PM: 30.8 Enter the tenperature for Honday at 12 AM: 56.2 Inter tha tarparatur or Handay12 PM: 61- Rnter the tperature for Handayat PM: 62.9 Enter the tenperature for Honday at 8 PM: 5.6 Enter the tarperatur er Tueaday at 12 AM: 58 The table produced for this and the remainder of the input is shown below Sample Output 3 onday Toesdsy Wednesdsy ursdsy Pridaystuday 7.90Explanation / Answer
If you have any doubts, please give me comment
#include <stdio.h>
#define READINGS 6
#define DAYS 7
const char daynames[DAYS][10] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
const char timings[READINGS][10] = {"12 AM", "4 AM", "8 PM", "12 PM", "4 PM", "8 PM"};
void getTempReadings(double arrayOfTemps[][DAYS], size_t numReadings)
{
int i, j;
for (i = 0; i < numReadings; i++)
{
for (j = 0; j < DAYS; j++)
{
printf("Enter the temperature for %s at %s: ", daynames[i], timings[j]);
scanf("%lf", &arrayOfTemps[i][j]);
}
}
}
double findAvgReading(const double getTempReadings[], size_t numDays)
{
int i = 0;
double avg;
for (i = 0; i < numDays; i++)
{
avg += getTempReadings[i];
}
avg /= numDays;
return avg;
}
int main()
{
double tempArray[READINGS][DAYS];
double avgs[READINGS] = {0.0}, HI[READINGS], LO[READINGS];
int i, j;
getTempReadings(tempArray, READINGS);
for(i=0; i<READINGS; i++){
LO[i] = tempArray[i][0];
HI[i] = tempArray[i][0];
}
int min_day = 0, min_timing = 0, max_day = 0, max_timing =0;
double min_temp = tempArray[0][0], max_temp = tempArray[0][0];
for (i = 0; i < READINGS; i++)
{
for (j = 0; j < DAYS; j++)
{
if (tempArray[i][j] < LO[j])
LO[j] = tempArray[i][j];
if (tempArray[i][j] > HI[j])
HI[j] = tempArray[i][j];
if (tempArray[i][j] < min_temp)
{
min_temp = tempArray[i][j];
min_day = j;
min_timing = i;
}
if (tempArray[i][j] > max_temp)
{
max_temp = tempArray[i][j];
max_day = j;
max_timing = i;
}
}
avgs[i] = findAvgReading(tempArray[i], DAYS);
}
printf(" %10c", ' ');
for (i = 0; i < DAYS; i++)
{
printf("%10s", daynames[i]);
}
printf("%15s ", "Average");
for (i = 0; i < READINGS; i++)
{
printf("%10s", timings[i]);
for (j = 0; j < DAYS; j++)
{
printf("%10.2lf", tempArray[i][j]);
}
printf("%15.2f ", avgs[i]);
}
printf(" %10s", "HI");
for (i = 0; i < DAYS; i++)
{
printf("%10.2lf", HI[i]);
}
printf(" %10s", "LO");
for (i = 0; i < DAYS; i++)
{
printf("%10.2lf", LO[i]);
}
printf(" The maximum temperature for the period was %.2lf ", max_temp);
printf("The maximum temperature occupied on %s at %s ", daynames[max_day], timings[max_timing]);
printf("The minimum temperature for the period was %.2lf ", min_temp);
printf("The minimum temperature occupied on %s at %s ", daynames[min_day], timings[min_timing]);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.