Official CBSE Assignments for Class 12 Computer Science
Access comprehensive school assignments for Constructors And Destructors Concepts using the CBSE Class 12 Computer Science Constructors And Destructors Concepts. Designed to align with the 2026-27 CBSE academic guidelines, these practice sets help Class 12 Computer Science students reinforce core concepts and improve their problem-solving accuracy.
Solved Practice Assignments for Computer Science
Navigate directly to the solved Computer Science assignments using the digital viewer below. Each practice set includes detailed step-by-step solutions, allowing students to instantly cross-check their work and identify areas requiring further revision.
CONSTRUCTORS
CONSTRUCTORS :
A member function with the same as its class is called Constructor and it is used to initialize the object of that class with a legal initial value.
Example :
class Student
{
int rollno;
float marks;
public:
student( ) //Constructor
{
rollno=0;
marks=0.0;
}
//other public members
};
TYPES OF CONSRUCTORS:
1. Default Constructor: A constructor that accepts no parameter is called the Default Constructor. If you don't declare a constructor or a destructor, the compiler makes one for you. The default constructor and destructor take no arguments and do nothing.
2. Parameterized Constructors: A constructor that accepts parameters for its invocation is known as parameterized Constructors , also called as Regular Constructors.
Copy Constructor
• A copy constructor is a special constructor in the C++ programming language used to create a new object as a copy of an existing object.
• A copy constructor is a constructor of the form classname(classname &).The compiler will use the copy constructors whenever you initialize an instance using values of another instance of the same type.
• Copying of objects is achieved by the use of a copy constructor and a assignment operator.
Example :
class Sample{ int i, j;}
public:
Sample(int a, int b) // constructor
{ i=a;j=b;}
Sample (Sample & s) //copy constructor
{ j=s.j ; i=s.j;
Cout <<”\n Copy constructor working \n”;
}
void print (void)
{cout <<i<< j<< ”\n”;}
:
};
CONSTRUCTORS :
A member function with the same name as its class is called a Constructor, and it is used to initialize the object of that class with a legal initial value.
Example :
class Student
{
int rollno;
float marks;
public:
student( ) //Constructor
{
rollno=0;
marks=0.0;
}
//other public members
};
TYPES OF CONSTRUCTORS:
1. Default Constructor:
A constructor that accepts no parameters is called the Default Constructor. If you don't declare a constructor or a destructor, the compiler makes one for you. The default constructor and destructor take no arguments and do nothing.
2. Parameterized Constructors:
A constructor that accepts parameters for its invocation is known as a Parameterized Constructor, also called a Regular Constructor.
DESTRUCTORS:
- A destructor is also a member function whose name is the same as the class name but is preceded by a tilde (~). It is called automatically by the compiler when an object is destroyed. Destructors are usually used to deallocate memory and do other cleanup for a class object and its class members when the object is destroyed.
- A destructor is called for a class object when that object passes out of scope or is explicitly deleted.
Example :
class TEST
{
int Regno, Max, Min, Score;
Public:
TEST( ) // Default Constructor
{ }
TEST (int Pregno, int Pscore) // Parameterized Constructor
{
Regno = Pregno; Max = 100; Min = 40; Score = Pscore;
}
~ TEST ( ) // Destructor
{ cout << "TEST Over" << endl; }
};
The following points apply to constructors and destructors:
- Constructors and destructors do not have a return type, not even void, nor can they return values.
- References and pointers cannot be used on constructors and destructors because their addresses cannot be taken.
- Constructors cannot be declared with the keyword virtual.
- Constructors and destructors cannot be declared static, const, or volatile.
- Unions cannot contain class objects that have constructors or destructors.
- The compiler automatically calls constructors when defining class objects and calls destructors when class objects go out of scope.
- Derived classes do not inherit constructors or destructors from their base classes, but they do call the constructor and destructor of base classes.
- The default destructor calls the destructors of the base class and members of the derived class.
- The destructors of base classes and members are called in the reverse order of the completion of their constructor.
- The destructor for a class object is called before destructors for members and bases are called.
Copy Constructor
- A copy constructor is a special constructor in the C++ programming language used to create a new object as a copy of an existing object.
- A copy constructor is a constructor of the form classname(classname &). The compiler will use the copy constructor whenever you initialize an instance using values of another instance of the same type.
- Copying of objects is achieved by the use of a copy constructor and an assignment operator.
Example :
class Sample
{
int i, j;
public:
Sample(int a, int b) // constructor
{
i = a; j = b;
}
Sample (Sample & s) // copy constructor
{
j = s.j; i = s.i;
cout << "\n Copy constructor working \n";
}
void print (void)
{
cout << i << j << "\n";
}
};
Note : The argument to a copy constructor is passed by reference. The reason is that when an argument is passed by value, a copy of it must be constructed. But creating this copy would invoke the copy constructor again, leading to an infinite recursive chain of calls until the compiler runs out of memory. Therefore, the argument in a copy constructor must always be passed by reference.
The following cases may result in a call to a copy constructor:
1. When an object is passed by value to a function:
The pass-by-value method requires a copy of the passed argument to be created for the function to operate upon. Thus, to create the copy of the passed object, the copy constructor is invoked.
If a function has the following prototype:
void cpyfunc(Sample s); // Sample is a class
then for the following function call:
cpyfunc(obj1); // obj1 is an object of Sample type
the copy constructor would be invoked to create a copy of the obj1 object for use by cpyfunc().
2. When a function returns an object:
When an object is returned by a function, the copy constructor is invoked.
Sample cpyfunc(); // Sample is a class and return type of cpyfunc()
If function cpyfunc() is called by the following statement:
obj2 = cpyfunc();
Then the copy constructor would be invoked to create a copy of the value returned by cpyfunc(), and its value would be assigned to obj2. The copy constructor creates a temporary object to hold the return value of a function returning an object.
1 & 2 Marks Solved Problems :
Question Q1. Answer the questions after going through the following class.
class Exam
{
char Subject[20];
int Marks;
public:
Exam() // Function 1
{ strcpy(Subject, "Computer"); Marks = 0; }
Exam(char P[]) // Function 2
{ strcpy(Subject, P); Marks = 0; }
Exam(int M) // Function 3
{ strcpy(Subject, "Computer"); Marks = M; }
Exam(char P[], int M) // Function 4
{ strcpy(Subject, P); Marks = M; }
};
(a) Which feature of Object Oriented Programming is demonstrated using Function 1, Function 2, Function 3, and Function 4 in the above class Exam?
(b) Write statements in C++ that would execute Function 3 and Function 4 of class Exam.
Answer:
(a) Function Overloading (specifically Constructor Overloading).
(b) Exam a(10); (executes Function 3) and Exam b("Comp", 10); (executes Function 4).
In simple words: Multiple constructors with different parameter lists are defined in the same class, which is called constructor overloading.
Exam Tip: Identify constructor overloading by checking if multiple constructors exist with the same name but different signatures (number or types of parameters).
Question Q2. Consider the following declaration:
class welcome
{
public:
welcome(int x, char ch); // constructor with parameter
welcome(); // constructor without parameter
void compute();
private:
int x;
char ch;
};
Which of the following are valid statements?
1. welcome obj(33, 'a9');
2. welcome obj1(50, '9');
3. welcome obj3();
4. obj1 = welcome(45, 'T');
5. obj3 = welcome;
Answer:
1. welcome obj(33, 'a9'); - Valid (Note: 'a9' is a multi-character constant in C++ which takes the last character, but syntactically the declaration matches the parameterized constructor).
2. welcome obj1(50, '9'); - Valid.
3. welcome obj3(); - Invalid (This gets parsed as a function declaration instead of object instantiation, known as the most vexing parse).
4. obj1 = welcome(45, 'T'); - Valid (Creates an explicit temporary object and assigns it).
5. obj3 = welcome; - Invalid (Missing parentheses and arguments for constructor invocation).
In simple words: Object creation requires correct constructor signatures without triggering function declaration ambiguities.
Exam Tip: Be careful with empty parentheses during object creation like welcome obj3(); as the compiler treats it as a function declaration.
2 Marks Practice Problems
Question Q1. What do you understand by constructor and destructor functions used in classes? How are these functions different from other member functions?
Answer:
Constructor: A special member function with the same name as the class, automatically called when an object is created, used to initialize object data members.
Destructor: A special member function preceded by a tilde (~) symbol with the class name, automatically called when an object goes out of scope, used to release resources.
Differences from other member functions:
1. Constructors and destructors do not have any return type (not even void).
2. They are called automatically by the compiler upon object creation and destruction, whereas normal member functions must be explicitly called using the dot operator.
In simple words: Constructors set up an object when born, destructors clean up when it dies, and unlike normal functions, they have no return types and run automatically.
Exam Tip: Mention the automatic invocation and lack of return types to secure full marks.
Question Q2. What do you understand by default constructor and copy constructor functions used in classes? How are these functions different from normal constructors?
Answer:
Default Constructor: A constructor that accepts no arguments (either defined with empty parameters or default arguments for all parameters).
Copy Constructor: A constructor of the form class_name (const class_name &) used to initialize a new object using an existing object of the same class.
Difference from normal (parameterized) constructors:
Normal constructors take custom user-defined arguments to initialize data members with specific values, whereas a default constructor requires no arguments, and a copy constructor takes a reference to an existing object of the same class.
In simple words: Default constructors take no arguments, copy constructors take an existing object of the same class to clone it, and normal constructors take custom parameters.
Exam Tip: Always emphasize that copy constructors must take their argument by reference to avoid infinite recursion.
Question Q3. Given the following C++ code, answer the questions (i) & (ii).
class TestMeOut
{
public:
~TestMeOut() // Function 1
{ cout << "Leaving the examination hall " << endl; }
TestMeOut() // Function 2
{ cout << "Appearing for examination " << endl; }
void MyWork() // Function 3
{ cout << "Attempting Questions " << endl; }
};
(i) In Object Oriented Programming, what is Function 1 referred as and when does it get invoked / called?
(ii) In Object Oriented Programming, what is Function 2 referred as and when does it get invoked / called?
Answer:
(i) Function 1 is a Destructor. It gets invoked automatically by the compiler when the object goes out of scope or is destroyed.
(ii) Function 2 is a Default Constructor. It gets invoked automatically by the compiler when an object of the class is created.
In simple words: Function 1 is the destructor called at object destruction, and Function 2 is the default constructor called at object creation.
Exam Tip: Look for the tilde symbol (~) to instantly identify a destructor.
Free study material for Computer Science
Download Practice Assignments: Class 12 Computer Science Constructors And Destructors Concepts
Revision Assignment: Constructors And Destructors Concepts (CBSE)
Access structured practice assignments for Constructors And Destructors Concepts designed in alignment with the latest CBSE curriculum for Class 12 Computer Science. These printable sets cover objective and descriptive problem types to support thorough revision.
Why Practice Class 12 Computer Science Assignments?
- Curriculum Standards: Assignments match modern CBSE sample formats to ensure relevant preparation.
- Thorough Revision: Detailed problem sets reinforce core concepts and eliminate conceptual weak spots.
- Execution Speed: Timed practice with assignment sets sharpens overall response timing.
Effective Strategy for Class 12 Computer Science Assignments
- Initial Reading: Begin by reading the NCERT book for Class 12 Computer Science to build a baseline understanding.
- Independent Testing: Attempt assignment questions unassisted, then verify work using provided answer keys.
- Supplementary Aids: Leverage revision notes and worksheets whenever you encounter difficult topics.
FAQs
You can download free PDF assignments for Class 12 Computer Science Constructors And Destructors Concepts from StudiesToday.com. These practice sheets have been updated for the 2026-27 session covering all concepts from latest NCERT textbook.
Yes, our teachers have given solutions for all questions in the Class 12 Computer Science Constructors And Destructors Concepts assignments. This will help you to understand step-by-step methodology to get full marks in school tests and exams.
Yes. These assignments are designed as per the latest CBSE syllabus for 2026. We have included huge variety of question formats such as MCQs, Case-study based questions and important diagram-based problems found in Constructors And Destructors Concepts.
Practicing topicw wise assignments will help Class 12 students understand every sub-topic of Constructors And Destructors Concepts. Daily practice will improve speed, accuracy and answering competency-based questions.
Yes, all printable assignments for Class 12 Computer Science Constructors And Destructors Concepts are available for free download in mobile-friendly PDF format.