Question
Hi, can you please help me with this C++ question? It is mainly about creating classes. Will thumbs up! Thanks! //vehicle.cpp file ------------------------------------------------------------------------------------------------------------------------------------------------------- #include vehicle.hpp
Hi, can you please help me with this C++ question? It is mainly about creating classes. Will thumbs up! Thanks!
//vehicle.cpp file -------------------------------------------------------------------------------------------------------------------------------------------------------
#include "vehicle.hpp"
//implementation of all methods defined in Vehicle.h file
Vehicle::Vehicle(string m, Date date, int mi, string id)
{
model = m;
dateOfJoin = date;
mileage = mi;
vehicle_id = id;
for (int i = 0; i
for (int j = 0; j
isVehicleAvailable[i][j] = true;
}
}
}
//constructor
Vehicle::Vehicle()
{
model = "";
dateOfJoin = Date();
mileage = 0;
vehicle_id = "";
for (int i = 0; i
for (int j = 0; j
isVehicleAvailable[i][j] = true;
}
}
}
void Vehicle::bookCar(Date date)
{
int day = date.getDay();
int month = date.getMonth();
if (day
if (isVehicleAvailable[month][day]){
cout
cout
date.print();
isVehicleAvailable[month][day] = false;
}
else{
cout
date.print();
}
}
}
void Vehicle::printDetails()
{
cout
cout
dateOfJoin.print();
cout
cout
}
void Vehicle::setModel(string mod)
{
model = mod;
}
string Vehicle::getModel() const
{
return model;
}
void Vehicle::setDateOfJoin(Date d)
{
dateOfJoin = d;
}
Date Vehicle::getDateOfJoin() const
{
return dateOfJoin;
}
void Vehicle::setMileage(int mil)
{
mileage = mil;
}
int Vehicle::getMileage() const
{
return mileage;
}
void Vehicle::setVehicleID(string id)
{
vehicle_id = id;
}
string Vehicle::getVehicleID() const
{
return vehicle_id;
}
bool Vehicle::vehicleAvailable(int month, int day)
{
return isVehicleAvailable[month][day];
}
void Vehicle::setVehicleAvailable(int month, int day, bool available)
{
isVehicleAvailable[month][day] = available;
}
vehicle.h file -------------------------------------------------------------------------------------------------------------------------------------------------------------
#ifndef VEHICLE_H
#define VEHICLE_H
#include "date.hpp"
using namespace std;
class Vehicle {
private:
string model;
Date dateOfJoin;
int mileage;
string vehicle_id;
bool isVehicleAvailable[12][30];
public:
//parameterized constructor
Vehicle(string m, Date date, int mi, string id);
//default constructor (new)
Vehicle();
//destructor
~Vehicle()
{
//does not need to do anything
}
//method to book a car
void bookCar(Date date);
//method to print details
void printDetails();
//setters and getters
void setModel(string mod);
string getModel() const;
void setDateOfJoin(Date d);
Date getDateOfJoin() const;
void setMileage(int mil);
int getMileage() const;
void setVehicleID(string id);
string getVehicleID() const;
bool vehicleAvailable(int month, int day);
void setVehicleAvailable(int month, int day, bool available);
};
#endif
date.cpp file -------------------------------------------------------------------------------------------------------------------------------------------------------------
#include
#include "date.hpp"
//implementation of all methods defined in Date.h file
Date::Date()
{
month = 0;
day = 0;
year = 0;
}
Date::Date(int m, int d, int y)
{
month = m;
day = d;
year = y;
}
/ewly implemented constructor
Date::Date(const Date& other)
{
month = other.month;
day = other.day;
year = other.year;
}
void Date::print()
{
cout
}
void Date::setMonth(int mon)
{
month = mon;
}
void Date::setDay(int dy)
{
day = dy;
}
void Date::setYear(int yr)
{
year = yr;
}
int Date::getMonth() const
{
return month;
}
int Date::getDay() const
{
return day;
}
int Date::getYear() const
{
return year;
}
date.h file -----------------------------------------------------------------------------------------------------------------------------------------------------------------
#ifndef DATE_H
#define DATE_H
#include
using namespace std;
class Date {
int month, day, year;
public:
//default constructor
Date();
//constructor taking month, day and year values
Date(int m, int d, int y);
//constructor taking other Date as object (newly implemented)
Date(const Date& other);
//destructor
~Date()
{
//doesn't need to do anything
}
//method to print data about date
void print();
//setter methods
void setMonth(int mon);
void setDay(int dy);
void setYear(int yr);
//getter methods
int getMonth() const;
int getDay() const;
int getYear() const;
};
#endif
Please use C++ Below are provided classes Vehicle and Date. Following instructions of a) and b), create classes Car, Truck and Customer. For each class, please include one or more constructors, destructor and the necessary set and get functions for each class. Also, provide a print function for each class which outputs all the data members of that class. a) Derive a Car class from the Vehicle class, where Car class should have an additional data member for the passenger capacity as an integer. Derive a Truck class from the Vehicle class, where Truck class should have an additional data member for the weight limit of the truck as an integer b) Define a class Customer with the following data members: name of the customer as a standard library string driving license of the customer as a library string date of birth of the customer (use class Date). Deliverables: car.cpp, car.h, truck.cpp, truck.h, customer.cpp, customer.h, test.cppStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started