Please code by C++ The required week4.cpp file code is below and dividesthe code into week4.cpp Vehicle.cpp
Question:
Please code by C++
The required week4.cpp file code is below and dividesthe code into week4.cpp Vehicle.cpp Vehicle.h
Please ask if you have any questions
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. Dont 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 shouldnt change, so make the Vehicle parameter to be aconstobject.
Implement the comparison operator:operator==(const Vehicle &)
This function should return true if the numDoors and numWheels are both equal to the parameters variables.
Implement the inequality operator:operator!=(const Vehicle&).This should just return the negation of the comparison operator of step #
Implement the prefix and postfix increment and decrement operators:
operator++()
operator++(int i)
operator--( )
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)
Dont forget that postfix increment returns a copy of the original values before incrementing. So
Vehicle veh(4, 2); veh++; would make veh = (5, 3), but return Vehicle(4, 2)
Implement the output operator: ostream& operator(>
You should declare the output operator as a friend of the Vehicle class and directly access the private variables of the Vehicle class when writing them to the stream.
Change your main function so that it looks like this:
int main(int argc, char **argv)
{
Vehicle original;
Vehicle copy(original); // copy constructor by reference
cout
cout
cout
cout
cout
// should be true:
cout
//should be false:
cout
//should be true:
cout
//This should make original = copy, and then return a Vehicle for output:
cout
return 0;
}
Week4.cpp:
#include | |
using namespace std; | |
class Fraction { | |
int numerator, denominator; | |
public: | |
Fraction(int n, int d) { | |
setNumerator(n); | |
setDenominator(d); | |
} | |
void setNumerator(int n){ numerator = n; } | |
int getNumerator(void) { return numerator; } | |
void setDenominator(int d) { denominator = d; } | |
int getDenominator(void) { return denominator; } | |
float asFloat(void) { | |
return (float)getNumerator() / getDenominator(); | |
} | |
}; | |
void printFraction(Fraction f) | |
{ | |
cout | |
} | |
int main() | |
{ | |
Fraction f(5, 1); | |
printFraction(f); | |
return 0; | |
} |
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill