Answer to Question #322903 in C++ for kiii

Question #322903

Implement a structure of car having car model, plate number, location, isParked (boolean type).

Car can move and park.


Move(): This function may update the location of car as it is moved.

Park(): This function added car details in the system and update is parked status.


 Your program will also tell the parking managemt about the status of parking using isParked().

IsParked() : This function can find a car is it parked on not?


1
Expert's answer
2022-04-04T08:22:21-0400




#include<iostream>
#include <string>
using namespace std;


class Car{
private:
	string model;
	string plateNumber;
	string location;
	bool is_Parked;
public:
	Car(){
		is_Parked=false;
	}
	//Move(): This function may update the location of car as it is moved.
	void Move(){
		cout<<"Enter a new location: ";
		getline(cin,location);
		is_Parked=false;
	}
	//Park(): This function added car details in the system and update is parked status.
	void Park(){
		cout<<"Enter model: ";
		getline(cin,model);
		cout<<"Enter plate number: ";
		getline(cin,plateNumber);
		cout<<"Enter location: ";
		getline(cin,location);
		is_Parked=true;
	}
	bool isParked(){
		return is_Parked;
	}


};




int main()
{
	Car c;
	c.Park();
	if(c.isParked()){
		cout<<"Is parked\n\n";
	}else{
		cout<<"Is not parked\n\n";
	}
	c.Move();
	if(c.isParked()){
		cout<<"Is parked\n\n";
	}else{
		cout<<"Is not parked\n\n";
	}


	system("pause");
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS