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
Ket [755]
3 years ago
8

Assignment Ahead of an expected drought this winter, the National Weather Service would like you to write a program that records

the rainfall totals for 5 California cities and calculates a some statistics on the data. They would like to use your program in their branch offices across the state, so it needs to be able to accept rainfall data for any 5 cities, specified by the user. Using values stored in arrays, write a program that does the following: 1. Prompts the user for the names of 5 California cities. You can use any 5 cities of your choosing. Here are some to help you get started: (note that some cities have spaces in their names, this should be allowed). 2. Prompts the user in a loop) to enter rainfall totals (in inches, as a decimal number) for each of the 5 cities. Validate the input so the rainfall must be re-entered if it is less than zero or greater than 100. 3. Using 3 value-returning functions, calculate the locations with the highest and lowest rainfall and the average rainfall across the 5 cities. 4. Output the 3 calculated values with a precision of 2 digits past the decimal point.
Engineering
1 answer:
Marat540 [252]3 years ago
6 0

Answer:

#include "stdafx.h"

#include <string>

#include <iostream>

#include <iomanip> //setprecision and fixed is located in this namespace

using namespace std;

const int Max = 5;

string Cities[Max];

double CitiesRainfall[Max];

int getIndexOfLowest(double[], int);

int getIndexOfHighest(double[], int);

double getAverage(double[], int);

void Menu();

void InputCities();

void InputCitiesRainfall();

void PrintOutput();

int main()

{

  InputCities();

  InputCitiesRainfall();

  PrintOutput();

  system("pause");

  return 0;

}

void InputCities()

{

  bool loop = false;

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

  {

      string city;

      do

      {

          cout << "Please enter city #" << i + 1 << ": ";

          getline(cin, city);

          if (city == "")

          {

              cout << "City cannot be empty!" << endl;

              loop = true;

          }

          else

          {

              loop = false;

          }

      } while (loop);

      Cities[i] = city;

  }

}

void InputCitiesRainfall()

{

  bool loop = false;

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

  {

      double rainfallTotal;

      do

      {

          cout << "Please enter the rainfall total for " << Cities[i] << ": ";

          cin >> rainfallTotal;

          if (rainfallTotal<0 || rainfallTotal>100)

          {

              cout << "Rainfall must be greater than 0 or less than 100." << endl;

              loop = true;

          }

          else

          {

              loop = false;

          }

      } while (loop);

      CitiesRainfall[i] = rainfallTotal;

  }

}

int getIndexOfLowest(double arr[], int size)

{

  int index = 0;

  int lowest = arr[0];

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

  {

      if (lowest>arr[i])

      {

          lowest = arr[i];

          index = i;

      }

  }

  return index;

}

int getIndexOfHighest(double arr[], int size)

{

  int index = 0;

  int highest = arr[0];

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

  {

      if (highest < arr[i])

      {

          highest = arr[i];

          index = i;

      }

  }

  return index;

}

double getAverage(double arr[], int size)

{

  double avg, total;

  avg = total = 0;

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

  {

      total += arr[i];

  }

  avg = total / size;

  return avg;

}

void PrintOutput()

{

  int highestRainfallIndex = getIndexOfHighest(CitiesRainfall, Max);

  cout << "The city with the highest rainfall is " << Cities[highestRainfallIndex] << "." << endl;

  int lowestRainfallIndex = getIndexOfLowest(CitiesRainfall, Max);

  cout << "The city with the lowest rainfall is " << Cities[lowestRainfallIndex] << "." << endl;

  cout << "The average rainfall across all cities is " << setprecision(2) << fixed << getAverage(CitiesRainfall, Max) << " inches." << endl;

}

Explanation:

You might be interested in
Answer the following questions, and very briefly explain your answer:
alexandr1967 [171]

Answer:

A) micro defects are left behind on the surface of metal components during the manufacturing process. These defects, in the form of micro-cracks or pits, becomes initiation sites for crack propagation or corrosion. Removing these imperfections on the surface of metal parts by electroplating greatly improves the life of metal components.

B) it will reduce fatigue crack growth.

Dispersion hardening involves the inclusion of small, hard particles in the metal, thus restricting the movement of dislocations, and thereby raising the strength properties. In dispersion hardening it is assumed that the precipitates do not deform with the matrix and that a moving dislocation bypasses the obstacles (precipitates) by moving in the clean pieces of crystal between the precipitated particles.

C) stress concentrations such as changes in section with sharp corners caused yielding, which will typically occur first at a stress concentration. For ductile materials localised plastic deformation can cause a redistribution of stress, enabling the component to continue to carry load. Brittle materials will typically fail at the stress concentration. Repeated loading may cause a fatigue crack to initiate and slowly grow at a stress concentration leading to the failure of even ductile materials. Fatigue cracks always start at stress raisers, so removing such defects increases the fatigue strength.

5 0
3 years ago
Solve the compound inequality. 3x − 4 &gt; 5 or 1 − 2x ≥ 7
Kaylis [27]
X ≤ −3 or x > 3
inequality form
3 0
3 years ago
What are the important things to remember when arriving for an interview?
ludmilkaskok [199]

Answer: That you are dressed appropriately, to speak in a formal manner, and to be confident in your answers.

8 0
3 years ago
What test should be performed on abrasive wheels
Svet_ta [14]

Answer:

before wheel is put on it should be looked at for damage and a sound or ring test should be done to check for cracks, to test the wheel it should be tapped with a non metallic instrument (I looked it up)

3 0
3 years ago
Read 2 more answers
A bus travels the 100 miles between A and B at 50 mi/h and then another 100 miles between B and C at 70 mi/h.
stira [4]

Answer:

c. less than 60 mi/h

Explanation:

To calculate the average speed of the bus, we need to calculate the total distance traveled by the bus, as well as the total time of travel of the bus.

Total Distance Traveled = S = 100 mi + 100 mi

S = 200 mi

Now, for total time, we calculate the times for both speeds from A to b and then B to C, separately and add them.

Total Time = t = Time from A to B + Time from B to C

t = (100 mi)/(50 mi/h) + (100 mi)(70 mi/h)

t = 2 h + 1.43 h

t = 3.43 h

Now, the average speed of bus will be given as:

Average Speed = V = S/t

V = 200 mi/3.43 h

<u>V = 58.33 mi/h</u>

It is clear from this answer that the correct option is:

<u>c. less than 60 mi/h</u>

7 0
3 years ago
Other questions:
  • A Michelson interferometer operating at a 500 nm wavelength has a 3.73-cm-long glass cell in one arm. To begin, the air is pumpe
    9·1 answer
  • A circuit contains a 40 ohm resistor and a 60 ohms resistor connected in parallel. If you test this circuit with a DMM you shoul
    14·1 answer
  • How do batteries and other types of power sources make physical computing systems more mobile?
    15·2 answers
  • How much heat (Btu) is prod uced by a 150-W light bulb that is on for 20-hours?
    14·1 answer
  • A light pressure vessel is made of 2024-T3 aluminum alloy tubing with suitable end closures. This cylinder has a 90mm OD, a 1.65
    8·1 answer
  • A random sample of 5 hinges is selected from a steady stream of product from a punch press, and the a. b. proportion nonconformi
    12·1 answer
  • A 50 mol% mixture of propane (1) and n-butane (2) enters an isothermal flash drum at 37°C. If the flash drum is maintained at 0.
    12·1 answer
  • True or false the camshaft is always located in the engine block
    10·1 answer
  • Engineering practices include which of the following? Select all that apply.
    10·1 answer
  • Explain the importance of water quality in aquaculture business.
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!