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.)
#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;
}
Comments
Leave a comment