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
|
#include<iostream>
#include<fstream>
#include<cstdlib>
#include<cmath>
#include<string>
using namespace std;
const int NUMBER_OF_MONTHS = 12;
void calculate_historical(int number_of_years);
void calculate_current(int number_of_years);
void get_total_average(double,double,string);
void graph();
void print_asterisks(double data_for_months, int numAsterisks);
void change_Value(double data_for_months, int number_of_years,double newvalue);
void reload_file();
double Totals[12];
double num1;
double newvalue;
string climphen;
int number_of_years(0);
double data_for_months(0);
string months[] = {"January","February","March","April","May","June","July","August","September","October","November","December"};
ifstream readWeather;
int main ()
{
readWeather.open("weatherdata.txt");
if (readWeather.fail())
{
cout << "Im Sorry, there was an error when attempting to open file. \n";
exit (1);
}
string climphen;
int number_of_years(0);
int data_for_months(0);
readWeather>>climphen;
readWeather>>number_of_years;
readWeather>>data_for_months;
cout<<"This program displays and calculates the historical and current data for the amount of ";
cout<<climphen<<" for "<<number_of_years<<" years.\r\n"<<"\n";
calculate_historical(number_of_years);
calculate_current(data_for_months);
// get_total_average(Totals[12] , data_for_months, climphen);
change_Value(data_for_months,number_of_years,newvalue);
readWeather.close();
return 0;
}
/******************************************/
void calculate_historical(int number_of_years)
{
double Totals[12];
double num1;
for (int i=1; i<=12;i++)
Totals[i]=0;
for (int i=0;i<number_of_years -1;i++)
{
for (int j=0;j<12;j++)
{
readWeather>>num1;
cout << months[j]<<", Historical average = ";
int numAsterisks = (int)(num1*10);
for (int j=0; j<numAsterisks; j++)
{
cout <<"*";
}
cout<<endl;
}
}
}
void calculate_current(int data_for_months)
{
double Totals[12];
double num2;
for (int i=1; i<=12;i++)
Totals[i]=0;
for (int j=0;j<12;j++)
{
readWeather>>num2;
cout << months[j]<<", Current average = ";
int numAsterisks = (int)(num2*10);
for (int j=0; j<numAsterisks; j++)
{
cout <<"=";
}
cout<<endl;
}
}
/* void get_total_average(double Totals, double data_for_months, string climphen)
{
for (int i=0;i<number_of_years -1;i++)
{
for (int j=0;j<12;j++)
{
readWeather>>num1;
cout<<"\n The total average of the Historical data for "<< climphen <<" is\n";
cout<<"\n The total average of the Current data for "<< climphen <<" is \n";
}
*/
void change_Value(double data_for_months, int number_of_years, double newvalue)
{
cout<<"Which value would you like to change?\r\n";
cout<<"If you do not wish to change any values, please select Q for Quit \r\n";
cout<<"Plese enter the value you would like to change\n";
cin>>data_for_months;
cout<<"What is the new value?\r\n";
cin>>newvalue;
if (data_for_months == 'Q' || 'q')
{
cout<<"Thank you, Have a Great Day\n";
exit(1);
}
}
//void reload_file()
|