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
|
#include <iostream>
using namespace std;
#include <math.h>
#include <fstream>
void loadData(int dayDate[], double highTemp[],double recordTemp[],
int recordTempYear[], double relativeHumidity, int&dataCount);
void displayMenu(void);
void displayData(int dayDate[], double highTemp[],double recordTemp[],
int recordTempYear[], double relativeHumidity, int dataCount);
void displayRecordTempandYear(int dayDate[], double recordTemp[],
int recordTempYear[], int dataCount);
void calculateRecordTempandYear(int magicDay, int dayDate[], double recordTemp[],
int recordTempYear[], int dataCount, double &record, int &year);
int main()
{
double highTemp[100],recordTemp[100], relativeHumidity[100];
int recordTempYear[100], dayDate[100];
int Moption,dataCount;
cout<<"Hello! We will be calculating and finding different mathematical"
" properties for the weather!"<<endl;
loadData(dayDate[],highTemp[],recordTemp[],recordTempYear[],relativeHumidity[], dataCount);
do
{
displayMenu();
cout<<"Enter option(1-7): "<<endl;
cin>>Moption;
if(Moption == 1)
{
displayData(dayDate[],highTemp[],recordTemp[],
recordTempYear[], relativeHumidity[], dataCount);
}
else if (Moption ==2)
{
displayRecordTempandYear(dayDate[], recordTemp[],
recordTempYear[],dataCount);
cout<<"Test"<<endl;
}
else if (Moption ==3)
cout<<"test"<<endl;
else if(Moption == 4)
cout<<"test"<<endl;
else if(Moption == 5)
cout<<"test"<<endl;
else if(Moption == 6)
cout<<"test"<<endl;
else if(Moption != 7)
cout<<endl<<"Please enter a number from 1 to 7"
<<endl<<endl;
}
while(Moption!=7);
return 0;
}
void loadData(int dayDate[], double highTemp[],double recordTemp[],
int recordTempYear[], double relativeHumidity, int&dataCount)
{
fstream infile;
infile.open("c:\\Documents and Settings\\Jake\\Desktop\\arraytest.txt", ios::in);
dataCount=0;
do
{
infile>>dayDate[dataCount];
infile>>highTemp[dataCount];
infile>>recordTemp[dataCount];
infile>>recordTempYear[dataCount];
infile>>relativeHumidity[dataCount];
++dataCount;
}
while(dayDate[dataCount-1] != 0);
infile.close();
--dataCount;
}
void displayMenu(void)
{
cout<<"Option 1: Display the data on a table "<<endl;
cout<<"Option 2: Display record high temperature and the"
" year it occured"<<endl;
cout<<"Option 3: Display heat index for each day "<<endl;
cout<<"Option 4: Display average, maximum, minimum, and range"
" for one field"<<endl;
cout<<"Option 5: Display largest difference between two consecutive"
" values in one field"<<endl;
cout<<"Option 6: Display chart summarizing the distribution of values"
" for one field"<<endl;
cout<<"Option 7: Quit Analyzing this set of data"<<endl;
}
void displayData(int dayDate[], double highTemp[],double recordTemp[],
int recordTempYear[], double relativeHumidity, int dataCount)
{
int ix;
for(ix=0;ix<dataCount;++ix)
{
cout<<"Date\tHighTemp\tRecordHigh\tYearOccured\tHumidity"<<endl;
cout<<dayDate[ix]<<"\t"<<highTemp[ix]<<"\t"<<recordTemp[ix]<<"\t"
<<recordTempYear[ix]<<"\t"<<relativeHumidity[ix];
}
}
void displayRecordTempandYear(int dayDate[], double recordTemp[],
int recordTempYear[], int dataCount)
{
int magicDay;
double record;
int year;
char condition,anotherDay;
do
{
condition='f';
cout<<"What day would you like to see the record temperature and"
" year for?"<<endl;
cin>>magicDay;
calculateRecordTempandYear(magicDay, dayDate[],recordTemp[],
recordTempYear[], dataCount, record, year,condition);
if(condition=='f')
{
cout<<"Sorry, data was not found"<<endl;
}
else
{
cout<<"Record Temperature: "<<record<<endl;
cout<<"Year occured: "<<year<<endl;
}
cout<<"Another day (y/n)?"<<endl;
cin>>anotherDay;
}
while(anotherDay=='y');
}
void calculateRecordTempandYear(int magicDay, int dayDate[], double recordTemp[],
int recordTempYear[], int dataCount, double &record, int &year,char condition)
{
int ix;
condition='f';
for(ix=0; ix<dataCount;++ix)
{
do
{
if(dayDate[ix]==magicDay)
{
record=recordTemp[ix];
year=recordTempYear[ix];
condition='t';
}
}
while(condition=='f');
}
}
|