My neighbor’s daughter has been working on a science project where she has colle
ID: 3766165 • 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 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
Code under development:
#include<stdio.h>
#include<dos.h>
#include "iostream"
#include "ctype.h"
#include "fstream"
using namespace std;
int main()
{
ifstream file("temp.txt");
int size;
file >>size;
int switchFlips = 0;
myArray = new int[size];
for (int i = 0; i < size; i++)
{
file >> myArray[i];
}
cout<<size;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.