Question & Answer: Write a program that determines which of 5 countrys (China, England, Iceland, India, an…..

Write a program that determines which of 5 countrys (China, England, Iceland, India, and USA) had the fewest reported automobile accidents last year. It should have the following two functions, which are called by main. o int getNumAccidents( ) is passed the name of a country. It asks the user for the number of automobile accidents reported in that country during the last year, validates the input, then returns it. It should be called once for each counry. o void findLowest( ) is passed the five accident totals. It determines which is the smallest and prints the name of the country, along with its accident figure

Expert Answer

 

#include <iostream>
#include <string>

using namespace std;

int getNumAccidents(string borough);
int findLowest(int [],const int);

int main()
{
string borough[5] = {“China”, “England”, “Iceland”, “India”, “USA”}; //Array of boroughs.
int numaccident [5];
const int cnt = 5;
int lowest;

for (int i=0;i<cnt;i++)
{
numaccident[i]=getNumAccidents(borough[i]);
}
lowest = findLowest(numaccident, cnt);
cout << endl;
cout << borough[lowest] << ” had the fewest accidents.n”;

cin.get();
return 0;
}

int getNumAccidents(string borough)
{
int numAccidents;

cout << “Enter the number of accidents that occured in “<< borough << “: “;
cin >> numAccidents;
if (numAccidents<0)    //Validation of accidents.
{
cout << “Please enter a number grater than 0 n”;
numAccidents=0;
cin >> numAccidents;
if (numAccidents<0)
{
cout << “You have entered an incorrect value 2 times, please run program again n”;
cin.get();
}
}
return numAccidents;

}

int findLowest(int numb[],const int size)
{
int lowest=numb[0];         //Stores first number as lowest.
int low;

for (int i= 0; i<size; i++)
{
if (numb[i]<lowest)
{
lowest=numb[i];
low = i;
}
}
return low;
}

Still stressed from student homework?
Get quality assistance from academic writers!