210: Create a class representing a car with private data members for company, model, and year. Implement member functions outside the class to set and get these attributes. Use constructor overloading to allow the creation of car objects with default, partial, or full information
// Create a class representing a car with private data members for company, model,
// and year. Implement member functions outside the class to set and get these
// attributes. Use constructor overloading to allow the creation of car objects with
// default, partial, or full information
#include <iostream>
using namespace std;
class Car
{
private:
const string company, model;
const unsigned int year;
public:
Car();
Car(string, string, int);
void getData();
};
Car ::Car() : company(""), model(""), year(0) {}
Car ::Car(string x, string y, int z) : company(x), model(y), year(z) {}
void Car ::getData()
{
cout << "Company: " << company << endl
<< "Model: " << model << endl
<< "Year: " << year << endl;
}
int main()
{
Car c1;
c1.getData();
cout << endl;
Car c2("Toyota", "Corolla", 2015);
c2.getData();
return 0;
}
Comments
Post a Comment