Write a program that determines which of the four geographic regions within a ma
ID: 3679804 • Letter: W
Question
Write a program that determines which of the four geographic regions within a major city (North, South, East, and West) had the fewest reported automobile accidents last year. It should have the following two functions, which are called by the main() function:
- int getNumAccidents() is passed the name of a region (string) as parameter. It asks the user for the number of automobile accidents reported in that region during the last year, validates the input, then returns it. It should be called once for every city region.
- void findLowest() is passed the four accident totals as parameter. It determines which is the smallest and prints the name of the region, along with its accident figure.
Input Validation: Do not accept an accident number that is less than 0.00
Figure out the logic on paper first and show it using flowchart.
Explanation / Answer
#incllude<iostream>
using namespace std;
void fn_getNAcc(int&);
void fn_lowest(int,int,int,int,int);
int main(int agrc, char** argv)
{
int i_north=0;
int i_south=0;
int i_east=0;
int i_west=0;
int i_central=0;
count<<"Please enter the number of automobile accidents: ";
count<<"Reported in north region:";
fn_getNacc(i_north);
count<<"Reported in south region:";
fn_getNAcc(i_south);
count<<"Reported in east region:";
fn_getNAcc(i_east);
count<<"Reported in west region:";
fn_getNAcc(i_west);
count<<"Reported in central region:";
fn_getNAcc(i_central);
fn_lowest(i_north,i_south,i_east,i_west,i_central);
return 0;
}
void fn_getNAcc(int& i_num)
{
cin>>i_num;
while(i_num<0)
{
count<<"check your input and please re-enter the value ";
cin>>i_num;
}
return;
void fn_lowest(int i_n,int i_s,int i_e,int i_w,int i_c)
{
void i_lowest=min(i_n,min(i_s,min(i_e,min(i_w,int i_c))));
if(i_lowesr == i_n)
count<<"North is safest region to drive"<<i_lowest<<"accident reports ";
else if(if(i_lowesr == i_s)
count<<"south is safest region to drive"<<i_lowest<<"accident reports ";
else if(if(i_lowesr == i_e)
count<<"east is safest region to drive"<<i_lowest<<"accident reports ";
else if(if(i_lowesr == i_w)
count<<"west is safest region to drive"<<i_lowest<<"accident reports ";
else
count<<"central is safest region to drive"<<i_lowest<<"accident reports ";
return;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.