Question

c plus plus determines which of 5 geographic regions within a major city north south east...

c plus plus

determines which of 5 geographic regions within a major city north south east west and central had the fewest reported traffic accidents last year it should have the following function which are called by main

int get NumAccidents is passed the name of a region it asks the user for the number of traffic accidents reported in that region during the last year validates the input then returns it. it should be called once for each city region.

void findlowest is passed the five accident totals it determins which is the smallest and prints the name of the region, along with its accident figure.

int calc findLowest is passed the five accident totals. it determins which is the smallest and prints the name of the region, along with its accident figure,

int calcAverage should calculate and return the average number of trafiic accidents of 5 regions

int main() demonstrate you functions by calling them from the main function.

your program should display

number of traffic accidents in each region;

the average number of accidents last year and

the name of the region that has the smallest number of trafiic accident

input validation not accepted an accident number that is less than 0

0 0
Add a comment Improve this question Transcribed image text
Answer #1

PROGRAM CODE (C++)

#include <iostream>
using namespace std;

// A struct Region which stores region name and number of accidents in it

struct Region{
   string name;
   int trafficAccidents;
};

// A function getNumAccidents which takes name of region as parameter

int getNumAccidents(string region) {
  
   // Ask user for traffic accidents in that region during last year
  
   int numAcc;
  
   cout << "Enter number of traffic accidents reported in " << region << " region during last year: ";
   cin >> numAcc;
  
   // Validating that number of accidents must not be less than 0
  
   if(numAcc < 0)
       numAcc = 0;
      
   // return that number of accidents
  
   return numAcc;          
}

// A function that will find the lowest region (where number of accidents are lowest) and print its name

void findLowest(Region regions[]) {
  
   // Finding the smallest region
  
   int lowest = regions[0].trafficAccidents;
   int index = 0;   // Store index of that region
  
   // Iterating through all regions
  
   for (int i=0; i<5; i++) {
      
       if(regions[i].trafficAccidents < lowest) {   // finding one which has lowest number of accidents
          
           lowest = regions[i].trafficAccidents;
           index = i;
       }
   }
  
   // Printing name and accident figure of that region
  
   cout << "**** Region with Smallest number of Traffic Accidents****" << endl;
   cout << "Name of Region: " << regions[index].name << endl;
   cout << "Number of Traffic Accidents: " << regions[index].trafficAccidents << endl;
}

// A function that will calculate average number of accidents in all five regions

int calcAverage(Region regions[]) {
      
   int totalAcc = 0;
  
   for (int i=0; i<5; i++) {
      
       totalAcc += regions[i].trafficAccidents;
   }
  
   return totalAcc / 5;
}

int main() {
  
   // An array of Region to store five regions
  
   Region regions[5] = {{"north", 0}, {"south", 0}, {"east", 0}, {"west", 0}, {"central", 0}};
  
  
   // Iterating over regions array and calling getNumAccidents to store number of accidents in each region last year
  
   cout << endl;
   for (int i=0; i<5; i++) {
      
       int num = getNumAccidents(regions[i].name);
       regions[i].trafficAccidents = num;
   }
  
   // Now showing number of accidents in each region
  
   cout << endl;
  
   cout << "Region\tNumber of Traffic Accidents" << endl;
  
   for (int i=0; i<5; i++) {
      
       cout << regions[i].name << "\t" << regions[i].trafficAccidents << endl;
   }
  
   // Calling findLowest function to print lowest region
  
   cout << endl;
   findLowest(regions);
  
   // Calling calcAverage to calculate average number of accidents
  
   cout << endl;
   cout << "The average number of accidents last year: " << calcAverage(regions) << endl;
  
   return 0;
}

SAMPLE OUTPUT

C:\Users\Dell OneDrive\Desktop\CPP July 2020\trafficAccidents.exe Enter number of traffic accidents reported in north region

----------------------------------------------------------------------------------------------------------------------------------------

