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

Problem: Chapter 6 Programming Challenge #4 pg 370 - Safest Driving Area of the

ID: 3533399 • Letter: P

Question

Problem: Chapter 6 Programming Challenge #4 pg 370 - Safest Driving Area of the Gaddis C++ Book. Constraints: This program must produce screen output that matches the format defined in the sample output below. NO GLOBAL VARIABLES ALLOWED. This program MUST use the following functions: int getNumAccidents() - is passed the name of the region by value and returns the number of accidents for that region. This function must ask the user for the number of accidents for that particular region using the name that was passed and validate the input (see Input Validation requirements below). void findLowest() - is passed the five accident totals by value and returns no value. This function must determine which region has the least amount of accidents and then display the region and the number of accidents for that region. ADDITIONAL FUNCTIONS: void Instruct() - is NOT passed any values and returns no value. This function outputs a description of the program and the developer's name (i.e. programmer's name). Your function MUST display the following text and fill in your name as the developer's name (i.e. replace "PUT YOUR NAME HERE" with your name). **************************************************************** This program will determine which region has the least amount of accidents. You will be prompted to enter the number of accidents for each region. Please enter an Integer. Program Developed by: "PUT YOUR NAME HERE" ***************************************************************** void Average() - is passed by Reference the average variable from main and passed the five accident totals by value. This function averages the five accident totals. All functions are called by main. Input Validation: Do not accept an accident number that is less than 0. If a value less than zero is entered the user must be prompted to enter a valid value. WRITE THE PROGRAM: Write the program for the Problem above. General Pseudo Code for main function: Declare and Initialize Variables Call Instruct() to display the program description Call getNumAccidents() for North Region Call getNumAccidents() for South Region Call getNumAccidents() for East Region Call getNumAccidents() for West Region Call getNumAccidents() for Central Region Call findLowest() Call Average() Output the Average number of Accidents

Explanation / Answer

#include <iostream>

using namespace std;


void Instruct();

int getNumAccidents();

int findLowest( int, int , int, int ,int);

int Average(int, int , int, int ,int);


int main()

{

int westAccidents, eastAccidents, southAccidents, northAccidents, centralAccidents;

int low, avg;

  

Instruct();

cout <<"Region West:" << endl;

westAccidents = getNumAccidents();

cout <<"Region East:" << endl;

eastAccidents = getNumAccidents();

cout <<"Region South:" << endl;

southAccidents = getNumAccidents();

cout <<"Region North:" << endl;

northAccidents = getNumAccidents();

cout <<"Region Central:" << endl;

centralAccidents =getNumAccidents();


low = findLowest(westAccidents, eastAccidents, southAccidents, northAccidents, centralAccidents);

avg = Average (westAccidents, eastAccidents, southAccidents, northAccidents, centralAccidents);

cout << " The lowest number of accidents was: " <<low <<endl;

cout << " The average number of accidents was: " << avg << endl;


cin.get();

cin.get();

return 0;

}

void Instruct()

{

cout << " **************************************************************** "<< endl;

cout <<" This program will determine which region has the least amount of accidents. You will be prompted to enter the number of accidents for each region. Please enter an Integer." <<endl;

cout << "Program Developed by: "YOURNAMEHERE"" << endl;

cout << " *****************************************************************" << endl;

}

int getNumAccidents()

{

int accidents;

cout <<"Enter the number of accidents" << endl;

cin >> accidents;

return accidents;


}

int findLowest ( int west, int east, int south, int north,int central)

{

int low = west;

if (east < low)

low = east;

if (south < low)

low = south;

if (north <low)

low = north;

if (central < low)

low = central;

return low;


}

int Average( int west, int east, int south, int north,int central)

{

int avg = 0;

avg = (west + east+ south + north+ central) /5;


return avg;

}

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