Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C program that reads a csv file and find the monthly weather statistics. Requirements: - The weather file is in csv format, and

Write a C program that reads a csv file and find the monthly weather statistics.
Requirements: - The weather file is in csv format, and the first line is the header line. - The weather file contains three columns: month, day and temperature. - You find the average for each month. - Your program should check if the month is from 1 to 12 and the day is from 1 to
31.- If there are multiple rows for a specific month and a day, only use the first row for
calculations.
o Hint: you can maintain a 2D array (month x day) to keep track of which days
have already been used for calculations. - The average temperature is calculated by (total temperature)/(number of days
calculated).
o For example, if there are 10 days for January, the temperatures will be
summed and then divided by 10 to find the average temperature. - The statistics should be written in this format: csv filename.txt.
o For example, if the csv filename is weather.csv, the result will be recorded in
weather.csv.txt.
Example Interaction (user input is underlined; your program must follow this format
precisely without the underline):
$ gcc -Wall assignment5.c
$ ./a.out jan.csv
$ cat jan.csv.txt
***** Jan *****
Measured days: 20
Average temperature: 64.00
***** Total *****
Measured months: 1
Measured days: 20
Average temperature: 64.00
$ ./a.out random.csv
$ cat random.csv.txt
***** Feb *****
Measured days: 20
Average temperature: 68.72
***** Jul *****
Measured days: 20
Average temperature: 86.53
***** Total *****
Measured months: 2
Measured days: 40
Average temperature: 77.62
$ ./a.out random2.csv
$ cat random2.csv.txt
***** Aug *****
Measured days: 10
Average temperature: 87.60
***** Dec *****
Measured days: 12
Average temperature: 62.79
***** Total *****
Measured months: 2
Measured days: 22
Average temperature: 74.07
$ ./a.out weather.csv
$ cat weather.csv.txt
***** Jan *****
Measured days: 31
Average temperature: 64.65
***** Feb *****
Measured days: 28
Average temperature: 70.27
***** Mar *****
Measured days: 31
Average temperature: 72.31
***** Apr *****
Measured days: 30
Average temperature: 76.95
***** May *****
Measured days: 31
Average temperature: 79.61
***** Jun *****
Measured days: 30
Average temperature: 83.23
***** Jul *****
Measured days: 31
Average temperature: 86.48
***** Aug *****
Measured days: 31
Average temperature: 86.89
***** Sep *****
Measured days: 30
Average temperature: 83.78
***** Oct *****
Measured days: 31
Average temperature: 77.55
***** Nov *****
Measured days: 30
Average temperature: 70.43
***** Dec *****
Measured days: 31
Average temperature: 64.92
***** Total *****
Measured months: 12
Measured days: 365
Average temperature: 76.45

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine M. Ricardo

1st Edition

0763733148, 978-0763733148

More Books

Students also viewed these Databases questions

Question

2. Do you agree that unions stifle creativity? Why or why not?

Answered: 1 week ago