The Weather Service Bureau department has data representing


The Weather Service Bureau department has data representing monthly rainfall for a year and we would like to create a table categorizing each month as rainy (rainfall 20% higher than average) dry (rainfall 25% lower than average). or average. The data file for monthly rain fall is called rainfall.txt.

Output
The year\'s average monthly rainfall was 139 mm.
September has the highest rainfall (190 mm).
January has the lowes rainfall (95 mm)

Month Rainfall(mm) Classification
------- ----------------- ------------------
1 95 Dry
2 100 Dry
3 120 Average
4 130 Average
5 135 Average
6 145 Average
7 155 Average
8 185 Rainy
9 190 Rainy
10 160 Average
11 130 Average
12 120 Average


Program Requirements:

Implement the following functions in the program:

void inputRainfall(int rainFal l[], int size)
The function reads the monthly rainfall from the file rainFall.txt and stores them in the array rainFall

int calculateAverageRainFall(int rainFall [], int size)
Return the average monthly rainfall (rounded to the nearest millimeter).

void classifyAndDisplayRainfall(int rainFall[], int months);
Display the average monthly rainfall, the month with the highest rainfall, and the month with the lowest rainfall.
Also classify each month as average, rainy, or dry.

Hint:

Read data from a file.

#include<fstream>

void inputRainFall(float rainFall[], int size)
//Open the file
ifstream inputFile;
inputFile.open(\"rainfall.txt\");
//Initialize month counter
int month = 0; //first month
//Read the monthly rainfall in the file
inputFile >> rainFall[month];

The Weather Service Bureau department has data representing monthly rainfall for a year and we would like to create a table categorizing each month as rainy (rainfall 20% higher than average) dry (rainfall 25% lower than average). or average. The data file for monthly rain fall is called rainfall.txt.

Output
The year\'s average monthly rainfall was 139 mm.
September has the highest rainfall (190 mm).
January has the lowes rainfall (95 mm)

Month Rainfall(mm) Classification
------- ----------------- ------------------
1 95 Dry
2 100 Dry
3 120 Average
4 130 Average
5 135 Average
6 145 Average
7 155 Average
8 185 Rainy
9 190 Rainy
10 160 Average
11 130 Average
12 120 Average


Program Requirements:

Implement the following functions in the program:

void inputRainfall(int rainFal l[], int size)
The function reads the monthly rainfall from the file rainFall.txt and stores them in the array rainFall

int calculateAverageRainFall(int rainFall [], int size)
Return the average monthly rainfall (rounded to the nearest millimeter).

void classifyAndDisplayRainfall(int rainFall[], int months);
Display the average monthly rainfall, the month with the highest rainfall, and the month with the lowest rainfall.
Also classify each month as average, rainy, or dry.

Hint:

Read data from a file.

#include<fstream>

void inputRainFall(float rainFall[], int size)
//Open the file
ifstream inputFile;
inputFile.open(\"rainfall.txt\");
//Initialize month counter
int month = 0; //first month
//Read the monthly rainfall in the file
inputFile >> rainFall[month];

The Weather Service Bureau department has data representing monthly rainfall for a year and we would like to create a table categorizing each month as rainy (rainfall 20% higher than average) dry (rainfall 25% lower than average). or average. The data file for monthly rain fall is called rainfall.txt.

Output
The year\'s average monthly rainfall was 139 mm.
September has the highest rainfall (190 mm).
January has the lowes rainfall (95 mm)

Month Rainfall(mm) Classification
------- ----------------- ------------------
1 95 Dry
2 100 Dry
3 120 Average
4 130 Average
5 135 Average
6 145 Average
7 155 Average
8 185 Rainy
9 190 Rainy
10 160 Average
11 130 Average
12 120 Average


Program Requirements:

Implement the following functions in the program:

void inputRainfall(int rainFal l[], int size)
The function reads the monthly rainfall from the file rainFall.txt and stores them in the array rainFall

int calculateAverageRainFall(int rainFall [], int size)
Return the average monthly rainfall (rounded to the nearest millimeter).

void classifyAndDisplayRainfall(int rainFall[], int months);
Display the average monthly rainfall, the month with the highest rainfall, and the month with the lowest rainfall.
Also classify each month as average, rainy, or dry.

Hint:

Read data from a file.

#include<fstream>

void inputRainFall(float rainFall[], int size)
//Open the file
ifstream inputFile;
inputFile.open(\"rainfall.txt\");
//Initialize month counter
int month = 0; //first month
//Read the monthly rainfall in the file
inputFile >> rainFall[month];

Solution

I have written below code as per the question:

It is compiling with no errors but there\'s a slight modification which needs to be done, apologies that I couldn\'t complete it with required output due to time consttraint.Although, you just need to check for one or two lines to get the output which is asked.

#include <iostream>
#include <iomanip>
#include <fstream> //Required for inputFile variable.
using namespace std;


void inputRainfall(int rainFall[], int size); //Function that displays the rainfall from .txt file.

int calculateAverageRainFall(int rainFall[], int size); //Function that gets the average rainfall.


void classifyAndDisplayRainfall(int rainFall[], int months); // Display the

// average monthly rainfall, the month with the highest rainfall, and the month

// with the lowest rainfall.

//Begin main function.

int main()
{
   const int SIZE=12; //Array size.
   int rainFall[SIZE]; //Rainfall variable with size declarator.
   int sum=0;       //Sum variable.
   int avg=0;   //Average variable.
   int highest=0;   //Highest rainfall variable.
   int lowest=0;   //Lowest rainfall variable.  
   int mnthNum1=0;   //Highest month variable, used for highest rainfall
   int months=0; //Months variable.
   int mnthNum2=0;   //Highest month variable, used for highest rainfall

//Set up numeric output formatting.
        for (int i=0; i<SIZE; i++)
        if (rainFall[i]==highest)
        {
            mnthNum1 = i+1;
            break;
          
        }
        for (int i=0; i<SIZE; i++)
        if (rainFall[i]==lowest)
        {
            mnthNum2 = i+1;
            break;
        }
cout << fixed << showpoint << setprecision(2);

inputRainfall(rainFall, SIZE); //Calls getRainFall function.

avg=calculateAverageRainFall(rainFall, SIZE); //Calls calculateAverageRainFall function.
cout << \"The average rainfall for the year is \" << avg << \" inches.\ \";

classifyAndDisplayRainfall(rainFall, months);

return 0;

} //End main function.

// Begin inputRainfall function.

   void inputRainfall(int rainFall[], int month)

   {
       const int SIZE=12;
       //Open the file
       ifstream inputFile;
       inputFile.open(\"rainfall.txt\");
       //Initialize month counter
       for(month=0; month<SIZE; month++)
       //Read the monthly rainfall in the file
       inputFile >> rainFall[month];
      
   } // End inputRainfall function.


//Begin calculateAverageRainFall function.


int calculateAverageRainFall(int rainFall[], int size)
{
   const int SIZE=12;
   int sum=0;
   int avg=0;
   for(size= 0; size<=SIZE; size++)
   //Calculate sum before the average
   sum=sum+rainFall[size];
   //Calculate the average rainfall.
   avg=sum/SIZE;
   //Return the average rainfall.
   return avg;
} //End calculateAverageRainFall function.

void classifyAndDisplayRainfall(int rainFall[], int size)

/* Display the average monthly rainfall, the month with the highest rainfall, and the month with the lowest rainfall.
Also classify each month as average, rainy, or dry.*/
{
   const int SIZE=12;
   int highest=rainFall[0]; //Holds highest rainfall.
   int mnthNum1; //Month that has the highest rainfall.
   for(size=0; size<SIZE; size++)
   //Find the highest rainfall.
   if(rainFall[size]>highest)
   {
       mnthNum1=highest;
       highest=rainFall[size];
   }


// Print the highest rainfall.
cout << \"The largest amount of rainfall was \" << highest << \" inches in month \" << mnthNum1 << endl;
int lowest=rainFall[0]; //Holds the lowest rainfall.
int mnthNum2; //Month that has the lowest rainfall.
for(size=0; size<SIZE; size++)
// Find the lowest rainfall.
if(rainFall[size]<lowest)
{
   mnthNum2=lowest;
   lowest=rainFall[size];
}

cout << \"The smallest amount of rainfall was \" << lowest << \" inches in month \" << mnthNum2 << endl;

}

 The Weather Service Bureau department has data representing monthly rainfall for a year and we would like to create a table categorizing each month as rainy (r
 The Weather Service Bureau department has data representing monthly rainfall for a year and we would like to create a table categorizing each month as rainy (r
 The Weather Service Bureau department has data representing monthly rainfall for a year and we would like to create a table categorizing each month as rainy (r
 The Weather Service Bureau department has data representing monthly rainfall for a year and we would like to create a table categorizing each month as rainy (r
 The Weather Service Bureau department has data representing monthly rainfall for a year and we would like to create a table categorizing each month as rainy (r

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site