Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.92 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<iomanip>
  4.  
  5.  
  6. const int rows = 12;     //make # of rows/cols a constant int
  7. const int cols = 2;
  8.  
  9.  
  10. using namespace std;
  11.  
  12. void getData( int listTemp[rows][cols]);
  13. void averageHigh( int listTemp[rows][cols]);
  14. void averageLow(int listTemp[rows][cols]);
  15. void indexHighTemp(int listTemp[rows][cols]);
  16. void indexLowTemp( int listTemp[cols][cols]);
  17.  
  18. ifstream infile;
  19. ofstream outfile;
  20.  
  21. int main()
  22. {
  23.        
  24.    
  25.   //  ofstream outfile;
  26.     double average;
  27.     int listTemp[rows][cols];
  28.    
  29.    
  30.     infile.open("E:\\jackson_lab3input.txt"); //open infile
  31.     outfile.open("E:\\jackson_lab3output.txt");
  32.    
  33.    outfile<<fixed<<showpoint;   //set showpoint so result will be able to show decimal points
  34.    outfile<<setprecision(2);
  35.    
  36.    
  37.    
  38.     getData(listTemp);                         //call functions
  39.     averageHigh(listTemp);
  40.     averageLow(listTemp);
  41.     indexHighTemp(listTemp);
  42.     indexLowTemp(listTemp);
  43.    
  44.    
  45.      
  46.     infile.close();
  47.     outfile.close();
  48.    
  49.     system("pause");
  50.     return 0;
  51.    
  52. }
  53.  
  54.     void getData(int listTemp[rows][cols])
  55.     {                                                    //read data in both arrays
  56.    
  57.              int x;
  58.              int j;
  59.             // ifstream infile;
  60.            //  ofstream outfile;
  61.                          
  62.              
  63.              for (x=0; x < rows; x++)
  64.              {
  65.                  for( j=0; j<cols; j++)
  66.                  {
  67.                      
  68.              infile >> listTemp[x][j] >> listTemp[x][j];
  69.              
  70.            //  outfile << listTemp[x][j] << " "<<listTemp[x][j]<< endl;
  71.            
  72.                      
  73.            }
  74.            }
  75. }
  76.     void averageHigh ( int listTemp[rows][cols])
  77.     {
  78.             int x=1;         
  79.             int Sum = 0;                                //read first column and find the average
  80.             double Average;                         //from the highs       
  81.            
  82.            
  83.              for (x=0; x < rows; x++)
  84.              {
  85.              Sum = listTemp[x][0] + Sum;           
  86.             // Average = Sum/x;          
  87.              }
  88.        // Average = Sum/12;
  89.        
  90.         Average = Sum/x;
  91.        
  92.        
  93.        
  94.         outfile << "Average high for the year: " << Average << endl<<endl;
  95.        
  96.          
  97.         }
  98.        
  99.     void averageLow ( int listTemp[rows][cols])
  100.      {
  101.      int Sum = 0;                                           //read the second column and find the
  102.      double Average;       
  103.                                       //average of the lows    
  104.      
  105.              for (int x=0; x < rows; x++)
  106.              {
  107.              Sum = listTemp [x][1] + Sum;
  108.              }
  109.              //  Average = Sum/12;
  110.              
  111.              Average = Sum/12;
  112.      
  113.              outfile << "Average low for the year: " << Average << endl<<endl;
  114.      }
  115.      
  116.      
  117.        
  118.     void indexHighTemp ( int listTemp[rows][cols])
  119.      {
  120.      int highestIndex = 0;  
  121.        
  122.                                                         //find highest in the "high" column                  
  123.      for(int x = 0; x < rows; x++)
  124.      {
  125.       if(listTemp[0][x] > highestIndex)
  126.       highestIndex = listTemp[0][x];
  127.              
  128.      }
  129.      outfile << "The index high temperature is " << highestIndex <<endl<<endl;
  130.  
  131.      }
  132.      
  133.     void indexLowTemp ( int listTemp[rows][cols])
  134.      {
  135.      int lowestIndex = 0;    
  136.                               //find the lowest in the low column
  137.      
  138.      for(int x = 0; x < rows; x++)
  139.  
  140.      {
  141.           if(lowestIndex > listTemp[0][x])
  142.           lowestIndex = listTemp[0][x];
  143.              
  144.      }     
  145.      outfile << "The index low temperature is " << lowestIndex << endl<<endl;
  146.      }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement