Question

starting out with c++ early objects 7th ed. chapter 8 programming challenges #7

Rainfall Statistics
Write a modular program that analyzes a year's worth of rainfall data. In addition to main, the program should have a getData function that accepts the total rainfallfor each of 12 months from the user, and stores it in a double array. It should also have four value-returning functions that compute and return to main thetotalRainfall, averageRainfall, driestRainfall, and wettestMonth. These last two functions return the number of the month with the lowest and highest rainfall amounts,not the amount of rain that fell those months. Notice that this month number can be used to obtain the amount of rain that fell those months. This information shouldbe used either by main or by a displayReport function called by main to print a summary rainfall report similiar to the following:

2010 Rain Report for Neversnows County

Total rainfall : 23.19 inches
Average monthly rainfall : 1.93 inches
The least rain fell in January with 0.24 inches.
The most rain fell in April with 4.29 inches.

Input validation: Do not accept rainfall amounts less than 0.


please make sure, the program includes all of the details, all functions asked for and do what is asked and a report as the one above is printed in the window and alsomake sure the program runs with no errors.
1 0
Add a comment Improve this question Transcribed image text
Answer #1
Does the program compile? If so, does it produce the output you expected? Does it have all of the functions it is required to have? If sample data isprovided, does the program produce the expected output for a given set of inputs? These are all questions you should ask yourself when you want to know ifyour assignment is "done".

I would think that driestMonth and wettestMonth would both return ints instead of doubles. Also, your avgRainfall function is wrong. You should use atemporary variable to store the sum of the rainfall, and that variable should be of type double. The average should also be of type double, and is found bydividing the sum of all the rainfall by 12.

There may be other problems that I failed to notice (I'm a bit tired, sorry)
answered by: Polly
Add a comment
Answer #2

Dear user,
Here is the c++ code below;

//Header file section
#include<iostream>
using namespace std;

//Start main
int main()
{
//Declare variables
const int N_MONTHS = 12;
int rain;
int values[N_MONTHS];
const int STRING_SIZE=15;
double total = 0;
double avg;
int largest,lmonth;
int smallest,smonth,count;
//Array with the names of the months
char p_months[N_MONTHS][STRING_SIZE] = { "January",
"February", "March",
"April","May","June", "July",
"August", "September", "October",
"November", "December" };
for ( int month = 1; month <= N_MONTHS; month++ )
{
//Get monthly total rainfall from user
cout<<"Enter the total rainfall for "<<p_months[month-1]<<":";
cin >>rain;
//input validation
if ( rain < 0 )
{
cout << "You enter negative number.try again" << endl;
cout << "Please reenter: ";
cin >> rain;
}
values[month-1]=rain;
total += rain;
} //Get the monthly rainfalls
cout << "nTotal rainfall: " << total <<" inches" << endl;
// Calculate the average amount of rainfall
avg = total / (double)N_MONTHS;
cout << "Average monthly rainfall: "<< avg << "inches"<< endl;
for ( int month = 1; month <= N_MONTHS; month++ )
{
largest = values[0];
//logic to find largest
for ( count = 1; count < N_MONTHS; count++ )
{
if ( values[count] > largest )
{
largest = values[count];
lmonth=count;
}
}


smallest = values[0];
//logic to find smallest
for ( count = 1; count < N_MONTHS; count++ )
{
if ( values[count] < smallest )
{
smallest = values[count];
smonth=count;
}

}
}

// Disply the highest and lowest rainfall
cout << "The most rain fell in " << p_months[lmonth]<< endl;

cout << "The least rain fell in " <<p_months[smonth]<< endl;

//pause system for a while
system("pause");
return 0;
}

//end main
-------------------------------------------------------------
Output:

uploaded image

answered by: taylour
Add a comment
Know the answer?
Add Answer to:
starting out with c++ early objects 7th ed. chapter 8 programming challenges #7
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • qbasic is the programming language Chapter 8 Do Programming Exercise 8-3 om page 414. Create a...

    qbasic is the programming language Chapter 8 Do Programming Exercise 8-3 om page 414. Create a string array to hold the months of the year. Call it anything you want to just make sure it's a string array is at the end of the name, e.g. months). Create a DATA statement that holds the month names: DATA "jan","Feb", "Mar" etc. Next you'll need a FOR loop to READ the DATA into the array, Call a SUB to get the rainfall...

  • [C++] Using Files—Total and Average Rainfall Write a program that reads in from a file a...

    [C++] Using Files—Total and Average Rainfall Write a program that reads in from a file a starting month name, an ending month name, and then the monthly rainfall for each month during that period. As it does this, it should sum the rainfall amounts and then report the total rainfall and average rainfall for the period. For example, the output might look like this: During the months of March–June the total rainfall was 7.32 inches and the average monthly rainfall...

  • How can we assess whether a project is a success or a failure? This case presents...

    How can we assess whether a project is a success or a failure? This case presents two phases of a large business transformation project involving the implementation of an ERP system with the aim of creating an integrated company. The case illustrates some of the challenges associated with integration. It also presents the obstacles facing companies that undertake projects involving large information technology projects. Bombardier and Its Environment Joseph-Armand Bombardier was 15 years old when he built his first snowmobile...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT