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

Create a program that simulates the decisions needed when a self-driving automob

ID: 3868567 • Letter: C

Question

Create a program that simulates the decisions needed when a self-driving automobile makes a left turn at a traffic light. The decision on whether to turn is to be based on the following conditions: What is the traffic light color? Red, Yellow, or Green? Is there oncoming traffic? Is the turn signal currently set to indicate a left turn, a right turn, or is it off? Required program input: The program is to take relevant input from the user at each decision point regarding the current condition in question. The program should produce the following output: At the end of the program, the program outputs whether the self-driving auto has decided to turn or has decided to wait.

Explanation / Answer

C++ code:

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
int c = 0;
while(true)
{
cout << "**" <<"If the traffic light is Red, Enter 1, if its Yellow enter 2, if its Green then Enter 3!" << endl;
cin >> c;
if(c == 1)
{
cout << "self-driving auto has decided to wait, beacause traffic light is red! ";
exit(0);
}
else if(c==2)
{
cout << "self-driving auto has decided to wait, beacause traffic light is Yellow! ";
exit(0);
}
else if(c == 3)
{
break;
}
else
{
cout << "Invalid input, please enter 1 or 2 or 3! ";
}

}

while(true)
{
cout << "**" <<"Enter 1 if there is oncoming traffic otherwise enter 2!" << endl;
cin >> c;
if(c == 1)
{
cout << "self-driving auto has decided to wait, beacause there is incoming traffic! ";
exit(0);
}
else if(c == 2)
{
break;
}
else
{
cout << "Invalid input, please enter 1 or 2! ";
}
}

while(true)
{
cout << "**" <<"If the turn signal currently set to indicate a left turn, Enter 1, if it indicates rigth, enter 2, if its off, then enter 3!"<< endl;
cin >> c;
if(c == 1)
{
cout << "self-driving auto has decided to turn left! ";
exit(0);
}
else if(c==2)
{
cout << "self-driving auto has decided to turn rigth! ";
exit(0);
}
else if(c == 3)
{
cout << "self-driving auto has decided to wait, since turn signal currently off! ";
exit(0);
}
else
{
cout << "Invalid input, please enter 1 or 2 or 3! ";
}
}

return 0;
}

Sample run Outputs:

1)

**If the traffic light is Red, Enter 1, if its Yellow enter 2, if its Green then Enter 3!

1
self-driving auto has decided to wait, beacause traffic light is red!

2)

**If the traffic light is Red, Enter 1, if its Yellow enter 2, if its Green then Enter 3!

3
**Enter 1 if there is oncoming traffic otherwise enter 2!
2
**If the turn signal currently set to indicate a left turn, Enter 1, if it indicates rigth, enter 2, if its off, then enter 3!

1
self-driving auto has decided to turn left!

3)

**If the traffic light is Red, Enter 1, if its Yellow enter 2, if its Green then Enter 3!

3
**Enter 1 if there is oncoming traffic otherwise enter 2!
2
**If the turn signal currently set to indicate a left turn, Enter 1, if it indicates rigth, enter 2, if its off, then enter 3!

2
self-driving auto has decided to turn rigth!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote