Question

Use appropriate constructors to initialize objects and demonstrate the use of both default and parameterized constructors in your program. Make assumptions, if necessary

07 Aug 2026
Answer :
Word Count : 989
Constructors are special member functions of a C++ class that are automatically invoked when an object of the class is created. They are mainly used to initialize the data members of an object. A constructor has the same name as the class and does not have a return type, not even `void`. C++ supports different types of constructors, among which default and parameterized constructors are commonly used. A default constructor initializes an object without receiving any arguments, whereas a parameterized constructor receives arguments and initializes an object with specific values. The following C++ program demonstrates the use of both default and parameterized constructors. The program assumes a `Student` class containing three data members: student name, roll number, and marks. ```cpp #include #include using namespace std; class Student { private: string name; int rollNo; float marks; public: // Default constructor Student() { name = "Unknown"; rollNo = 0; marks = 0.0; } // Parameterized constructor Student(string n, int r, float m) { name = n; rollNo = r; marks = m; } // Function to display student details void display() { cout << "Name: " << name << endl; cout << "Roll Number: " << rollNo << endl; cout << "Marks: " << marks << endl; cout << "------------------------" << endl; } }; int main() { // Object created using default constructor Student student1; // Object created using parameterized constructor Student student2("Rahul", 101, 85.5); // Another object using parameterized constructor Student student3("Priya", 102, 91.0); cout << "Details of Student 1:" << endl; student1.display(); cout << "Details of Student 2:" << endl; student2.display(); cout << "Details of Student 3:" << endl; student3.display(); return 0; } ``` In this program, the `Student` class contains three private data members: `name`, `rollNo`, and `marks`. These members represent the basic information associated with a student. The class also contains two constructors and one member function named `display()`. The first constructor is the default constructor: ```cpp Student() { name = "Unknown";
________ ________ __________ ________ ________ __________ ____ ___ ________ _______ ____ __________.
_________ ______ _______ ______ _____ _____ _________ _________ _____ ______ ______.
_____ _________ _______ _______ _________ ________ _______.
__________ ________ ________ _______ __________.
_______ ______ ______ ______ ___.
_____ _______ ________ ___ _________ __________ _________ ________ ______ ______.
_________ ___ ___ __________ _________ ________ _______.
_______ __________ ________ ________ ___ ___ ____ ______ ________.
__________ ______ ____ _________ ___ _________ ____ _____ ____ _________ ____ ______.
____ ______ _____ ____ ______ __________ ____ ________ ___.
___ __________ ___ _____ _______ _______.
______ ___ __________ ___ ___ _________ _______ ________.
___ ___ __________ ___ ____ ________ ____ __________ ___ ___.
_____ _______ _______ _______ ______.
______ ________ ______ _______ ________ _____ _______ _________ _______.
____ ___ ___ ___ ________ ______ _______ ______ __________ _________.
_____ _____ __________ __________ _____.
______ ______ _______ ______ ______.
____ ____ _____ _____ ______ ________.
__________ ___ ______ _____ ___ ______ __________ ___.
__________ ___ ____ _____ ____ _________ _________ __________ _____ _________ ____.
____ __________ ______ ___ __________ ______ ___ ______ ________ ______ _______.
__________ ________ __________ __________ ___ ___ _________ ___ _______.
______ __________ ___ _____ ________ ______ _________ ________ _________ __________ ____ _________.
___ ____ ____ ___ __________ ____ ________.
_______ _____ _______ ______ ___ ___.
____ _____ ________ __________ ________.
______ __________ ____ __________ ______ ____ _________ _________ _________ _______ _______.
_______ ______ ___ ________ _________.
_________ ________ _________ ______ ________ ______ ________ _________ ___.
_____ ___ _____ ______ _______.
___ _______ ____ ___ ______ _____ ______ ____ ___ ___ ____ _______.
_______ ___ _______ __________ _______ ________ ___ ______ ________ _________.
__________ _______ ________ ____ _____ _______.
___ _________ _________ _____ _______ ___ _______ _______ ______.
_______ __________ _______ ______ ________ _________ ________ _____ _____ _________ ____.
_______ _____ _________ ________ ____ _____.
_____ __________ ______ ________ _______ _______.
____ ___ _______ _____ _________ ___.
___ ______ _________ ___ _________ ________ __________ _____.
_______ __________ ____ __________ ______ _______ _____.
_______ _____ _________ ______ __________ __________ _______ _______.
_____ ___ ____ _________ ______ __________ ______ _______ ______ _____ __________ _____.
____ ______ ________ __________ ______ __________ _____.
_____ ______ ____ __________ __________ ________ __________ __________ ______ ______ ____ _______.
__________ ___ _________ ______ _________ ___ ____ __________ ___ ____.
_____ ________ _____ _______ _________ _______ _________ _______ ___.
________ _____ _________ __________ _____.
__________ ________ _______ ______ ______ ___ __________ _________ __________ ___.
_____ _____ __________ ____ _________ __________ _________ ______ _________ _________ _______.
____ _________ _________ _____ ____ _______ ____ _______ _____ ___ ______ ________.
______ _______ ________ ____ ___ __________ _________ ________ ___ _____ ___.
______ ____ __________ ___ ______ __________ ____ _______ _____ ________ _______ ____.
___ _____ _____ ______ _________ ___ ________.
________ _________ _________ ________ _______ ________ ___ _______ _____ _________ ________ _____.
____ ______ _______ _________ _____ ______ ______ ________ _________.
__________ _____ _________ ____ _____ _______.
_____ ______ _____ __________ ____ _______ __________ __________ __________ __________.
________ _______ ________ ________ _________ ___ ________ ______ ________ ____ ___.
____ ________ _____ ______ ________.
______ ________ _________ __________ ____ ________ _________ __________ ______ ___ _____ _______.
____ __________ ____ _______ ________ _____ _______ ___ ________ ________ __________ __________.
______ _________ _______ _______ _____ ___ ____ _____ __________.
______ ___ _____ _________ _____ ______ ____ __________ _______ __________.
______ _______ ________ ____ __________ _______.
__________ _____ __________ _______ __________ ______ ______ __________ ________ _________ _________ __________.
_____ _______ __________ ________ __________.
___ _________ __________ _____ _____ __________ _____ _________.
____ _____ _____ _______ __________ ___.
_______ _______ ________ __________ ________ ___ ___ ___ ________ _____ __________.
_________ ________ _________ ________ _____ _________ _____ ________ __________.
_____ ________ ________ ____ ___ _______.
______ ____ __________ ______ ________ _____ ______ ____ _____ _________ _________.
___ _____ ____ _______ __________ ___ _________ ________.
_______ _________ _______ ______ ________ __________ ___.
______ __________ _______ ________ ________ ___ ______ ____ _____ __________ ________.
_________ __________ ___ ___ _____ _____ ________ _______ _________ _______.
IGNOU ACADEMY
Your IGNOU journey, made easier.
  • Solved Assignments
  • Study Notes
  • Guess Papers
  • Question Papers
Skip in 10
Top
📞
Call Support Instant phone assistance IGNOU BCSL 32 2026 2027 - Use appropriate constructors to initialize objects and demonstrate the | IGNOU Academy
→
🟢
WhatsApp Chat Fast live messaging
→
Email Us Business enquiries & support
→