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
The purpose of an Internet _____ is to receive packets and send them along towards their final destination.
Bumek [7]

The tool that receives packets and send them along towards their final destination is; Internet Server

<h3>Internet Servers</h3>

We are told that the tool is used to receive packets and send them along towards their final destination.

  • Now, the tool is an internet server because internet servers are softwares and hardwares that make use of HTTP and other protocols to respond to client requests that are made over the World Wide Web.

Now, the main job of an internet server is to display website content through storing, processing and delivering webpages to the final destination.

Read more about internet server at; brainly.com/question/20602197

7 0
2 years ago
2.4 Code Practice: Question 1
USPshnik [31]

Answer:

num = float(input("Enter a number : "))

ab = abs(num)

sqrt = float(ab ** 0.5)

print(sqrt)

Explanation:

6 0
3 years ago
When one method calls another, which of the following statements are true?
jonny [76]

Answer:

I. The class methods and instance methods of one class may call the public class methods of another class using dot notation and referencing the name of the other class.

Explanation:

Private methods are being accessed from only within the class or scope specified. No other means of accessibility is possible, and even through inheritance. And instance methods can never call without using dot notation, any of the class method of the same class. Hence second and third options are not correct. And the class method and the instance methods of one class may call the public class methods of another class using the dot notation and referencing the name of the other class. Hence, the correct option is the first one.

3 0
3 years ago
Need the answer ASAP!!! I’ll mark brainliest if correct
san4es73 [151]

Answer:

update standerds

Explanation:

7 0
3 years ago
Which of the following is NOT a name of one of the central features of Facebook? Timeline Activity Log Graph Search Daily News
Thepotemich [5.8K]
I think it's Graph Search because there isn't any graphs in Facebook. That is my opinion. I don't use social media.
4 0
3 years ago
Other questions:
  • Achieving a degree in computer forensics, information technology, or even information systems can provide a strong foundation in
    11·1 answer
  • Students recently created a Gaming Club at their school. On Friday of every week, students bring in their gaming consoles (Xbox,
    10·1 answer
  • Krystal recorded her times for all her cross-country meets this season. To sort her data showing the lowest times first, what wi
    14·2 answers
  • When you are working on an unsaved document on a PC, where is the document temporarily saved?
    5·1 answer
  • FTP requires confirmation that a file was successfully transmitted to a client, but it has no built-in mechanism to track this i
    7·2 answers
  • -Convert the 1's complement 10111010 to decimal
    15·2 answers
  • Write a line of code to convert time to hours. Remember there are 60 minutes in an hour. Then write a line of code to calculate
    9·2 answers
  • I need help for my computer science class I would appreciate it
    11·1 answer
  • Gn guys have an Amazing day!
    12·2 answers
  • Assume that students in a course are required to produce a written report on an ICT-related
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!