Instructions:
Define a Person class with the following class variables string firstName, lastName and address. The default constructor should set them all to the empty string. It should have setters and getters for each variable.
Create a Car class that has the private variables string make, string color, int year. It should also have driver that is a pointer to a Person. It should have a default constructor that creates a default person and sets the other variables to a Black, 1910, Ford.
You should setters and getters for all variables, including a setDriver method that takes a firstName, lastName, and Address and updates the driver to those values (note, this does not create a new driver, it simply updates the existing driver).
Finally, create an overloaded = operator (assignment), copy constructor, and << operator (insertion). The insertion operator should return “year color make driven by firstname space lastname of address”. The assignment and insertion should both be implemented as friends.
First test them with your own main program, after you have them using, se the provided driver to show that your classes properly work.
I posted my car.hpp
file below. I have my Person
class done, I don't need help with that part.
I am mostly just confused by:
the
setDriver()
method, am I getting input from user? I don't understand what the instructions are saying. How do I update the driver without creating a new driver?the copy constructor. I literally have no idea where to start with the
setDriver()
method. I did my best with the copy constructor. I also am not sure if I did the default constructer correctly.
Before anyone gets upset, no you do not "need to do my homework for me", I am just simply asking for advice and your knowledge on these subjects, as I have very, very little knowledge myself.
This is my car.hpp
file, where most of the code is, this is all I have so far:
class Car
{
Person * driver;
std::string make;
std::string color;
int year;
public:
Car(std::string black, std::string Ford) : make(Ford), color(black), year(1910){driver = new Person;}
Car(const Car &other) : make(other.make), color(other.color), year(other.year){this->driver = new std::string();}
~Car();
void setMake(std::string make2){this->make = make2;}
void setColor(std::string color2){this->color = color2;}
void setYear(int year2){this->year = year2;}
void setDriver(){};
const std::string getMake(){return make;}
const std::string getColor(){return color;}
const int getYear(){return year;}
Car & operator=(Car const & other)
{
*(driver) = *(other.driver);
}
bool operator>(Car const & other)
{
return *(driver) > *(other.driver)
}
};