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
The Torricelli's theorem states that the (velocity—pressure-density) of liquid flowing out of an orifice is proportional to the
Sergeeva-Olga [200]

Answer:

The correct answer is 'velocity'of liquid flowing out of an orifice is proportional to the square root of the 'height'  of liquid above the center of the orifice.

Explanation:

Torricelli's theorem states that

v_{exit}=\sqrt{2gh}

where

v_{exit} is the velocity with which the fluid leaves orifice

h is the head under which the flow occurs.

Thus we can compare the given options to arrive at the correct answer

Velocity is proportional to square root of head under which the flow occurs.

4 0
3 years ago
To revise a monthly budget, changes in which categories might need to be addressed? Check all that apply.
GREYUIT [131]

Income

amount budgeted

expenses

5 0
2 years ago
An aircraft component is fabricated from an aluminum alloy that has a plane strain fracture toughness of 40MPa. It has been dete
Nataly [62]

Answer:

Yes, fracture will occur

Explanation:

Half length of internal crack will be 4mm/2=2mm=0.002m

To find the dimensionless parameter, we use critical stress crack propagation equation

\sigma_c=\frac {K}{Y \sqrt {a\pi}} and making Y the subject

Y=\frac {K}{\sigma_c \sqrt {a\pi}}

Where Y is the dimensionless parameter, a is half length of crack, K is plane strain fracture toughness, \sigma_c  is critical stress required for initiating crack propagation. Substituting the figures given in question we obtain

Y=\frac {K}{\sigma_c \sqrt {a\pi}}= \frac {40}{300\sqrt {(0.002*\pi)}}=1.682

When the maximum internal crack length is 6mm, half the length of internal crack is 6mm/2=3mm=0.003m

\sigma_c=\frac {K}{Y \sqrt {a\pi}}  and making K the subject

K=\sigma_c Y \sqrt {a\pi}  and substituting 260 MPa for \sigma_c  while a is taken as 0.003m and Y is already known

K=260*1.682*\sqrt {0.003*\pi}=42.455 Mpa

Therefore, fracture toughness at critical stress when maximum internal crack is 6mm is 42.455 Mpa and since it’s greater than 40 Mpa, fracture occurs to the material

6 0
3 years ago
1. Two technicians are discussing tire rotation. Technician A says that you always follow the tire-rotation procedure outlined i
siniylev [52]

Answer:

don't know

Explanation:

huhuh

8 0
3 years ago
Which of the following uses pressure and flow to transmit power from one location to another?
lord [1]

Answer:

fluid power

Explanation:

fluids commonly used in fluid power are Oil, Water, Air, CO², and Nitrogen gas, fluid power is commonly confused with hydraulic power, which only uses liquids, fluid power uses either liquids or gases

5 0
2 years ago
Other questions:
  • A mass of 5 kg of saturated liquid-vapor mixture of water is contained in a piston-cylinder device at 125 kPa. Initially, 2 kg o
    8·1 answer
  • (8 points) Consider casting a concrete driveway 40 feet long, 12 feet wide and 6 in. thick. The proportions of the mix by weight
    8·1 answer
  • Psychologist who uses behavioral approach to therapy would probably try which of the following
    13·2 answers
  • What is the physical significance of the Reynolds number?. How is defined for external flow over a plate of length L.
    13·1 answer
  • A specimen of commercially pure copper has a strength of 240 MPa. Estimate its average grain diameter using the Hall-Petch equat
    14·1 answer
  • Which one of the following is a list of devices from least efficient to most efficient
    9·1 answer
  • A soil element is subjected to a minor principle stress of 50 kPa on a plane rotated 20 ° counterclockwise from vertical. If the
    10·1 answer
  • You apply a force of 19 lbs on to the end of a lever to lift a crate. The resistance of the load is 106 lbs. Calculate the
    13·1 answer
  • The hot-wire anemometer.' A hot-wire anemome ter is essentially a fine wire, usually made of platinum,which is heated electrical
    6·1 answer
  • What invention of the Middle Ages contributed to making books easily available?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!