Question
Use appropriate constructors to initialize objects and demonstrate the use of both default and parameterized constructors in your program. Make assumptions, if necessary
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 _________ _________ ____ ___ ____ ____ _______ _____ _____ _____ ___ ___.
_________ ______ _________ ______ ________.
__________ __________ _____ ______ __________ ______ __________ ______ _______.
__________ _____ _____ ______ _________.
______ _______ ______ ___ ____ ________ ___ __________.
____ _____ _____ _________ ________ __________ _________ __________ _______.
______ ______ _______ _____ _________.
________ _______ ____ _____ ______ ______ _____ ____ _____ ____.
_____ __________ _______ _____ ________ _________ _________.
__________ __________ ______ _______ ______ __________ _________ _______ __________.
_________ _____ _____ __________ ______ ___ ______ __________ _____ ___ _____ _______.
________ __________ __________ ________ ____ ______ ____ __________.
____ _______ _______ _____ __________ ___ ____ _______ ____ ________ ___ ____.
___ _________ _____ ___ _____ _____ ___ _____ _________ _________ _________ _________.
__________ ___ ____ _________ _____ ____ ___.
______ _____ _____ ________ _________ _______.
______ ___ ________ ______ ________ ______.
_________ _____ ________ _____ ____ ________ _____ ___ _____ _____.
_____ ____ __________ ________ ___ ________ ________ _____ _________ _____ _____.
______ _______ _______ __________ ______ _______ _____ ____ ____.
_______ ________ ___ _________ ______ ______ _________ ________.
__________ _____ ____ ______ ___ _________ _____ _____ _____.
___ ____ ________ ______ ________ ____.
_____ __________ ______ ____ __________ ______ ________ _______ _____ ________ ________.
________ _____ _____ ___ ________ _____ ______ ____.
_____ _____ ____ __________ _________ ____ _________.
__________ ______ _______ ___ _____ ______.
__________ ___ ___ ________ ________ _____.
________ _______ _______ _________ __________ ___ ______ ______.
________ __________ ____ _____ _________ _____ ____ ___ __________ _____.
_________ _________ _____ ______ __________ ______ _____ _________.
_______ ________ _____ _________ __________ _______ _______ _______ ______ _________.
____ _______ _________ __________ ___ __________ _________ _________.
_________ _________ _____ __________ _____ _________ __________ _______ _________ _____ ______ ________.
________ __________ _________ ________ ________.
________ ________ ____ _________ _______ _______ ___ _________ ____ _________.
______ ______ ________ ___ ______ ______ ______ ________ ___ ________.
__________ ___ ____ ________ ______ __________ ______ __________ ____ _____ _____.
__________ _________ _____ ______ ___ ___ _______ _______ ______ _____ _____ _________.
_________ _____ _________ __________ _________.
____ ________ _________ _________ ______ _________ ____ _______ ___ _________ ______ _________.
_________ __________ _________ ____ _____ ___ _______ ____.
____ _____ _________ _________ ________ _______ ________ ___ ________.
____ ___ ______ _________ _______ ________ __________ _______ ___ ____ __________ __________.
_________ ____ ________ _______ ___ _____ _______ ______ _______ _____ ______ _________.
_________ _________ _______ __________ ________ ____ ___ __________ _____ ____.
_________ _____ _____ _____ ___ ____ __________ ____ _______ ____ ______ ____.
___ _________ _________ ________ _______ __________ __________ ____ ___ _________.
__________ _________ ___ __________ ____ _________ ____ ______ _________.
___ _______ _______ ______ _________ _________ ____ ______ _____.
______ _____ _________ _______ _______ ____ _____ ______.
__________ _______ __________ _____ _______.
____ _________ _________ ___ _______ _____ ___ _______ ____ __________ _____ ______.
____ ________ __________ ___ ________ _________ __________ ___ _____ ___ _____.
_____ ________ ___ ________ ______ _________ ____.
_________ __________ ___ ________ _________ _______ __________ __________ ____ ________ _____.
_____ ________ ___ _____ ________ _________ _____.
_____ __________ _______ ______ _______.
_____ __________ ________ ______ ________.
______ __________ __________ ____ ____.
__________ _____ ______ ____ _____ ___ __________ __________ ________ ___.
__________ ___ _________ _____ ________ ________ ___ ____ ___ ___ _________ __________.
_________ ____ _____ ____ __________ ______ _____.
__________ ___ _____ ____ ______ __________ __________ __________ _____ ___ ____ ______.
_______ _________ __________ __________ ______ ___ ________ _____ ___.
________ _____ _________ _________ ____.
_________ _________ __________ _____ __________ __________ ___ ______ _____ __________.
___ _______ ________ _____ ___ ______ _______ _____ __________ ___.
_____ _________ _____ ____ _________ ______ _______.
__________ _______ ______ _____ _________ __________ _____.
______ ___ ___ ______ __________ ________ ____.
__________ __________ ________ _______ ___ ___ __________.
_______ __________ ___ __________ ____ _______ _______ __________ _________ __________ ________.
________ _____ ______ _____ ___ ________ ____.
________ ___ _______ _____ _____ ______ ____ _________ __________ _____.
_____ ________ ___ ____ ________ __________ _____ _____ ___ _____.
_______ _________ ________ ____ ___ ________ _________ ______ _____ __________ ______ __________.
____ ___ ____ _________ ________ _______ ________ ____ _____ ___.
_________ _____ _________ ____ ______.
________ ______ ___ ______ _______ _______ ____ _______.
_____ __________ _______ _____ ____ ___ __________ ____ ____ __________ _______.
__________ _____ __________ _____ _____ ____ ___.
_________ _______ _____ _____ _________ ______ ______ ________ ____ _______ _______ ________.
__________ _______ _________ ____ _________ _____.
____ _________ ____ ______.
Get Full Answer on WhatsApp
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
_________ ______ _________ ______ ________.
__________ __________ _____ ______ __________ ______ __________ ______ _______.
__________ _____ _____ ______ _________.
______ _______ ______ ___ ____ ________ ___ __________.
____ _____ _____ _________ ________ __________ _________ __________ _______.
______ ______ _______ _____ _________.
________ _______ ____ _____ ______ ______ _____ ____ _____ ____.
_____ __________ _______ _____ ________ _________ _________.
__________ __________ ______ _______ ______ __________ _________ _______ __________.
_________ _____ _____ __________ ______ ___ ______ __________ _____ ___ _____ _______.
________ __________ __________ ________ ____ ______ ____ __________.
____ _______ _______ _____ __________ ___ ____ _______ ____ ________ ___ ____.
___ _________ _____ ___ _____ _____ ___ _____ _________ _________ _________ _________.
__________ ___ ____ _________ _____ ____ ___.
______ _____ _____ ________ _________ _______.
______ ___ ________ ______ ________ ______.
_________ _____ ________ _____ ____ ________ _____ ___ _____ _____.
_____ ____ __________ ________ ___ ________ ________ _____ _________ _____ _____.
______ _______ _______ __________ ______ _______ _____ ____ ____.
_______ ________ ___ _________ ______ ______ _________ ________.
__________ _____ ____ ______ ___ _________ _____ _____ _____.
___ ____ ________ ______ ________ ____.
_____ __________ ______ ____ __________ ______ ________ _______ _____ ________ ________.
________ _____ _____ ___ ________ _____ ______ ____.
_____ _____ ____ __________ _________ ____ _________.
__________ ______ _______ ___ _____ ______.
__________ ___ ___ ________ ________ _____.
________ _______ _______ _________ __________ ___ ______ ______.
________ __________ ____ _____ _________ _____ ____ ___ __________ _____.
_________ _________ _____ ______ __________ ______ _____ _________.
_______ ________ _____ _________ __________ _______ _______ _______ ______ _________.
____ _______ _________ __________ ___ __________ _________ _________.
_________ _________ _____ __________ _____ _________ __________ _______ _________ _____ ______ ________.
________ __________ _________ ________ ________.
________ ________ ____ _________ _______ _______ ___ _________ ____ _________.
______ ______ ________ ___ ______ ______ ______ ________ ___ ________.
__________ ___ ____ ________ ______ __________ ______ __________ ____ _____ _____.
__________ _________ _____ ______ ___ ___ _______ _______ ______ _____ _____ _________.
_________ _____ _________ __________ _________.
____ ________ _________ _________ ______ _________ ____ _______ ___ _________ ______ _________.
_________ __________ _________ ____ _____ ___ _______ ____.
____ _____ _________ _________ ________ _______ ________ ___ ________.
____ ___ ______ _________ _______ ________ __________ _______ ___ ____ __________ __________.
_________ ____ ________ _______ ___ _____ _______ ______ _______ _____ ______ _________.
_________ _________ _______ __________ ________ ____ ___ __________ _____ ____.
_________ _____ _____ _____ ___ ____ __________ ____ _______ ____ ______ ____.
___ _________ _________ ________ _______ __________ __________ ____ ___ _________.
__________ _________ ___ __________ ____ _________ ____ ______ _________.
___ _______ _______ ______ _________ _________ ____ ______ _____.
______ _____ _________ _______ _______ ____ _____ ______.
__________ _______ __________ _____ _______.
____ _________ _________ ___ _______ _____ ___ _______ ____ __________ _____ ______.
____ ________ __________ ___ ________ _________ __________ ___ _____ ___ _____.
_____ ________ ___ ________ ______ _________ ____.
_________ __________ ___ ________ _________ _______ __________ __________ ____ ________ _____.
_____ ________ ___ _____ ________ _________ _____.
_____ __________ _______ ______ _______.
_____ __________ ________ ______ ________.
______ __________ __________ ____ ____.
__________ _____ ______ ____ _____ ___ __________ __________ ________ ___.
__________ ___ _________ _____ ________ ________ ___ ____ ___ ___ _________ __________.
_________ ____ _____ ____ __________ ______ _____.
__________ ___ _____ ____ ______ __________ __________ __________ _____ ___ ____ ______.
_______ _________ __________ __________ ______ ___ ________ _____ ___.
________ _____ _________ _________ ____.
_________ _________ __________ _____ __________ __________ ___ ______ _____ __________.
___ _______ ________ _____ ___ ______ _______ _____ __________ ___.
_____ _________ _____ ____ _________ ______ _______.
__________ _______ ______ _____ _________ __________ _____.
______ ___ ___ ______ __________ ________ ____.
__________ __________ ________ _______ ___ ___ __________.
_______ __________ ___ __________ ____ _______ _______ __________ _________ __________ ________.
________ _____ ______ _____ ___ ________ ____.
________ ___ _______ _____ _____ ______ ____ _________ __________ _____.
_____ ________ ___ ____ ________ __________ _____ _____ ___ _____.
_______ _________ ________ ____ ___ ________ _________ ______ _____ __________ ______ __________.
____ ___ ____ _________ ________ _______ ________ ____ _____ ___.
_________ _____ _________ ____ ______.
________ ______ ___ ______ _______ _______ ____ _______.
_____ __________ _______ _____ ____ ___ __________ ____ ____ __________ _______.
__________ _____ __________ _____ _____ ____ ___.
_________ _______ _____ _____ _________ ______ ______ ________ ____ _______ _______ ________.
__________ _______ _________ ____ _________ _____.
____ _________ ____ ______.
Get Full Answer on WhatsApp
IGNOU NEWS
Assignment Submission Last Date Extended Till 30 June 2026 Click Here★★★IGNOU June 2026 TEE Date Sheet Released Click Here★★★