1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Nesterboy [21]
2 years ago
6

Write a program that lets the user enter the total rainfall for each of 12 months (starting with January) into an array of doubl

es. 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:
Computers and Technology
1 answer:
lianna [129]2 years ago
3 0

Answer:

The C++ code is given below with appropriate comments

Explanation:

#include "stdafx.h"

//Header file section

#include <iostream>

#include <iomanip>

#include <string>

using namespace std;

//Function prototypes

double rainfallTotal(double[], int);

double averageMonthlyRainfall(double[], int);

double highestAmountRainfall(double[], int, int &);

double lowestAmountRainfall(double[], int, int &);

int main()

{

//Initialize variables

const int ALL_MONTHS = 12;

int highIndex = 0;

int lowIndex = 0;

//Declare variables

double totalRf;

double averageRf;

double mostRf;

double leastRf;

double monthlyRf[ALL_MONTHS];

string monthName[ALL_MONTHS] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };

for (int i = 0; i < ALL_MONTHS; i++)

{

 cout << "Enter rainfall for " << monthName[i] << ": ";

 cin >> monthlyRf[i];

 // Check the input as negative numbers

 //for monthly rainfall

 while (monthlyRf[i] < 0)

 {

  cout << "Invalid data (negative rainfall) " << endl;

  cout << "Retry the rainfall in " << monthName[i] << ": ";

  cin >> monthlyRf[i];

 }

}

//Call the methods

totalRf = rainfallTotal(monthlyRf, ALL_MONTHS);

averageRf = averageMonthlyRainfall(monthlyRf, ALL_MONTHS);

mostRf = highestAmountRainfall(monthlyRf, ALL_MONTHS, highIndex);

leastRf = lowestAmountRainfall(monthlyRf, ALL_MONTHS, lowIndex);

//Display output

cout << fixed << showpoint << setprecision(2) << endl;

cout << "Total rainfall: " << totalRf << endl;

cout << "Average rainfall: " << averageRf << endl;

cout << "Least rainfall in " << monthName[lowIndex] <<endl;

cout << "Most rainfall in " << monthName[highIndex] <<endl;

system("pause");

return 0;

}

//Method definition of rainfallTotal

double rainfallTotal(double totalRainfall[], int n)

{

double total = 0;

for (int i = 0; i < n; i++)

 total += totalRainfall[i];

return total;

}

//Method definition of averageMonthlyRainfall

double averageMonthlyRainfall(double totalRainfall[], int n)

{

double average = 0.0;

double total = 0;

for (int i = 0; i < n; i++)

 total += totalRainfall[i];

average = total / n;

return average;

}

//Method definition of lowestAmountRainfall

double lowestAmountRainfall(double totalRainfall[], int n, int &monthIndex)

{

double least;

int i = 0;

least = totalRainfall[i];

while (i < n)

{

 if (totalRainfall[i] < least)

 {

  least = totalRainfall[i];

  monthIndex = i;

 }

 i++;

}

return least;

}

//Method definition of highestAmountRainfall

double highestAmountRainfall(double totalRainfall[], int n, int &monthIndex)

{

double high;

int i = 0;

high = totalRainfall[i];

while (i < n)

{

 if (totalRainfall[i] > high)

 {

  high = totalRainfall[i];

  monthIndex = i;

 }

 i++;

}

return high;

}

You might be interested in
What do you mean by flow of program​
Ahat [919]
The flow program now called Power Automate, is cloud-based software that allows employees to create and automate workflows and tasks across multiple applications and services without help from developers. I think Thts what you meant
7 0
2 years ago
Important tools used in the _____ phase of the DMAIC process include a project charter, a description of customer requirements,
Anna71 [15]
Important tools used in the "Define" phase of the DMAIC process include a project charter, a description of customer requirements, process maps, and Voice of the Customer (VOC) data.
6 0
3 years ago
The scientific process is most similar to what
Papessa [141]

Answer:

A dyagram

Explanation:

Have a nice day.

-London

8 0
2 years ago
Question 4 (2 points)
rodikova [14]

Answer:

Add the broadcast jump! code to the end of Scratch Cat's code.

Explanation:

If we broadcast the jump! code, then the Gobo will listen, and he will start jumping up and down. It looks like that he is not getting what Scratch Cat is saying, and if the message of Scratch Cat is broadcasted then Gobo will listen to what Scratch Cat is telling. Hence, the above option is the correct option.

6 0
3 years ago
Read 2 more answers
When patel’s advertising co. decided to upgrade its computer network, many people were involved in the decision. In b2b buying s
babunello [35]

In b2b buying systems, decisions are often made by by a committee after a lot of considerable deliberation.

<h3>What is Business-to-Business service?</h3>

Business-to-business is known to be a kind of a scenario where one business is said to often makes a commercial transaction with another kind of business.

The B2B decision-making process is known to be made up of some discrete tasks such as:

  • Knowing that there is an issue or need.
  • Examining  and comparing the available alternative or solutions
  • Defining the requirements that is needed for the product and others.

Hence, In b2b buying systems, decisions are often made by by a committee after a lot of considerable deliberation.

Learn more about b2b from

brainly.com/question/26506080

#SPJ1

4 0
2 years ago
Other questions:
  • A network engineer arrives at work and discovers that many users are having problems when attempting to connect to the company n
    9·2 answers
  • Two technicians are discussing the voltage measurements taken on the circuit below: V1 = 12Volts; V2 = 12Volts; V3 = 0Volts; V4
    11·1 answer
  • Technology is often discovered by accident
    5·1 answer
  • Markaplier nand jackceptieye are the best YT ever who agrees
    5·2 answers
  • Which of the following statements opens the file info.txt for both input and output? a) dataFile.open("info.txt", ios::in &amp;&
    11·2 answers
  • Which of the following images illustrates safe driving?
    8·2 answers
  • You use a Windows desktop system to edit and produce audio files. Your system has two hard disks installed. Your applications ar
    10·1 answer
  • Una laptop agarra mas internet que una computadora de escritorio?
    11·1 answer
  • ________ take advantage of vulnerabilities in software. Group of answer choices Blended threats Bots Trojan horses Direct-propag
    6·1 answer
  • What does the word collaborative mean?
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!