0% found this document useful (0 votes)
5 views1 page

C++ Constructor Program Example

This program demonstrates the use of a constructor in C++. It defines a student class with two constructors, one default and one that takes two integer parameters. The main function prompts the user to enter two integer values, creates an instance of the student class using the default constructor and another using the two parameter constructor, passing in the user input values.

Uploaded by

Jitender Garg
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

C++ Constructor Program Example

This program demonstrates the use of a constructor in C++. It defines a student class with two constructors, one default and one that takes two integer parameters. The main function prompts the user to enter two integer values, creates an instance of the student class using the default constructor and another using the two parameter constructor, passing in the user input values.

Uploaded by

Jitender Garg
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Write a program of constructor

#include<iostream.h>
#include<conio.h>
class student
{
public:
student(){}
student(int x,int y)
{
cout<<x*y;
}
};
void main()
{
int a,b;
clrscr();
cout<<"Enter Value of A: ";
cin>>a;
cout<<"Enter value of B:";
cin>>b;
student o;
student p(a,b);
getch();

You might also like