Object Oriented Programming Using C++(313304) Practical No.10: Write programs for Default Constructor Answer
The classes and objects help to represent real-life entities with different attributes and related member functions. The use of constructor functions facilitates the initialization of instance variables.
Constructor: Constructors are special member functions that perform the initialization of every object. The Compiler calls the Constructor whenever an object is created. Constructors initialize values to instance variables after storage is allocated to the object. Constructors are of three types :
1. Default Constructor
2. Parameterized Constructor
3. Copy Constructor
Object Oriented Programming Using C++(313304) Exercise:
1. WAP to implement default constructor that initializes num1 and num2 as 10 and 20 and prints the values of num1 and num2.
Answer:
2. Define a class student that contains member variables as roll no,name and course. Write a program using a constructor as "Computer Engineering" for course . Accept this data for objects of the class and display the data.
Answer:
Practical Related Questions
1. WAP to declare a class student having data members as name and percentage. Write a constructor to initialize these data members. Accept and display data for one object.
Answer:
2. WAP to declare class time having data members as hrs, min, sec. Write a constructor to accept data and display for two objects.
Answer:
3. Complete the following table:
Answer:
Conclusion
We completed Object Oriented Programming Using C++(313304) Practical No.10 in which we wrote various C++ programs for Default Constructor.