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
Double bar graphs compare multiple what
GalinKa [24]
You would multiply by 2
7 0
3 years ago
Select the correct answer. Trackers are associated with which audio format?
KonstantinChe [14]
MP3 and FMsynthesid
7 0
3 years ago
Meenakshi has created a presentation of six slides. The slides have the same background, but s wants to change the background of
sdas [7]
Ans:- Using Background Styles button present in Background group on the Design tab.
5 0
2 years ago
within the data set hrd.temp, payrate is a numeric variable and hours is a character variable. what happens when the following p
Fantom [35]
  • SAS converts the PayRate value to a numeric value form; a message is written in the form of a log

  • SAS can be defined a comprehensive statistical software that provides a wide variety of analytical capabilities, data management, and visualization options

   

  • Compare between SAS and Python

Python is a high-level programming language, more object-oriented, and is known by all programmers.

In addition, python also includes a modern programming language.

Python is a programming language that has evolved from previous programming languages.

But in terms of learning, SAS is a programming language that is easier to follow compared to python.

These are the advantages and disadvantages of each programming language

Learn more about programming language here brainly.com/question/23959041

#SPJ1

6 0
1 year ago
write (define) a public static method named countup, that takes one int argument and returns no value. you can safely assume tha
tester [92]

Using the knowledge of computational language in python it is possible to write a code that write (define) a public static method named countup, that takes one int argument and returns no value.

<h3>Writting the code:</h3>

<em>public class </em><em>Main</em>

<em>{</em>

<em>public static void main(</em><em>String</em><em>[] args) {</em>

<em>// testing the method </em><em>countDown </em><em>with values 5, 6, 1</em>

<em>countDown(5);</em>

<em>System.out.println();</em>

<em>countDown(6);</em>

<em>System.out.println();</em>

<em>countDown(2);</em>

<em>System.out.println();</em>

<em>}</em>

<em />

<em>public static void </em><em>countDown</em><em>(int num)</em>

<em>{</em>

<em>for (int i=1 ; i<=num ; i++) // for </em><em>loop </em><em>iterates from 1 to num</em>

<em>{</em>

<em>System.out.print(i+","); // prints num followed by comma ,</em>

<em>}</em>

<em>}</em>

<em>}</em>

See more about JAVA at brainly.com/question/12975450

#SPJ1

7 0
1 year ago
Other questions:
  • HELP PLEASE
    7·2 answers
  • How can i save a word 2016 document as a word 2016 document?
    6·1 answer
  • The code segment below uses the procedure IsPartOf (list, item), which returns true if item appears in list and returns false ot
    13·1 answer
  • What is a binary message
    12·2 answers
  • Match the terms with their definitions.
    5·2 answers
  • The main advantage of a solid state drive is:
    5·1 answer
  • How do you write the slope-intercept form?
    5·1 answer
  • B. List any four major drawbacks of the first generation computer​
    10·1 answer
  • Pleaseeeeeeee tellllllllllllllllllllll​
    8·1 answer
  • Which website offers guidance on putting together a checklist to provide guidance on configuring and hardening operating systems
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!