Answer to Question #177739 in C++ for Hamna sattar

Question #177739

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


1
Expert's answer
2021-04-02T07:09:27-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS