Define a class named as Vehicle Contain data members(Minimum 3) Color, Wheels etc. Contain member functions( Minimum 3) Include a prototype and def of copy constructor A default constructor An Overloaded constructor No Need to define the functions Call the functions using OmniBus in main and use overloaded constructors to set values. Use copy constructors to make copy of OmniBus to a constructor SchoolBus
#include <iostream>
#include <string>
using namespace std;
class Vehicle
{
public:
Vehicle() {}
Vehicle(string col, int wh, int se, string V);
Vehicle(const Vehicle& Veh);
string getColour() { return colour; }
void setColour(string col) { colour = col; }
int getWheels() { return wheels; }
void setWheels(int wh) { wheels = wh; }
int getSeats() { return seats; }
void setSeats(int se) { seats = se; }
string getVIN() { return VIN; }
void setVIN(string V) { VIN = V; }
void Move() { cout << "Vehicle is moving...." << endl; }
void Start() { cout << "Vehicle is started." << endl; }
void Stop() { cout << "Vehicle is stopped!" << endl; }
void Display();
private:
string colour;
int wheels;
int seats;
string VIN;
};
Vehicle::Vehicle(const Vehicle& Veh)
{
cout << "Copy constructor" << endl;
this->colour = Veh.colour;
this->seats = Veh.seats;
this->VIN = Veh.VIN;
this->wheels = Veh.wheels;
}
Vehicle::Vehicle(string col, int wh, int se, string V) : colour(col), wheels(wh), seats(se), VIN(V)
{}
void Vehicle::Display()
{
cout << "*******************************" << endl;
cout << "Colour is: " << colour << endl;
cout << "Number of wheels is: " << wheels << endl;
cout << "Number of seats is: " << seats << endl;
cout << "VIN is: " << colour << endl;
cout << "*******************************" << endl;
}
int main()
{
Vehicle OmniBus("Black", 6, 16, "15KD36");
OmniBus.Display();
Vehicle SchoolBus(OmniBus);
SchoolBus.Display();
SchoolBus.setColour("Yellow");
SchoolBus.setWheels(8);
SchoolBus.setSeats(26);
SchoolBus.setVIN("15BA78");
SchoolBus.Display();
SchoolBus.Start();
SchoolBus.Move();
SchoolBus.Stop();
return 0;
}
Comments
Leave a comment