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 165 166 167 168 169 170 171 172 173
|
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <stdio.h>
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;
};
struct SearchParams
{
int lowsiteIDNumber, highsiteIDNumber,
lowdayOfMonth, highdayOfMonth,
lowwindSpeed, highwindSpeed,
lowtemperature, hightemperature;
};
void getParams( SearchParams& params );
void displayMatch( ifstream& database, const SearchParams& params );
int main()
{
string datafile; // Name of file that contains meteorological data
SearchParams params;
measured_data_t data[MAX];
char temp[10];
measured_data_t a_measured_data;
int i;
int n;
int 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;
cout << " Enter name of file that contains meteorological data " << endl;
cin >> datafile;
ifstream inventory( datafile.c_str(), ios::in );
if (!inventory.fail())
{
getParams( params );
displayMatch( inventory, params );
inventory.close();
}
else
{
cout << " Cannot open file " << datafile << endl;
}
cout << " site ID, Day of Month, Wind speed, Temp " << endl;
for( i=0; i; )
{
cout << " %4d %3d %3d %3d " << endl;
}
// Gets the different site ID values
n=0;
diff[0]=data[0].siteIDNumber;
for ( i=0; i; )
{
if (diff[n]==data[n].siteIDNumber)
{
continue;
}
else
{
n++;
diff[n]=data[n].siteIDNumber;
}
}
// Gets the max value of temperature for all individual sites
n=0;
for( i=0; i; )
{
if (diff[n]==data[n].siteIDNumber)
{
if(max[n])
{
max[n]=data[n].temperature;
min[n]=data[n].temperature;
}
n++;
}
}
// Gets the min value of temperature for all individual sites
for( i=0; i; )
{
for(n=0;n<3;n++)
{
if(diff[n]==data[n].siteIDNumber)
{
if(min[n]>data[n].temperature)
min[n]=data[n].temperature;
}
}
}
// Gets the mean wind speed for the given site ID
for( i=0; i; )
{
for(n=0;n<3;n++)
{
if(diff[n]==data[n].siteIDNumber)
{
avg[n]=avg[n]+data[n].windSpeed;
count[n]+=1;
continue;
}
}
}
cout << " site ID, Max Temp, Min Temp, Variation, Mean Wind speed " << endl;
for(i=0;i<3;i++)
cout << diff << max << min << max-min << avg << endl;
// Calculates 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];
}
cout << " Temperature " << endl; // Prints the greatest variation in temp among sites
for(n=0;n<3;n++)
{
if((max[n]-min[n])==var)
cout << " Greatest Variation is at Site Id " << diff[n] << endl;
}
// Calculates the value of greatest variation for mean wind speed
var=0;
for(n=0;n<3;n++)
{
if((avg[n]/count[n])>var)
var=avg[n]/count[n];
}
cout << " Mean Wind Speed " << endl; // This prints out the greatest variation in mean wind speed
for(n=0;n<3;n++)
{
if((avg[n]/count[n])==var)
cout << " Greatest Variation is at Site ID " << diff[n] << endl;
}
system("pause");
return 0;
}
|