Friday, November 9, 2018

COPY CONSTRUCTOR

#include<iostream.h>
using namespace std;
class Marks{
public:
int math, science;
Marks(int a, int b)
{
maths=a;
science=b;
}
Marks(Marks &ob)
{
maths=obj.maths;
science=obj.science;
}
void Display()
{
cout<<"Maths="<<maths;
cout<<endl<<"Science="<<science;

}
};
int main()
{
Marks m(80,90);
Marks m1(m);
m.Display();
}

PARAMETERIZED CONSTRUCTOR

#include<iostream.h>
using namespace std;
class Marks{
public:
int math, science;
Marks(int a, int b)
{
maths=a;
science=b;
}
void Display()
{
cout<<"Maths="<<maths;
cout<<endl<<"Science="<<science;

}
};
int main()
{
Marks m(80,90);
m.Display();
}

CONSTRUCTOR

CONSTRUCTOR:

Constructor are the special member function of the class which are used to initialize the objects of that class. The constructor of class is automatically called after the creation of the object. Name of the constructor should exactly same as that of name of the class. Constructor is called once in a lifetime of object when object is created.

PROGRAM:

#include<iostream.h>
using namespace std;
class Marks{
public:
int math, science;
Marks()
{
maths=65;
science=80;
}
void Display()
{
cout<<"Maths="<<maths;
cout<<endl<<"Science="<<science;
}
};
int main()
{
Marks m;
m.Display();
 return 0;
}

Static Member Function

CODE : #include<iostream> using namespace std; class test  {     int code;       static int count;               //static...