Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

Questions on Classes

1. Class Definition: Create a C++ program that defines a class named Vehicle with public
member variables for make, model, and year. It should include a constructor to initialize
these values.
2. Member Functions: Enhance the Vehicle class by adding member functions for setting
and getting each of the member variables, with names like setMake, getMake, and so on.
3. Display Function: Implement a function called displayInfo within the Vehicle class that
outputs the make, model, and year of the vehicle to the console.
4. Default Constructor: Update the Vehicle class to include a default constructor that sets
the make and model to "Unknown" and the year to 0.
5. Overloading Constructors: Add an overloaded constructor to the Vehicle class enabling
initialization of a vehicle object with just the make and model, defaulting the year to
2022.
6. Private Members: Modify the make, model, and year member variables of the Vehicle
class to be private, ensuring the member functions still function correctly.
7. Static Member Variable: Introduce a static member variable in the Vehicle class to
keep count of the total number of Vehicle objects created, and display this count in the
displayInfo function.
8. Destructor: Implement a destructor in the Vehicle class that outputs a message
indicating a Vehicle object has been destroyed.
Questions on Inheritance
1. Basic Inheritance: Define a Car class that inherits from the Vehicle class, including a
member variable for numberOfDoors, and demonstrate inheritance by creating an
instance of Car.
2. Constructor Inheritance: Update the Car class to feature a constructor that initializes
both the Vehicle attributes and numberOfDoors.
3. Function Overriding: Add a displayInfo function to the Car class that overrides the
Vehicle's displayInfo function to display vehicle information including numberOfDoors.
4. Protected Members: Change the make, model, and year member variables in the
Vehicle class to protected and discuss how this alteration impacts the Car class.
5. Multiple Inheritance: Create an Engine base class with member variables for
horsepower and cylinderCount, and then demonstrate multiple inheritance by defining a
SportsCar class that inherits from both Vehicle and Engine.
6. Virtual Base Classes: Explain the concept of a virtual base class in C++ and illustrate it
by making Vehicle a virtual base class for two new classes, Truck and Bus, which then
serve as base classes for a new class named SchoolBus.
7. Abstract Classes and Pure Virtual Functions: Transform the Vehicle class into an
abstract class by adding at least one pure virtual function, and explain how this
modification affects its derived classes.
8. Accessing Overridden Functions: In the Car class, implement a function that invokes
the displayInfo function from the Vehicle base class, in addition to its own overridden
displayInfo.

You might also like