



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This assignment was given by Dr. Jyoti Lokesh at Biju Patnaik University of Technology, Rourkela for Computer Programming course. It includes: Traffic, Problems, Program, Procedure, Sample, Run, Timer, Value, Statement, Indentation, Code, Commenting
Typology: Exercises
1 / 5
This page cannot be seen from the preview
Don't miss anything!




Course No. CS Course Title Computer Programming
Deadline: Monday 19th^ March, 2012 12:00pm
Today when you were entering the university you realized that our beloved university, MAJU, is facing traffic problems on the main gate. A guard has to be always there to direct the traffic. You being an efficient CS student offer your services to resolve this issue. You suggest that traffic lights be inserted on the three roads meeting at MAJU gate. Traffic moves out of gate through one road (let us call it the “out-road”) and can come in from two roads (let us call these “in-road1” and “in-road2”). You are now writing the software for traffic lights on these three roads (i.e. out-light, in-light1 and in-light2 respectively). Each traffic light stays green for 3 seconds, yellow for 1 second and red for 8 seconds (we assume traffic is moving at the speed of light for this assignment!). The lights turn green in this order: out-light, in-light1, in-light2.
You can represent the three signals of a traffic light: red, yellow and green, by the characters ‘R’, ‘Y’ and ‘G’ respectively. The on signal can be represented by writing the word “on” with respective signal, e.g. if green is on for in-light1, this state can be represented as:
In-Light1: R Y G(on)
You have to display a timer too and change the signals accordingly.
Your program starts by prompting user to enter a timer value. The program then displays lights’ statuses for decrementing timer values till the timer turns down to 0. Then the program asks the user if he wants to enter another timer value.
Here is a sample run of your program:
Please enter the timer value: (user enters 26)
Timer: 26 Out-Light: R Y G(on) In-Light1: R(on) Y G In-Light2: R(on) Y G Timer: 25 Out-Light: R Y G(on) In-Light1: R(on) Y G In-Light2: R(on) Y G Timer: 24 Out-Light: R Y G(on) In-Light1: R(on) Y G In-Light2: R(on) Y G Timer: 23 Out-Light: R Y(on) G In-Light1: R Y(on) G In-Light2: R(on) Y G Timer: 22 Out-Light: R(on) Y G In-Light1: R Y G(on) In-Light2: R(on) Y G Timer: 21 Out-Light: R(on) Y G In-Light1: R Y G(on) In-Light2: R(on) Y G Timer: 20 Out-Light: R(on) Y G In-Light1: R Y G(on) In-Light2: R(on) Y G Timer: 19 Out-Light: R(on) Y G In-Light1: R Y(on) G In-Light2: R Y(on) G Timer: 18 Out-Light: R(on) Y G In-Light1: R(on) Y G In-Light2: R Y G(on) Timer: 17 Out-Light: R(on) Y G In-Light1: R(on) Y G In-Light2: R Y G(on) Timer: 16
Out-Light: R(on) Y G In-Light1: R(on) Y G In-Light2: R Y G(on) Timer: 4 Out-Light: R(on) Y G In-Light1: R(on) Y G In-Light2: R Y G(on) Timer: 3 Out-Light: R Y(on) G In-Light1: R(on) Y G In-Light2: R Y(on) G Timer: 2 Out-Light: R Y G(on) In-Light1: R(on) Y G In-Light2: R(on) Y G Timer: 1 Out-Light: R Y G(on) In-Light1: R(on) Y G In-Light2: R(on) Y G Timer: 0 Out-Light: R Y G(on) In-Light1: R(on) Y G In-Light2: R(on) Y G
Do you want to enter another timer value? Please enter y for yes or n for no: (user enters x) Please answer with yes or no only.
Do you want to enter another timer value? Please enter y for yes or n for no: (user enters 7) Please answer with yes or no only.
Do you want to enter another timer value? Please enter y for yes or n for no: (user enters Y) Please enter the timer value: (user enters 1)
Timer: 1 Out-Light: R Y G(on) In-Light1: R(on) Y G In-Light2: R(on) Y G Timer: 0 Out-Light: R Y G(on) In-Light1: R(on) Y G In-Light2: R(on) Y G
Do you want to enter another timer value? Please enter y for yes or n for no: (user enters N)
Have a nice day! Good bye : )