Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Program 3. Rainfall Statistics (20 points) Write a program that reads from a

ID: 3688081 • Letter: C

Question

C++ Program

3. Rainfall Statistics (20 points) Write a program that reads from a manually created file "Rainfall.txt" (You can manually create this file first and fill it with any twelve double values written one below the other so that reading them through code becomes easy) the total rainfall for each of 12 months into an array of doubles. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amounts Create an array of strings nameMonth in main() that holds the twelve month names: "January", "February",.,"December" Create a function fillArray() that takes another parallel twelve element array rainMonth as its argument and reads a file named "Rainfall.txt" to fill this array with double values. This function is called from main) Create a function display() that takes the array rainMonth from main() and prints o Rainfall for each month(display values with a in-between) o Total rainfall for the year o Average monthly rainfall (two digits after decimal point) Create a function min_max() that takes the arrays nameMonth and rainMonth as arguments from main() and displays the months with the Highest and Lowest amounts. Do NOT use STL vector in your program

Explanation / Answer

#include<iostream>
#include<stdlib>
#include<fstream>

using namespace std;

double * fillArray(double rainMonth[])
{
   int i=0;
   ifstream in("Rainfall.txt");

   while(in)
   {
       in>>rainMonth[i];
       i++;
   }
   return rainMonth;
}

void display(double rainMonth[])
{
   double av,sum=0,i;
   cout<<"Rainfall for each month:";
   for(i=0;i<12,i++)
   {
       cout<<rainMonth[i]<<"; ";
       sum=sum+rainMonth[i];
   }
   av=sum/12;

   cout<<"Total rainfall:"<<sum<<endl;
   cout<<"Average monthly rainfall:"<<av;
}

void min_max(double rainMonth[])
{
   double min=rainMonth[0],max=rainMonth[0];
   int i,ind,ind1;

   for(i=0;i<12;i++)
   {
       if(rainMonth[i]<min)
       {
           min=rainMonth[i];
           ind=i;
       }

       if(rainMonth[i]>min)
       {
           max=rainMonth[i];
           ind1=i;
       }
   }
   cout<<"Highest Rainfall recorded is"<<max<<"inches"<<endl;
   cout<<"Lowest Rainfall recorded is"<<min<<"inches";
}
void main()
{
   string nameMonth[]={"January","February","March","April","May","June","July","August","September","Octomber","November","December"};

   double rainMonth[12];

   double rainMonth=fillArray(rainMonth);
   display(rainMonth);
   min_max(rainMonth);
   system("pause");
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote