we are using 2013 visual studio C++ i got comfused with this question for exampl
ID: 662372 • Letter: W
Question
we are using 2013 visual studio C++
i got comfused with this question for example question can somebody write a program for ma?
At the intersection of Campus and Culver Street there is a traffic light which is to be operated by a traffic controller (TC).
The TC has a clock with one minute period. The lights should operate so as to alternate allow traffic to flow on Campus for one minute and then Culver street for one minute.
If a pedestrian presses a button (P) at the corner, all lights should turn red at the end of the current period, stay red for two minutes and then resume operation as if the interruption had not occurred, i.e. in proper sequences.
1- Simulate this traffic light controller by writing a program in C. The program accepts input p as a pedestrian request.
2-Th console should display the following messages repeatedly if p=0:
No Pedestrian, Campus is GREEN, Culver is RED
After one minute delay the message changes to:
No Pedestrian, Campus is RED, Culver is GREEN
3-The console should display the following message if p=1
Pedestrian is Passing, Campus is RED, Culver is RED
After two minutes delay p resets to zero and step 2 will start.
4-The cycle should continue until the process is stopped by inputting p=3.
Explanation / Answer
#include<iostream.h>
#include<time.h>
int main()
{
int selection;
int p;
do{
cout<<"enter a number";
}
switch(selection)
case 1:
if(p==0)
{
cout<<"No pedestrain, Campus is green, Culver is Red";
time_t start;
time_t current;
time(&start);
do
{
time(¤t);
}
while(difftime(current,start) < 240.0);
break;
}
Case 2:
if(p==1)
{
cout<<"Pedestrain is passing, Campus is Red, Culver is Red";
time_t start;
time_t current;
time(&start);
do
{
time(¤t);
}
while(difftime(current,start) < 240.0);
break;
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.