write a C++ program for a Semi-autonomous vehicle (Self-Driving Car) that has the
following requirements. Class name is Car that contains the following attributes.
• The name of car
• The direction of car (E,W,N,S)
• The position of car (from imaginary zero point)
• Create a rough Map of the way you come to school (e.g go east for x distance, go west
for x distance, etc) and use the class that you just created a function and pass in these
values and print the steps. For example, I turn west for 200m so it would print: “Moving:
West for distance: 200” (Translate the map into code)
#include <iostream>
#include <string>
using namespace std;
class Car
{
	string name;
	char dir;
	int pos;
public:
	Car():name(""),dir(' '),pos(0){}
	Car(string _name, char _dir, int _pos)
	:name(_name),dir(_dir),pos(_pos){}
	void Assign()
	{
		cout << "Please, enter a name of car: ";
		cin >> name;
		cout << "Please, enter a direction of car: ";
		cin >> dir;
		cout << "Please, enter a position of car: ";
		cin >> pos;
	}
	void TurnOnMap(char c, int position)
	{
		cout << endl<<name<<" moving: ";
		switch (c)
		{
			case 'E':case 'e':
			{
				cout << "East ";
				break;
			}
			case 'W':case 'w':
			{
				cout << "West ";
				break;
			}
			case 'N':case 'n':
			{
				cout << "North ";
				break;
			}
			case 'S':case 's':
			{
				cout << "South ";
				break;
			}
		}
		cout << "for distance " << position;
	}
};
int main()
{
	Car c("Toyota", 'W', 100);
	c.TurnOnMap('E', 400);
	c.TurnOnMap('n',250);
	Car d;
	cout << endl;
	d.Assign();
	d.TurnOnMap('S', 400);
}
Comments