0% found this document useful (0 votes)
6 views14 pages

Miniproject

The Weather Data Analyzer project, developed in C, processes and analyzes weather data such as temperature, humidity, and wind speed. It calculates statistical parameters, identifies trends, and allows users to filter data and visualize results. The program is designed for scalability and maintainability, serving as a practical tool for meteorologists and researchers.

Uploaded by

Rohan Kumar Hota
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views14 pages

Miniproject

The Weather Data Analyzer project, developed in C, processes and analyzes weather data such as temperature, humidity, and wind speed. It calculates statistical parameters, identifies trends, and allows users to filter data and visualize results. The program is designed for scalability and maintainability, serving as a practical tool for meteorologists and researchers.

Uploaded by

Rohan Kumar Hota
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

PROJECT TITLE:

WEATHER
DATA ANALYZER
STUDENT NAME: ROHAN KUMAR

REGISTER NUMBER: 2117240030117


STUDENT NAME:RESHWANTH S B
REGISTER NUMBER: 2117240030116
STUDENT NAME: ROHITH H
REGISTER NUMBER: 2117240030118

Abstract: Weather Data Analyzer in C

This project involves the development of a Weather Data Analyzer using


the C programming language. The program is designed to process,
analyze, and visualize weather-related data efficiently. It reads raw
weather data from files or user input, including temperature, humidity,
wind speed, and precipitation. The analyzer provides functionalities such
as calculating statistical parameters (average, maximum, minimum),
identifying trends, and detecting anomalies in the data. Additionally, the
program offers user-friendly features like data filtering based on time
periods or weather parameters, graphical representations of trends (using
ASCII art), and customizable data export options.
The Weather Data Analyzer is designed with modular programming
practices, ensuring scalability and maintainability. It demonstrates the
application of essential C programming concepts such as file handling,
data structures, dynamic memory allocation, and algorithm optimization.
This tool can serve as a practical resource for meteorologists,
researchers, or enthusiasts interested in understanding weather patterns
and making data-driven decisions.

Introduction

Weather plays a crucial role in daily life, influencing various activities.


Analyzing weather data helps us identify patterns and make informed
decisions. This project aims to create a C program that reads temperature
data from a file, calculates average, maximum, and minimum
temperatures, and provides insights like the number of days exceeding a
user-defined threshold.

Algorithm

1. Start.

2. Create a text file named weather_data.txt containing temperature


data (one value per line).
3. Open the file in read mode.

4. Initialize variables:

Sum = 0

Max = very_small_value

Min = very_large_value

Count = 0.

5. Read each temperature value from the file:

Add the value to sum.

Update max if the value is greater than the current max.


Update min if the value is smaller than the current min.

Increment count.

6. Close the file.

7. Calculate the average as sum / count.

8. Display the average, maximum, and minimum temperatures.

9. Prompt the user to enter a threshold temperature.

10. Count and display the number of days with temperatures


exceeding the threshold.

11. Handle errors for missing files or invalid data.


12. End.

Flowchart

| Start |

|
V

| Open file for reading|

|
V

| Initialize variables |

|
V
| Read temperatures |

| Update sum, max, min |

|
V

| Calculate average |

| Display results |
| Average, Max, Min |

|
V

| User enters threshold |

|
V

| Count days exceeding |


| threshold |

|
V

| Display count |

|
V

| End |

C Code

Save the following code as weather_analyzer.c:

#include <stdio.h>
#include <stdlib.h>

// Function prototypes
Void analyzeWeatherData(const char *filename, float *average, float
*max, float *min, int *count);
Int countAboveThreshold(float temperatures[], int size, float threshold);

Int main() {
Const char *filename = “weather_data.txt”; // Input file name
Float average = 0, max = 0, min = 0;
Int count = 0;

Printf(“Weather Data Analyzer\n”);


Printf(“---------------------\n”);

// Analyze weather data


analyzeWeatherData(filename, &average, &max, &min, &count);

if (count == 0) {
printf(“No valid data found in the file.\n”);
return 1;
}

// Display results
Printf(“\nResults:\n”);
Printf(“Average Temperature: %.2f\n”, average);
Printf(“Maximum Temperature: %.2f\n”, max);
Printf(“Minimum Temperature: %.2f\n”, min);

// User-defined threshold
Float threshold;
Printf(“\nEnter a temperature threshold: “);
Scanf(“%f”, &threshold);

// Threshold analysis
Float temperatures[count];
Int daysAboveThreshold = countAboveThreshold(temperatures, count,
threshold);
Printf(“Number of days above %.2f: %d\n”, threshold,
daysAboveThreshold);

Return 0;
}

Void analyzeWeatherData(const char *filename, float *average, float


*max, float *min, int *count) {
FILE *file = fopen(filename, “r”);
If (file == NULL) {
Printf(“Error: Could not open file ‘%s’.\n”, filename);
Exit(EXIT_FAILURE);
}

Float temp, sum = 0;


*max = -1e6; // Initialize to a very small value
*min = 1e6; // Initialize to a very large value
*count = 0;

While (fscanf(file, “%f”, &temp) == 1) {

Sum += temp;
If (temp > *max) {
*max = temp;
}
If (temp < *min) {
*min = temp;

}
(*count)++;
}

If (*count > 0) {

*average = sum / (*count);


}

Fclose(file);
}

Int countAboveThreshold(float temperatures[], int size, float threshold) {


Int count = 0;
For (int I = 0; I < size; i++) {
If (temperatures[i] > threshold) {
Count++;
}

}
Return count;
}

How to Run

1. Create the Input File:

Create a text file named weather_data.txt in the same directory as the


program.

Add temperature values (one per line). Example:

25.5
30.0

28.7
22.1
27.3
2. Compile the Program:

Gcc -o weather_analyzer weather_analyzer.c

3. Run the Program:

./weather_analyzer

Example Output

For the input file:

25.5
30.0
28.7
22.1
27.3

The output will be:

Weather Data Analyzer

Results:
Average Temperature: 26.72

Maximum Temperature: 30.00


Minimum Temperature: 22.10

Enter a temperature threshold: 25


Number of days above 25.00: 3

Conclusion

This project demonstrates how weather data can be processed and


analyzed using file handling and basic statistical calculations in C. It
provides users with insights into temperature patterns and helps in
decision-making, showcasing the utility of programming in solving real-
world problems.

You might also like