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

My neighbor’s daughter has been working on a science project where she has colle

ID: 3766393 • Letter: M

Question

My neighbor’s daughter has been working on a science project where she has collected the high temperature for each day of an entire month. Now she needs to display information regarding heat waves by highlighting those days that might be considered part of a heat wave. You are to write a program to help.

All of the data has been stored in a text file. Because there are several months of data, your program will read the file name using command line arguments.

The information is stored as follows:

• The first line of the file contains the name of the month that the data was collected.

• The remaining lines will contain one value per line which represents the high temperature for that day.

• All values are integers.

You are to write a C or C++ program. The first step is to read in the month name and determines the number of days in the month the data was collected. You must use a separate function for this procedure and the function header must be,

int numDaysInMonth(char[] month)

Next, read in the temperatures. Calculate and print the average temperature (two decimal places) for the month. You must use a separate function for this procedure and the function header must be,

void averageTemp(float* avg, int *arr, int len)

where avg is a pointer that is the address of the a float variable; arr is a pointer to the array of temperatures; and len is the number of elements in the array, arr.

For each day of the month, print the day number and the temperature that was read from the original file. For every day that is in part of a set of 3 or more consecutive days above the average, display a “+” beside the temperature. Numbers should line up so that the ones digits are all in the same column. Your program must use at least one array. See the sample output below.

Output for the sample file:

The average temperature for August was 91.97

1 85

2 87

3 92 +

4 95 +

5 97 +

6 98 +

7 90

8 84

9 87

10 93 +

11 95 +

12 96 +

13 96 +

14 94 +

15 90

16 91

17 93 +

18 96 +

19 94 +

20 95 +

21 96 +

22 94 +

23 95 +

24 89

25 89

26 89

27 87

28 97

29 88

30 87

Using the MinGW (Windows) or gcc (Apple/Unix), make sure that the program will compile and run.

Explanation / Answer

The following input data file means that the data was collected for 2 months over 15 days in January and

20 days in february

January
15
1 90
2 94
3 95
5 99
6 95
7 90
9 77
10 99
11 90
12 91
13 92
14 93
15 93
29 95
30 90
February
20
1 90
2 99
3 96
4 79
5 90
6 90
7 87
8 86
9 95
10 90
11 96
12 90
13 96
14 95
15 99
16 97
17 90
18 91
19 92
20 92

#include <iostream.h>   // input output stream header file
#include <fstream.h>
#include <stdio.h>   // standard input output header file
#include <stdlib.h>     // standard library header file
//#include <string.h>   // header file with string function
#include <conio.h>   // console input output header file
int main()   // start main
{
char *str, *monNm;
FILE *fp1;
//ifstream
fp1 = fopen("E:/Files/temp1.txt", "r");
   while ( 1 ) {
       fscanf(fp, "%s", monNm);
       cout << monNm << endl;
       if ( feof(fp1)) break;
   } // end while
fclose(fp1);

return 0; // exit
} // end of main()

#include <iostream.h>   // input output stream header file
#include <fstream.h>
#include <stdio.h>   // standard input output header file
#include <stdlib.h>     // standard library header file
//#include <string.h>   // header file with string function
#include <conio.h>   // console input output header file
int main()   // start main
{
char *str, *monNm;
FILE *fp1;
int dayCount = 0;
float tempAray[35];
int i; float temp; int numOfDays;
//ifstream
fp1 = fopen("E:/Files/temp1.txt", "r");
   while ( 1 ) {
       fscanf(fp1, "%s", monNm);
       cout << monNm << endl;
       fscanf(fp1, "%d", numOfDays);
       for (i= 1; i<= numOfDays; i++) {
           fscanf(fp1, "%f", temp);
           if ( temp > 91.97) dayCount ++;
           tempAray[i] = temp;
           cout << tempAray[i] ;
           if (dayCount >= 3) cout << "+" ;
           cout << endl;
       }
       if ( feof(fp1)) break;
   } // end while
//for (i = 1; i <= numOfDays; i++)

fclose(fp1);


return 0; // exit
} // end of main()

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