1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
const int MAX_ID = 3345; // Maximum siteIDNumber
const int MAX_WINDSPEED = 22; // Maximum windSpeed
const int MAX_DAY = 16; // Maximum dayOfMonth
const int MAX_TEMP = 30; // Maximum temperature
const int MAX = 10; // Max array size
struct measured_data_t
{
int siteIDNumber, dayOfMonth,
windSpeed, temperature;
};
int main()
{
measured_data_t data[MAX];
char temp[10];
measured_data_t a_measured_data;
int i,n,var;
int max[3]={0,0,0},min[3],diff[3],avg[3]={0,0,0},count[3]={0,0,0};
n = 0;
cout << " Weather and Climate Research Data " << endl;
cout << " Temp variation & average wind speed " << endl;
FILE *infilep; /* file pointer */
infilep = fopen(" C:\Users\David\Desktop\data.txt ", "r"); /* open file in read mode */
if (infilep == NULL)
{
cout << " Cannot Open File - Check File Name " << endl;
}
for (i=0;i<8;i++) /* To just skip the first line */
{
fscanf(infilep,"%s",&temp);
}
for ( i=0; i; )
{
fscanf(infilep, "%4d %3d %3d %3d",&a_measured_data.siteIDNumber,&a_measured_data.dayOfMonth,&a_measured_data.windSpeed,&a_measured_data.temperature);
data[n]=a_measured_data;
n++;
}
fclose(infilep);
cout << " site ID, Day of Month, Wind speed, Temp " << endl;
for( i=0; i; )
{
cout << " %4d %3d %3d %3d " << endl;
}
cout << " \n\n " << endl;
/* To get the different ID Values */
n=0;
diff[0]=data[0].siteIDNumber;
for ( i=0; i; )
{
if (diff[n]==data.siteIDNumber)
{
continue;
}
else
{
n++;
diff[n]=data.siteIDNumber;
}
}
/* To get the Maximum value of temperature for all individual ID */
n=0;
for( i=0; i; )
{
if (diff[n]==data.siteIDNumber)
{
if(max[n])
{
max[n]=data.temperature;
min[n]=data.temperature; //We are setting min value of temperature to maximum value so that it can further be decreased
}
n++;
}
}
/* To get the Minimum value of temperature for all individual ID */
for( i=0; i; )
{
for(n=0;n<3;n++)
{
if(diff[n]==data.siteIDNumber)
{
if(min[n]>data.temperature)
min[n]=data.temperature;
}
}
}
/* to Get the Average windfall for the given ID */
for( i=0; i; )
{
for(n=0;n<3;n++)
{
if(diff[n]==data.siteIDNumber)
{
avg[n]=avg[n]+data.wind_speed;
count[n]+=1;
continue;
}
}
}
/* Display Calculated data */
cout << " site ID, Max Temp, Min Temp, Variation, Mean Wind speed " << endl;
for(i=0;i<3;i++)
cout << " %d\t%d\t%d\t%d\t%d\n " << diff << max << min << max-min << avg << endl;
/* To calculate the value of greatest variation in temperature*/
var=0;
for(n=0;n<3;n++)
{
if((max[n]-min[n])>var)
var=max[n]-min[n];
}
/* Print Greatest Variation in temperature*/
cout << " Temperature " << endl;
for(n=0;n<3;n++)
{
if((max[n]-min[n])==var)
cout << " Greatest Variation is at Site Id " << diff[n] << endl;
}
/* To calculate the value of greatest variation for average wind speed*/
var=0;
for(n=0;n<3;n++)
{
if((avg[n]/count[n])>var)
var=avg[n]/count[n];
}
/* Print Greatest variation in average wind speed */
cout << " Average Wind Speed " << endl;
for(n=0;n<3;n++)
{
if((avg[n]/count[n])==var)
cout << " Greatest Variation is at Site ID " << diff[n] << endl;
}
}
|