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:
starting out with c++ early objects 7th ed. chapter 8 programming challenges #7
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 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 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...