Back Button
Back to Chapter
C++ Introduction
No items found.
C++ Basics
No items found.
C++ Control Statements
No items found.
C++ Logical Operators
No items found.
C++ Procedural Programming
No items found.
C++ Structural Programming
No items found.
C++ Implementation of OOPS
No items found.
C++ Arrays and Vectors
No items found.
C++ Error Handling
No items found.
C++ File Handling
No items found.
Collapse_Icon
Table of Contents

Pseudais is a car company, recently they have developed an electric-powered car, the C.E.O of the company wants to add an auto-pilot feature to the car. He hires a software engineer to write a code for this, he explains to him that the car needs to detect the traffic signals and move and stop the car accordingly,  he also says that the car should be programmed to take input from sensors and turn left or right.

Based on what you have learned in the previous lesson write a piece of code for the above problem.

Solution

#include using namespace std; void leftright() { int ch; cout<<"check if cars approaching from 1.left or 2.right or 3.from both direction!!"<>ch; switch(ch) { case 1: cout<<"steer right"<>ch; switch(ch) { case 1: cout<<"apply brakes\n"; break; case 2: leftright(); break; case 3: cout<<"Go ahead\n"; break; default: cout<<"enter valid input\n"; } } main() { int ch; do { cout<<"Do you wish to start car simulation\n 1.yes\n 2.no"<>ch; if (ch==1) { cout<<"car is moving ahead........................................................"<
Output: Do you wish to start car simulation 1.yes 2.no 1 car is moving ahead........................................................ traffic signal ahead!!! sense the light wavelenght and determine the color: 1.red 2. yellow 3.green 2 check if cars approaching from 1.left or 2.right or 3.from both direction!! 3 stop