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

In this assignment, you will write a program that will read in a list of 12 doub

ID: 3919104 • Letter: I

Question

In this assignment, you will write a program that will read in a list of 12 doubles from a file. Each double represents the total rainfall in inches for the 12 months of the year in month order. The 12 doubles should be written into an array.
The program should do the following with the data:
? Calculate the average rainfall for the year. ? Determine which month had the lowest amount of rainfall. ? Determine which month had the highest amount of rainfall. ? Sort the array of rainfall in descending order (highest rainfall first) using a bubble sort. ? Neatly display the average, minimum, and maximum rainfall. Be sure to display the month of the minimum and maximum rainfalls. Then display a table of month and rainfall amount from the sort that you did earlier. Each of the monthly rainfall, average, minimum, and maximum rainfalls should be displayed to two decimal places.
You will not be given a sample program for this assignment. You have already done a similar program for reading in values from a file and finding averages, minimums, and maximums. The most difficult part of the assignment will be to display the correct months with the correct rainfall values after you have sorted them. I would suggest using parallel arrays for rainfall and months and every time you swap array indices for rainfall, you do the same swap for the months.
Make sure you use good programming style. This includes commenting all your variables and commenting through your code. Comments should explain why you are doing something. Use good indentation (see my examples and the books examples for demonstration of good indentation). Make sure variable names are self-documenting. Make good use of white space. Group logical sections together with one blank line between logical sections.
Your output should be neat and pleasant to read.
Make sure you follow the specifications. If you must, you can add to the program, but do not change the specifications in doing so.
Name your file PA4_lastName_firstName.cpp, replacing lastName with your actual last name and firstName with your actual first name.

Below is possible output for a sample run for this programming assignment:

Monthly Rainfall for Fort Worth, TX 2014

Minimum: September 0.06
Maximum: August 4.34
Monthly Average for Year: 1.77

Sorted by Total Rainfall

Month Inches
August 4.34
May 3.40
June 3.26
November 2.13
October 2.09
April 1.74
March 1.45
December 1.13
July 0.98
February 0.41
January 0.33
September 0.06

The program has to compile in visual studio 2017

Explanation / Answer

#include<stdio.h>

#include<conio.h>

#include<string.h>

void main()

{ int d,i=0;

double swapdouble,highestfall,lowestfall,avgfall=0;

double rainfall[12];

char monthswap[10];

char monthname[12][10]={“january”,”feburary”,”march”,”april”,”may”,”june”,”jully”,”august”,”september”,”october”,”november”,”december”};

clrscr(); // to clear the screen

FILE *fp; // stream for reading from file

/*asumming that the rainfall data is in “rainfalldata.dat” hence opening this file in “r” (read mode) only*/

if((fp=fopen(“rainfalldata.dat”,”r”))=NULL)

printf(“file does not exist “);

else

do

{ fscanf(fp,”%lf”,&(rainfall[i]));

i++;

}while(!feof(fp));

/* loop for buble sort in descending order, below */

for(i=0;i<12;i++)

{ for(d=0;d<12-i-1;d++)

{ if(rainfall[d]<rainfall[d+1])

{ /*swapping rainfall, below*/

swapdouble=rainfall[d];

rainfall[d]=rainfall[d+1];

rainfall[d+1]=swapdouble;

/* swapping month below */

strcpy(monthswap,monthname[d]);

strcpy(monthname[d],monthname[d+1]);

strcpy(monthname[d+1],monthswap);

}

}

}

/* calculating avg rainfall, below*/

for(i=0;i<12;i++)

avgfall+=rainfall[i];

avgfall=avgfall/12;

highestfall=rainfall[0];

lowestfall=rainfall[11];

printf(“ the average rainfall is : %lf the minimum rainfall is : %lf for %s the maximum rainfall is : %lf for %s”,avgfall,lowestfall,(monthname[11]),highestfall,(monthname[0]));

/* loop for displaying month and rainfall in descending order, below */

printf(“ Month Inches “);

for(i=0;i<12;i++)

printf(“%s %lf”,monthname[i],rainfall[i]);

getch();

}