//I need help trying to find a way to make all my variables local and also allowing the user to type in name of the data file for reading. Also do a simple search to retrieve the weather information for a single query date
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
//Globals
string year, year2, year3, year4;
string avgMinTmp,avgMinTmp2,avgMinTmp3,avgMinTmp4;
string avgMaxTmp,avgMaxTmp2,avgMaxTmp3,avgMaxTmp4;
string totalRainfall,totalRainfall2,totalRainfall3,totalRainfall4;
string reportedWeather,reportedWeather2,reportedWeather3,reportedWeather4;
string daysReported,daysReported2,daysReported3,daysReported4;
//Function Prototypes
void SaveDataFile();
void LoadDataFile();
void OverallStats();
void SearchByDate();
void MonthlyStats();
void Quit();
//------------------------------------------------------------------------------------------------------------------------
int main(int argc, char** argv)
{
char CHOICE[25];
cout << "\n\t Welcome to my Weather stat generator\n";
while(CHOICE[0] !='Q')
{
cout << "\n\t-------------------Main Menue---------------------";
cout << "\n\t| |";
cout << "\n\t| (L)oad data file |";
cout << "\n\t| (O)verall stats |";
cout << "\n\t| (F)earch by date |";
cout << "\n\t| (M)ontly stats |";
cout << "\n\t| (Q)uit |";
cout << "\n\t| |";
cout << "\n\t| Enter a Capital Letter to make a selction |";
cout << "\n\t-------------------Main Menue---------------------";
cin >> CHOICE;
switch(CHOICE[0])
{
case 'S' : SaveDataFile(); break;
case 'L' : LoadDataFile(); break;
case 'O' : OverallStats(); break;
case 'F' : SearchByDate(); break;
case 'M' : MonthlyStats(); break;
case 'Q' : Quit(); break;
default : "\n\tInvalid input!";
}
}
system("PAUSE");
return 0;
}
//---------------------------------there is a option to save the data but not shown to us---------------------------------
void SaveDataFile()
{
try
{
ofstream DATAFILE;
DATAFILE.open("DATA1.FILE",ios::out);
DATAFILE << " 2012 " << "\n";
DATAFILE << " 11" << "\n";
DATAFILE << " 19" << "\n";
DATAFILE << " 230 mm" << "\n";
DATAFILE << " Snow" << "\n";
DATAFILE << " 140" << "\n";
DATAFILE << " 2013 " << "\n";
DATAFILE << " 12" << "\n";
DATAFILE << " 20" << "\n";
DATAFILE << " 300 mm" << "\n";
DATAFILE << " Rain" << "\n";
DATAFILE << " 160" << "\n";
DATAFILE << " 2014 " << "\n";
DATAFILE << " 15" << "\n";
DATAFILE << " 23" << "\n";
DATAFILE << " 102 mm" << "\n";
DATAFILE << " Clear" << "\n";
DATAFILE << " 260" << "\n";
DATAFILE << " 2015 " << "\n";
DATAFILE << " 16" << "\n";
DATAFILE << " 25" << "\n";
DATAFILE << " 332 mm" << "\n";
DATAFILE << " hail" << "\n";
DATAFILE << " 30" << "\n";
DATAFILE.close();
cout << "\n\tSuccess! Data was saved to file.";
}
catch (exception X)
{ cout << "\n\tFile Error! Could not Save Data.";}
}
//------------------------------------------------------------------------------------------------------------------------
void LoadDataFile()
{
try
{
ifstream DATAFILE;
DATAFILE.open("DATA1.FILE",ios::in);
getline(DATAFILE,year);
getline(DATAFILE,avgMinTmp);
getline(DATAFILE,avgMaxTmp);
getline(DATAFILE,totalRainfall);
getline(DATAFILE,reportedWeather);
getline(DATAFILE,daysReported);
getline(DATAFILE,year2);
getline(DATAFILE,avgMinTmp2);
getline(DATAFILE,avgMaxTmp);
getline(DATAFILE,totalRainfall2);
getline(DATAFILE,reportedWeather2);
getline(DATAFILE,daysReported2);
getline(DATAFILE,year3);
getline(DATAFILE,avgMinTmp3);
getline(DATAFILE,avgMaxTmp3);
getline(DATAFILE,totalRainfall3);
getline(DATAFILE,reportedWeather3);
getline(DATAFILE,daysReported3);
getline(DATAFILE,year4);
getline(DATAFILE,avgMinTmp4);
getline(DATAFILE,avgMaxTmp4);
getline(DATAFILE,totalRainfall4);
getline(DATAFILE,reportedWeather4);
getline(DATAFILE,daysReported4);
DATAFILE.close();
cout << "\n\tSuccess! Data was loaded.";
}
catch (exception X)
{ cout << "\n\tFile Error! Unable to Load dat.";}
}
//------------------------------------------------------------------------------------------------------------------------
void OverallStats()
{
system("CLS");
cout << "\n\n\t------------------Weather Data--------------------------";
cout << "\n\tYear:" << year;
cout << "\n\tAverage Min Tempature:" << avgMinTmp;
cout << "\n\tAverage Max Tempature:" << avgMaxTmp;
cout << "\n\tTotal Rain Fall:" << totalRainfall;
cout << "\n\tWeather Type:" << reportedWeather;
cout << "\n\tDays Reported:" << daysReported;
cout << "\n\n\t--------------------------------------------------------";
cout << "\n\n\t------------------Weather Data--------------------------";
cout << "\n\tYear:" << year2;
cout << "\n\tAverage Min Tempature:" << avgMinTmp2;
cout << "\n\tAverage Max Tempature:" << avgMaxTmp2;
cout << "\n\tTotal Rain Fall:" << totalRainfall2;
cout << "\n\tWeather Type:" << reportedWeather2;
cout << "\n\tDays Reported:" << daysReported2;
cout << "\n\n\t--------------------------------------------------------";
cout << "\n\n\t------------------Weather Data--------------------------";
cout << "\n\tYear:" << year3;
cout << "\n\tAverage Min Tempature:" << avgMinTmp3;
cout << "\n\tAverage Max Tempature:" << avgMaxTmp3;
cout << "\n\tTotal Rain Fall:" << totalRainfall3;
cout << "\n\tWeather Type:" << reportedWeather3;
cout << "\n\tDays Reported:" << daysReported3;
cout << "\n\n\t--------------------------------------------------------";
cout << "\n\n\t------------------Weather Data--------------------------";
cout << "\n\tYear:" << year4;
cout << "\n\tAverage Min Tempature:" << avgMinTmp4;
cout << "\n\tAverage Max Tempature:" << avgMaxTmp4;
cout << "\n\tTotal Rain Fall:" << totalRainfall4;
cout << "\n\tWeather Type:" << reportedWeather4;
cout << "\n\tDays Reported:" << daysReported4;
cout << "\n\n\t--------------------------------------------------------";
}
//------------------------------------------------------------------------------------------------------------------------
void SearchByDate()
{
cout << "\n\tEnter a Year: ";
cin.ignore();
getline(cin, year);
}
//------------------------------------------------------------------------------------------------------------------------
void MonthlyStats()
{
}
//------------------------------------------------------------------------------------------------------------------------
void Quit()
{
}
//------------------------------------------------------------------------------------------------------------------------
//End of main