Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

4. Safest Driving Area Write a program that determines which of five geographic

ID: 3911270 • Letter: 4

Question

4. Safest Driving Area Write a program that determines which of five geographic regions within a major city (north, south, east, west, and central) had the fewest reported automobile accidents last year. It should have the following two functions, which are called by main: int getNumAccidents() is passed the name of a region. It asks the user for the number of automobile accidents reported in that region during the last year, vali- dates the input, then returns it. It should be called once for each city region. void findLowest () is passed the five accident totals. It determines which is the smallest and prints the name of the region, along with its accident figure. Input Validation: Do nota ident number that is less than 0.

Explanation / Answer

Find the required program in c++ as:

//=================================================================================

#include <iostream>
#include <string>

using namespace std;

// Global declaration of regions allow it to be used throughout the program
string regions[5]={"east","west","north","south","central"};  

int getNumAccidents(string region)
{
    int accidentCount = 0;
    while(accidentCount<=0)     // Check condition for +ve accident count
    {
        std::cout << "Please enter the number of automobile accidents reported in "<<region<<" region during last year: " << std::endl;
        std::cin >> accidentCount;      
    }
    return(accidentCount);
}

void findLowest(int* accidents)
{
    int min,index,i;
    min=accidents[i];
    index=i;
// The following loop simply scans the entire array and retains only the minimum count with its region index
    for(i=0;i<4;i++)  
    {
        if(min>accidents[i+1])
        {
            min=accidents[i+1];
            index=i+1;
        }
      
    }
cout<<"Region "<<regions[index]<<" is reported with minimum accident numbers of: "<<min<<endl;
  
}

int main() {
int region_accident_count[5];
int accidentCount,i;

// Calling the function five times to get the accident data
for(i=0;i<5;i++)
{
region_accident_count[i] = getNumAccidents(regions[i]);
}

// Calling to find the lowest reporting region with value
findLowest(region_accident_count);
return 0;
}

//==================================================================================

Sample output:

Hope this helps! ********** Please Thumbs Up! **********

In case of any clarification required, please comment!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote