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
A company has a stack that emits a hazardous air pollutant. The ground mass concentration directly downwind of the plume sometim
fredd [130]

Answer:

do the wam wam

Explanation:

3 0
3 years ago
Read 2 more answers
Which term describes how a mineral looks when it breaks apart in an irregular way ​
attashe74 [19]

Answer:

Fracture.

Explanation:

Fracture describes how a mineral looks when it breaks apart in an irregular way.

8 0
2 years ago
Read 2 more answers
For which of the following structures would a pile foundation be appropriate? (Select all that apply.)
tiny-mole [99]

Answer:

Football stadium on rocky soil

Skyscraper on bedrock

Apartment building on sandy soil

Explanation:

6 0
3 years ago
What is the one thing that Zeus loathes the most? What did he do when he caught humans committing this act? What parallels to an
mel-nik [20]

Answer:

ares

Explanation:

He refer ares as the God that he hate the most

8 0
2 years ago
A ceramic matrix composite contains internal flaws as large as 0.001 cm in length. The plane strain fracture toughness of the co
murzikaleks [220]

Since the applied stress required for failure due to crack propagation is still higher than 550 MPa, the ceramic is expected to fail due to overload and not because of the flaws

Explanation:

<u>Plane -Strain Fracture toughness is calculated as</u>

k_{IC}=fб\sqrt{\pi a}

F=geometry factor of the flaw

б=Stress applied

k_{IC}=Fracture toughness

a=Flaw size

<u>Given that </u>

Internal Flaw,a=0.001cm

Fracture Toughness k_{IC}=45MPa\sqrt{m}

Tensile Strength б=550 MPa

Geometry Factor,f=1

<u>Calculation</u>

An internal Flaw i s 0.001 cm

2a=0.001cm

a=0

6 0
3 years ago
Other questions:
  • Does a thicker core make an electromagnet stronger?
    13·1 answer
  • A 0.40-m3 insulated piston-cylinder device initially contains 1.3 kg of air at 30°C. At this state, the piston is free to move.
    15·1 answer
  • What entrepreneurial activities do you know?are you capable of doing entrepreneurial activities
    15·1 answer
  • The hot and cold inlet temperatures to a concentric tube heat exchanger are Th,i = 200°C, Tc,i = 100°C, respectively. The outlet
    10·1 answer
  • Assume a steel pipe of inner radius r1= 20 mm and outer radius r2= 25 mm, which is exposed to natural convection at h = 50 W/m2.
    12·1 answer
  • 53. The plan of a building is in the form of a rectangle with
    13·1 answer
  • In a device to produce drinking water, humid air at 320C, 90% relative humidity and 1 atm is cooled to 50C at constant pressure.
    14·1 answer
  • Find the capacitance reactance of a 0.1 micro frequency capacitor 50Hz and at 200Hz​
    9·1 answer
  • The minimum recommended standards for the operating system, processor, primary memory (RAM), and storage capacity for certain so
    12·2 answers
  • What is the locating position of the land field?​
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!