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

This file contains wind speed and temperature data for 30 days. The first value

ID: 3806667 • Letter: T

Question

This file contains wind speed and temperature data for 30 days. The first value on each line is the day - day 1, day 2, day 3, etc., up to day 30. The second value on the line is the wind speed in knots - 14 knots for day 1, 12 knots for day 2, etc., up to 14 knots for day 30. The third value on the line is the temperature in Celsius - 25 c for day 1, 31 c for day 2, etc., up to 22 c for day 30. Create a program to read the data in the file and use it to calculate and output the average wind speed and the average temperature. Do not store the data in arrays (or any other structure) - process it as you go.

Explanation / Answer

Here is the C++ code for you:

#include <iostream>
#include <fstream>

using namespace std;
int main()
{
    ifstream fin;
    fin.open("WindSpeedAndTemperatures.txt");
    double averageWindSpeed = 0.0, averageTemperature = 0.0;
    int day;
    double windSpeed, temperature;
    for(int i = 0; i < 30; i++)
    {
       fin >> day >> windSpeed >> temperature;
       averageWindSpeed += windSpeed;
       averageTemperature += temperature;
    }
    cout << "The average windspeed of the month is: " << averageWindSpeed << endl;
    cout << "The average temperature of the month is: " << averageTemperature << endl;
}

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