write in C++ program and write an accessor that returns the value of the Car class’s make private member variable.
Given the following class definition:
class Car
{
public:
Car() : make {}, model {}, year {} {}
Car(std::string make, std::string model, int year) :
make {make},
model {model}
year {year}
{
}
private:
std::string make;
std::string model;
int year;
};
string getMake() { return make; }
#include <iostream> #include <string> using namespace std; class Car { public: Car() : make{}, model{}, year{} {} Car(std::string make, std::string model, int year) : make{make}, model{model}, year{year} { } string getMake() { return make; } private: std::string make; std::string model; int year; }; int main() { Car car("Ferrari", "F1", 2020); cout << car.getMake() << endl; return 0; }
Get Answers For Free
Most questions answered within 1 hours.