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

Hello All, Thanks in advance for helping me to figure out the following: Write a

ID: 3535391 • Letter: H

Question

Hello All,

Thanks in advance for helping me to figure out the following:


Write a program that lets the user enter the total rainfall for each of 12 months (starting with January) into an array of doubles. The program should calculate and display (in this order):

the total rainfall for the year,
the average monthly rainfall,
and the months with the highest and lowest amounts.

Months should be expressed as English names for months in the Gregorian calendar, i.e.: January, February, March, April, May, June, July, August, September, October, November, December.

Input Validation: Do not accept negative numbers for monthly rainfall figures. When a negative value is entered, the program outputs "invalid data (negative rainfall) -- retry" and attempts to reread the value.

Prompts And Output Labels: Decimal values should be displayed using default precision, i.e. do not specify precision. Each item read should be prompted for by a string of the form "Enter rainfall for MONTH:" where MONTH is "January" or "February" or ... or "December". The output should be of the form:
Total rainfall: 12.36
Total rainfall: 1.03
Least rainfall in August
Most rainfall in April
where the specific amount of rainfall or specific months identified depend on the actual input.


Then, modify the program so it displays a list of months, sorted in order of rainfall, from highest to lowest.

Prompts And Output Labels. See Programming Challenge 2 in Chapter 7. In addition, the program should print for each month a line of this form: "R inches in M" where R is the inches of rainfall for month M. These lines should be in ascending order based on the value of R.

Even though I have received a possible solution, written in Java, to this problem here:


http://www.chegg.com/homework-help/questions-and-answers/question-q3983695


and I really appreciate those efforts that stack105 has put into solving this, my question was actually about the C++.


Partially, the problem has been discussed here:


http://www.chegg.com/homework-help/questions-and-answers/rainfall-statistics-write-program-lets-user-enter-total-rainfall-12-months-starting-januar-q2394221


(I also appreciate Thomas Huzij's version).


I tried to figure out how to convert the Java code into C++, and this is what I have got so far:


#include <iostream>
#include <string>
using namespace std;
int main()
{
public class RainfallStatistics
{
static void main(String argv[])
{
Scanner input=new Scanner(System.in);
double rainfall[]=new double[12];
double value;
String months[]={"January","February","March","April",
"May","June","July","August",
"September","October","Novemeber","December"};
cout << "Enter the total rainfall for each of 12 months ";
for(int i=0;i<12;i++)
{
while(true)
{
cout << "Enter rainfall for "+months[i]+" :" << endl;
value=input.nextDouble();
if(value<0.0)
cout << "invalid data (negative rainfall) -- retry";
else
{
rainfall[i]=value;
break;
}
}
}
double totalRainfall=0.0;
for(int i=0;i<12;i++)
totalRainfall+=rainfall[i];
cout << "Total rainfall for the year = " << totalRainfall << endl;
cout << "The average monthly rainfall = " << totalRainfall/12.0 << endl;
selectionSort(rainfall,months);
cout << "The months with the highest rainfall =" << months[11] << endl;
cout << "The months with the lowest rainfall =" << months[0] << endl;
for(int i=0;i<12;i++)
cout << months[i] + " : " + rainfall[i] << endl;
}
public static void selectionSort(double rainfall[],String months[])
{
double temp;
String tempStr="";
for(int i=0; i < rainfall.length-1; i++)
{
for(int j=i+1;j<rainfall.length;j++)
{
if(rainfall[i]>rainfall[j])
{
temp=rainfall[i];
rainfall[i]=rainfall[j];
rainfall[j]=temp;
tempStr=months[i];
months[i]=months[j];
months[j]=tempStr;
}
}
}
}
}


This does not compile.


Any ideas how to make this work?

Thank you.

Explanation / Answer

#include #include #include using namespace std; void tableFormat(string,string,string,string); void tableFormat(double,double,double,double); int main () { double avgRain = 0; double rainSum = 0; int count = 0; double monthlyTotals[12]; string outRainSum; double lowpoint=100000; double highpoint=0; string lowMonth; string highMonth="January"; string monthNames[] = {"January","Febuary","March","April","May","June","July","August","September","October","November","December"}; cout
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