In: Computer Science
Program to implement in c++
dont forget to implement the 2D array and print whether the vehicle is available or not! This is the main part that I dont know how to implement! no good rating if this isnt done.
Define a class Vehicle that has the following data members: Model of the vehicle (e.g., Ford, Toyota) as a standard library string. The date that vehicle has joined to the fleet use the class Date that has the following data members:month, day, year. The mileage of the vehicle as an integer. A four digit id of the vehicle as a standard library string, such as string vehicle_id = "2345"; A two-dimensional 12-by-30 array of Boolean variables that shows whether the vehicle is available or has been rented out for each day of the year. If the vehicle is available on a given date then Boolean variable is true and if rented out is false. Each row of the array corresponds to a month and for simplicity we assume that the number of days in each month is 30.
#include<iostream>
#include<string>
using namespace std;
//date class
class date{
public:
int day,month,year;
date(){}
date(int d,int m,int y){
day = d;
month = m;
year=y;
}
};
//vehicle class
class vehicle{
public:
//class data members
string model, id;
date d;
int mileage;
bool calendar[12][30];
vehicle(){} //non-parameterized constructor
//parameterized constructor
vehicle(string m,string Id,date dd,int mil){
model = m;
id=Id;
d=dd;
mileage=mil;
}
//isAvialable function return value based on the date
bool isAvailable(date dd){
return calendar[dd.month][dd.day];
}
//by passing date, vehicle can be rented
void rentIt(date dd){
calendar[dd.month][dd.day] = false;
}
};
//main function
int main()
{
//sample test definitions
date d(21,10,2018);
vehicle v("Ford","1234",d,25);
if(v.isAvailable(d))
cout<<"Available";
else cout<<"Not";
return 0;
}
//output screenshot
//any query, post in the comment section