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
sertanlavr [38]
2 years ago
15

Write a program that lets the user enter the total rainfall for each of 12 months into a vector of doubles. The program will als

o have a vector of 12 strings to hold the names of the months. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amounts.
Computers and Technology
1 answer:
madam [21]2 years ago
3 0

Answer:

Explanation:

#include<iostream>

#include<iomanip>

#include<vector>

using namespace std;

double getAverage(const vector<double> amounts)

{

   double sum = 0.0;

   for (int i = 0; i < amounts.size(); i++)

       sum += amounts[i];

   return(sum / (double)amounts.size());

}

int getMinimum(const vector<double> amounts)

{

   double min = amounts[0];

   int minIndex = 0;

   for (int i = 0; i < amounts.size(); i++)

   {

       if (amounts[i] < min)

       {

           min = amounts[i];

           minIndex = i;

       }

   }

   return minIndex;

}

int getMaximum(const vector<double> amounts)

{

   double max = amounts[0];

   int maxIndex = 0;

   for (int i = 0; i < amounts.size(); i++)

   {

       if (amounts[i] > max)

       {

           max = amounts[i];

           maxIndex = i;

       }

   }

   return maxIndex;

}

int main()

{

   vector<string> months;

   vector<double> rainfalls;

   months.push_back("January");

   months.push_back("February");

   months.push_back("March");

   months.push_back("April");

   months.push_back("May");

   months.push_back("June");

   months.push_back("July");

   months.push_back("August");

   months.push_back("September");

   months.push_back("October");

   months.push_back("November");

   months.push_back("December");

   cout << "Input 12 rainfall amounts for each month:\n";

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

   {

       double amt;

       cin >> amt;

       rainfalls.push_back(amt);

   }

   cout << "\nMONTHLY RAINFALL AMOUNTS\n";

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

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

       cout << left << setw(11) << months[i] << right << setw(5) << rainfalls[i] << endl;

   cout << "\nAVERAGE RAINFALL FOR THE YEAR\n" << "Average: " << getAverage(rainfalls) << endl;

   int minIndex = getMinimum(rainfalls);

   int maxIndex = getMaximum(rainfalls);

   cout << "\nMONTH AND AMOUNT FOR MINIMUM RAINFALL FOR THE YEAR\n";

   cout << months[minIndex] << " " << rainfalls[minIndex] << endl;

   cout << "\nMONTH AND AMOUNT FOR MAXIMUM RAINFALL FOR THE YEAR\n";

   cout << months[maxIndex] << " " << rainfalls[maxIndex] << endl;

   return 0;

}

You might be interested in
How would you create a tint of a color?
svetlana [45]
D. white with a hue
HOPE THIS HELPS
5 0
2 years ago
True or false? malware problems and other compromises of your computer information are rare.
Marina86 [1]
I think that is false I am not 100% sure.
3 0
3 years ago
Help with what the awnser is
wariber [46]
Flute on a boot ;) hope i helped

8 0
3 years ago
What helps companies and organizations to target masses of people, provide 24/7 services, and deliver better marketing in a chea
Sever21 [200]
The money their making
6 0
3 years ago
Which of the following is the best reason to use a macro?: *
marin [14]

Answer:c)You want to automate a repetitive task to save time

Explanation: Macro is the program that is utilized when there is a requirement of a task or operation to be repeated in a automatic way.This helps in saving the time without commanding the same operation to take place manually.

This program works by taking the into and generating the preset output sequence. Other options are incorrect because it does not help in email functions, correction of the citation in documents or generation of the table.Thus, the correct option is option(c).

7 0
3 years ago
Other questions:
  • A collision between gas atoms and electrons raises the energy levels of oxygen and nitrogen in the _________.
    8·2 answers
  • What is the purpose of the .NET Framework Class Library? a. it provides pre-written code that can be used by .NET applications b
    13·1 answer
  • Write a program that does the following:
    11·1 answer
  • A ____________ would be a misconfiguration of a system that allows the hacker to gain unauthorized access, whereas a____________
    12·1 answer
  • An executable file that was determined to be infected with a virus was terminated from the running processes list. However, afte
    14·1 answer
  • Describe how catching exceptions can help with file errors. Write three Python examples that actually generate file errors on yo
    12·1 answer
  • A(n) _____ is a firm that delivers a software application, or access to an application, by charging a usage or subscription fee.
    6·1 answer
  • Write a program num2rome.cpp that converts a positive integer into the Roman number system. The Roman number system has digits I
    8·1 answer
  • What is Roko's Basilisk?
    7·1 answer
  • (10 LC)
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!