Provide two methods, one of renting a vehicle and the other for returning a vehicle with the following method specifications.
The rent() methods accepts as argument the name and license number of the person renting the vehicle and also the number of days the vehicle will be on hire. If the vehicle is currently available it should set the status to '0', store the name, license number and days rented in the corresponding instance variables before returning true. Otherwise this method should simply return false. This method should have the following signature: public bool rent (string name, string license, int rented)
The returnBack() method should return 0(zero) if an attempt is made to return back a car which is not on loan, otherwise it should compute and return the charges for renting the vehicle (number of days multiplied by daily-rate). This method should have the following signature: public double returnBack ()
SOLUTION CODE
#include <iostream>
using namespace std;
//define a struct to store the details of the person renting
struct person_renting
{
char name[50];
string licence;
int rented;
int status = 0;
}s[2];
public bool rent (string name, string license, int rented)
{
if(status == 0)
{
s[0].name = name;
s[0].license = name;
s[0].rented = rented;
return True;
}
else
{
return False;
}
}
//declare a variable for daily rate
int daily_rate = 1000;
public double returnBack ()
{
if(status != 0)
{
return s.rented *daily-rate;
}
else
{
return 0;
}
}
Comments
Leave a comment