Access over 20 million homework & study documents
search

A traffic surveyor uses a program to analyze traffic flow on the Yel

Content type

User Generated

Rating

Showing Page:
1/5
A traffic surveyor uses a program to analyze traffic flow on
the Yellow Brick Bridge over the course of a week. The
program has been pre-loaded with the following daily
traffic values in an array: 23, 55, 64, 52, 79, 66, 30. The
program provides a recurring menu that allows the
surveyor the choice of viewing the maximum, minimum or
average traffic flow values for the week until the exit option
is selected.
Write a C program on the above scenario. The program
should make use of arrays and modular programming.
Please make comments as necessary.
Solution
#include <stdio.h>
#include <stdlib.h>
int menu();
void max(int traficValues[]);
int smallest(int traficValues[]);
float average(int traficValues[]);
int main(void)
{
int traficValues[7]={23, 55, 64, 52, 79, 66, 30};//pre-load
int option;

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/5
int Min;
float avg;
option = menu();
while(option!=4)
{
switch(option)
{
case 1: max(traficValues);/*could you either call a function
or just write everything in the case*/
option = menu();// Ask user what they want to do next
break;
case 2: Min = smallest(traficValues);
printf(\"Minimum trafic values: %d\", Min);
option = menu();
break;
case 3: avg = average(traficValues);
printf(\"Average trafic values of the week: %.1f\", avg);
option = menu();
break;
case 4: printf(\"exit\");
exit(101);
break;

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/5

Sign up to view the full document!

lock_open Sign Up
End of Preview - Want to read all 5 pages?
Access Now

Unformatted Attachment Preview

A traffic surveyor uses a program to analyze traffic flow on the Yellow Brick Bridge over the course of a week. The program has been pre-loaded with the following daily traffic values in an array: 23, 55, 64, 52, 79, 66, 30. The program provides a recurring menu that allows the surveyor the choice of viewing the maximum, minimum or average traffic flow values for the week until the exit option is selected. Write a C program on the above scenario. The program should make use of arrays and modular p rogramming. Please make comments as necessary. Solution #include #include int menu(); void max(int traficValues[]); int smallest(int traficValues[]); float average(int traficValues[]); int main(void) { int traficValues[7]={23, 55, 64, 52, 79, 66, 30};//pre -load int option; int Min; float avg; option = menu(); while(option!=4) { switch(option) { case 1: max(traficValues);/*could you either call a function or just write everything in the case*/ option = menu();// Ask user what they want to do next break; case 2: Min = smallest(traficValues); printf(\"Minimum trafic values: %d\", Min); option = menu(); break; case 3: avg = average(traficValues); printf(\"Average trafic values of the week: %.1f \", avg); option = menu(); break; case 4: printf(\"exit\"); exit(101); break; default: printf(\"Incorrect Option. Please re-enter. \ \"); option = menu(); break; } } return 0; } int menu(void) { int option; printf(\"\ What would you like to do\ \"); printf(\"1. View ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Anonymous
I use Studypool every time I need help studying, and it never disappoints.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4