COMMENT DOWN FOR ANY QUESTIONS...........
HIT A THUMBS UP IF YOU DO LIKE IT!!!

Add a comment
Know the answer?
Add Answer to:
c plus plus determines which of 5 geographic regions within a major city north south east...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Write a program that determines which of the 6 states had the most traffic tickets...

    C++ Write a program that determines which of the 6 states had the most traffic tickets last year. The 6 states are California, Georgia, Alabama, Illinois, Michigan, and Florida. The program should have the following 2 functions, which are called by main. Int getNumTickets () is passed the name of the state. It asks the user for the number of traffic tickets reported during last year, validates the input and then returns it. It should be called once for each...

  • Write a program that determines which of a company's eight divisions (North, South, East, West, Northeast,...

    Write a program that determines which of a company's eight divisions (North, South, East, West, Northeast, Southeast, Northwest, Southwest) had the greatest sales for a quarter. It should include the following two functions which are called only by main. double getSales() - it is passed the name of a division. It asks the user for a division's quarterly sales figure, validates the input then returns it. It should be called once for each division. Negative dollar amounts are invalid. void...

  • Help. Write a C++ program that determines which of a company's four divisions (North, South, East,...

    Help. Write a C++ program that determines which of a company's four divisions (North, South, East, West) has the greatest sales for the quarter. It should include three functions at a minimum: float getSales() is passed the name of a division. It asks the user for a division's quarterly sales figure, calls a validate() function that will validate the input, and then returns the value back to main(). This function should be called once for each division. void validate() is...

  • Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that...

    Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions. • void getScore() should ask the user for a test score, store it in the reference parameter variable, and validate it. This function should be called by the main once for each of the five scores to be entered. •...

  • Q1. Write a recursive function in C++ void printNumberedChars(string str, int i=0) { ... } which...

    Q1. Write a recursive function in C++ void printNumberedChars(string str, int i=0) { ... } which prints each character of the given string str on a new line, with each line numbered 1, 2, 3, …. For example calling the function with printNumberedChars("hello"); should output the following: 1. h 2. e 3. l 4. l 5. o Q2. Write a recursive function in C++ int sumArray(const int* arr, unsigned int size) { ... } which takes an array of integers,...

  • Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate...

    Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate the number of test scores the user enters; have scores fall into a normal distribution for grades -Display all of the generated scores - no more than 10 per line -Calculate and display the average of all scores -Find and display the number of scores above the overall average (previous output) -Find and display the letter grade that corresponds to the average above (overall...

  • Santa Monica College CS 20A: Data Structures with C++ Spring 2019 Name: True/False: Circle one Assignment...

    Santa Monica College CS 20A: Data Structures with C++ Spring 2019 Name: True/False: Circle one Assignment 1 ID: 1. True / False 2. True / False 3. True / False 4. True / False 5. True / False 6. True / False 7. True / False 8. True / False 9. True / False 10. True / False Variable and functions identifiers can only begin with alphabet and digit. Compile time array sizes can be non-constant variables. Compile time array...

  • Edit a C program based on the surface code(which is after the question's instruction.) that will...

    Edit a C program based on the surface code(which is after the question's instruction.) that will implement a customer waiting list that might be used by a restaurant. Use the base code to finish the project. When people want to be seated in the restaurant, they give their name and group size to the host/hostess and then wait until those in front of them have been seated. The program must use a linked list to implement the queue-like data structure....

  • code in java please:) Part I Various public transporation can be described as follows: A PublicTransportation...

    code in java please:) Part I Various public transporation can be described as follows: A PublicTransportation class with the following: ticket price (double type) and mumber of stops (int type). A CityBus is a PublicTransportation that in addition has the following: an route number (long type), an begin operation year (int type), a line name (String type), and driver(smame (String type) -A Tram is a CityBus that in addition has the following: maximum speed (int type), which indicates the maximum...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT