Saturday, 31 January 2015

constructor overloading in c++

Structure of the Problem Requirements

Constructor is used to initialize the data elements of the class. In this problem a constructor is overloaded three times and save the CMS numbers of the different student.

Source Code

using namespace std;
class CMS
int cmsNum,regNum;
CMS() //default constructor
cmsNum=regNum=0; //set the value of variables in default constructor
CMS(int x) //one arguments constructor
CMS(int x,int y)//Two arguments constructor
cmsNum = x;
regNum = y;
void Display() //Values display function
cout<<"Cms Number : "<<cmsNum<<endl<<endl;
cout<<"Reg Number : "<<regNum<<endl<<endl;
int main()
cout<<"\n\n\t ********* Constructor Overloading ************* \n\n";
CMS c(8651);
CMS c1(8661);
CMS c2(8939,8649);
return 0;

Output of the Program

constructor overloading in c++

Share it Please

About Author!

Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.


Post a Comment