Question
C++ please :) Define a Person class with the following class variables string firstName, lastName and address. The default constructor should set them all to
C++ please :)
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.
This is my Car.hpp file where majority of the code is going, this is all I have so far and am stuck:
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)
}
};
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started