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

Popular posts from this blog

153: Write a program to read an amount (integer value) and break the amount into smallest possible number of bank notes. Note: The possible banknotes are 500, 100, 50, 20, 10, 5, 2, and 1

206: Write a program to create a class named "Circle" which has the property "radius". Define functions to calculate the area and circumference of the circle.

221: // In Task 2, we discussed multilevel inheritance with parameterized constructors for Student, UndergraduateStudent, and GraduateStudent classes in a university management system. Can you explain the advantages of using multilevel inheritance with specific details about the functions and data members in these classes? How were the parameterized constructors (e.g., setting student name, age, and ID) used to ensure that each class in the hierarchy correctly initializes its properties, such as creating an UndergraduateStudent named "John," aged 20, with a student ID of 12345