Advertisement
KeeganT

Ass76

Oct 25th, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.04 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. string text;
  8. float precipitation[1000][1000];
  9. string citys[]{"London","Kingston","Northbay","Dryden"};
  10. string months[]{"January","February","March","April","May","June"};
  11. int rows=0;
  12.  
  13. void display()
  14. {
  15.     ifstream lineCount("precipitation.txt");
  16.     while(getline(lineCount,text))rows++;
  17.     lineCount.close();
  18.     ifstream file("precipitation.txt");
  19.     for(int c=0;c<rows;c++)file>>precipitation[c][0]>>precipitation[c][1]>>precipitation[c][2]>>precipitation[c][3];
  20.     cout<<right<<setw(53)<<"Precipitation (cm)"<<endl;
  21.     cout<<left<<setw(16)<<"Month"<<setw(16)<<citys[0]<<setw(16)<<citys[1]<<setw(16)<<citys[2]<<citys[3]<<endl;
  22.     for(int c=0;c<6;c++)cout<<left<<setw(16)<<months[c]<<setw(16)<<precipitation[c][0]<<setw(16)<<precipitation[c][1]<<setw(16)<<precipitation[c][2]<<precipitation[c][3]<<endl;
  23.     file.close();
  24.     cout<<endl;
  25. }
  26.  
  27. int main()
  28. {
  29.     display();
  30.     float total=0, average=0;
  31.     for(int c=0;c<6;c++)total+=precipitation[c][2];
  32.     average=total/6;
  33.     cout<<"The average monthly precipitation for Northbay is: "<<average<<endl;
  34.     total=0, average=0;
  35.     for(int c=0;c<4;c++)total+=precipitation[3][c];
  36.     average=total/4;
  37.     cout<<"The average precipitation for April is: "<<average<<endl;
  38.     total=0;
  39.     for(int c=0;c<6;c++)
  40.     {
  41.         for(int x=0;x<4;x++)total+=precipitation[c][x];
  42.     }
  43.     cout<<"The total average for all areas for the first six months is: "<<total<<endl;
  44.     float high=0, temp=0;
  45.     int city=0;
  46.     for(int c=0;c<4;c++)if(precipitation[5][c]>high)
  47.     {
  48.         high=precipitation[5][c];
  49.         city=c;
  50.     }
  51.     cout<<"The city with the largest precipitation in the month of June is: "<<citys[city]<<" ("<<high<<")"<<endl;
  52.     float low=9999;
  53.     int month=0;
  54.     for(int c=0;c<6;c++)if(precipitation[c][0]<low)
  55.     {
  56.         low=precipitation[c][0];
  57.         month=c;
  58.     }
  59.     cout<<"The month with the smallest precipitation in London is: "<<months[month]<<" ("<<low<<")"<<endl;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement