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

Last Modified 02/15/2009 Key Concepts: for loops, nesting structures Suppose you

ID: 3609133 • Letter: L

Question

Last Modified 02/15/2009

Key Concepts: for loops, nesting structures

Suppose you're analyzing the traffic flow on a given road andyou have access to traffic flow data readily available. This datais in the form of how fast traffic was moving through a given pointon the road at the given date and time.

We'll classify traffic flow data using the the three colorclassifications Google Maps uses for traffic data (according tothis Help page on 7/29/2008):

Suppose your data is available for 100 days and is recorded bydate and a day number from 0 to 99. September 3, a Wednesday, isday 0. Because traffic patterns vary from weekends to weekdays, wewant to look only at traffic data on Wednesdays. Write a programthat prompts the user for the speed of traffic recorded during eachWednesday's observation. Count how many observations fall into eachof the categories. Report your counts for each category at theend.

Your prompt must be more sophisticated than asking for"Wednesday #1," "Wednesday #2," etc. It must at least refer to daynumbers. If you have time, work on making it include the date.

Explanation / Answer

#include<iostream.h>
int main()
{int i=0,speed[100]={0};
int green=0,yellow=0,red=0;

do{
    cout<<"Enter traffic speed in m.p.h. onDay "<<i<<": ";
    cin>>speed[i];
    if(speed[i]>50)
        green++;
    else
       if(speed[i]>=25)
         yellow++;
       else
          red++;
    
     i+=7;
     }while(i<100);
cout<<" TRAFFIC SUMMARY: ";
cout<<"# Green observations (traffic moving faster than 50m.p.h.): "<<green<<endl;
cout<<"# Yellow observations (traffic moving between 25 and50 m.p.h.): "<<yellow<<endl;
cout<<"# Red observations (traffic moving slower than 25m.p.h.): "<<red<<endl;
system("pause");
return 0;
}