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

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

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.

212: Build a class representing a university student with private data members for name, ID, and a static data member for the total number of students. Implement getter and setter functions for name and ID, and a static getter function to retrieve the total number of students. Use default constructors