Answer to Question #276047 in C++ for Joy Chepkwemoi

Question #276047

with a custom method called displayVehicle() that displays the details of a vehicle as follows:





If the vehicle is available then it should display the details of a vehicle as the values of the instance variables vehicleID and dailyRate only





Otherwise, if the vehicle is currently on loan it should display the name and license number of the person holding the car as well as the number of days it was rented out. (this obvious includes details above.)




1
Expert's answer
2021-12-06T05:30:15-0500
#include <string>
#include <iostream>
using namespace std;




class Vehicle
{
private:
	string vehicleID;
	double dailyRate;




	string licenseNumberPerson;
	int numberDaysRented;


public:
	Vehicle()
	{
		this->vehicleID  = "";
		this->dailyRate = 0;
		string licenseNumberPerson="";
		int numberDaysRented=0;
	}
	Vehicle(string vehicleID , double dailyRate,string licenseNumberPerson,int numberDaysRented)
	{
		this->vehicleID  = vehicleID;
		this->dailyRate = dailyRate;
		this->licenseNumberPerson = licenseNumberPerson;
		this->numberDaysRented = numberDaysRented;
	}


	void displayVehicle()
	{
		cout << "Vehicle ID: " << this->vehicleID << "\n";
		cout <<	"Daily Rate: " << this->dailyRate << "\n";


		if(this->numberDaysRented!=0){
			cout << "The license number of the person holding the car: " << this->licenseNumberPerson << "\n";
			cout <<	"The number of days it was rented out: " << this->numberDaysRented << "\n";
		}
		cout<<"\n";
	}
};




int main()
{


	Vehicle vehicles[5]; 
	vehicles[0]=Vehicle("FJH 123N", 12.00,"",0);
	vehicles[1]=Vehicle("DKY 222N", 25.0,"",0);
	vehicles[2]=Vehicle("GAF 333N", 18.0,"FG45421",5);
	vehicles[3]=Vehicle("BGH 444N", 40.0,"",0);
	vehicles[4]=Vehicle("FRS 555N", 30.0,"FG45412",4);


	for (int i=0;i<5;i++) {
		vehicles[i].displayVehicle();
	}
	cout << "\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