Question: Vehicle.h #pragma once #include using namespace std; class Vehicle { private: int numWheels, numDoors; public: // Default constructor Vehicle(); Vehicle(int, int); Vehicle(int); // Copy Constructors

 Vehicle.h #pragma once #include using namespace std; class Vehicle { private:int numWheels, numDoors; public: // Default constructor Vehicle(); Vehicle(int, int); Vehicle(int); //

Vehicle.h

#pragma once #include using namespace std;

class Vehicle { private: int numWheels, numDoors; public: // Default constructor Vehicle(); Vehicle(int, int); Vehicle(int); // Copy Constructors Vehicle(Vehicle &); Vehicle(Vehicle *); // Additional function void printVehicle(); // Destructor ~Vehicle(); };

Vehicle.cpp

// Vehicle.cpp #include "Vehicle.h"

Vehicle::Vehicle():Vehicle(0, 0){}

void Vehicle::printVehicle() { cout

Vehicle::Vehicle(int w, int d) { numWheels = w; numDoors = d; cout

Vehicle::Vehicle(int w):Vehicle(w, 2){}

// Implementing copy constructors

Vehicle::Vehicle(Vehicle &copy):Vehicle(copy.numWheels, copy.numDoors) { cout

Vehicle::Vehicle(Vehicle *copy) {

this->numWheels = copy->numWheels; this->numDoors = copy->numDoors; cout

Vehicle::~Vehicle(){}

week2.cpp

#include #include "Vehicle.h"

using namespace std;

// CreateVehicle function

void CreateVehicle(Vehicle &v, int w=4, int d=2) { v = Vehicle(w, d); }

int main(int argc, char** argv) {

Vehicle original; //empty constructor no ()

Vehicle copy(original); // copy constructor by reference

Vehicle secondCopy(&original); //copy constructor by point

copy.printVehicle();

CreateVehicle(copy, 2); //wheels is 2, everything else is default value copy.printVehicle(); CreateVehicle(copy, 2, 3); //wheels is 2, doors is 3

copy.printVehicle();

copy = secondCopy;

copy.printVehicle(); // copy is same as second copy

return 0; }

CST8219 - C++ Programming Lab 5 1. Implement the assignment operator: operator=(Vehicle &) This should make the numWheels and numDoors equal to those of the object that are being passed in. It is similar to a copy constructor, only now you are not initializing memory. Don't forget that the return type of the function should be Vehicle& so that you can write something like: veh1 = veh2 = veh3 = veh4; This makes veh3 = veh4, but then returns veh4 so that it is used for the next assignment: veh2 = veh4; Also, veh4 shouldn't change, so make the Vehicle parameter to be a const object. 2. Implement the comparison operator: operator==(const Vehicle &) This function should return true if the numDoors and numWheels are both equal to the parameter's variables. 3. Implement the inequality operator: operator!=(const Vehicle&). This should just return the negation of the comparison operator of step #3. 4. Implement the prefix and postfix increment and decrement operators: a. operator++0) b. operator++(int i) C. operator--( ) d. operator--(int i) For a Vehicle, you should implement increment so that all of the variables are incremented by 1. So Vehicle(2, 2) would be incremented to: Vehicle(3, 3) Don't forget that postfix increment returns copy of the original values before incrementing. So Vehicle veh(4, 2); veh++; would make veh = (5,3), but return Vehicle(4, 2) 5. Implement the output operator: ostream& operator

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!