C++ Program to implement Constructor Overloading – Q13
Q13. Program to implement Constructor Overloading:
Implement the concept of Constructor Overloading with the help of not less than three different constructors within any class of your choice.
… from College notes (BCA/MCA assignments):
#include <iostream.h> #include <conio.h> #include <string.h> class Cperson{ private: char name[20]; public: Cperson(){ cout<<"\n Constructor Called."<<endl; strcpy(name, "Manoj"); } Cperson(char *str){ strcpy(name, str); } Cperson(Cperson &per){ strcpy(name, per.name); } void Show_Name(){ cout<<name; } }; void main(){ clrscr(); Cperson Op1; Cperson Op2("Pandey"); Cperson Op3(Op2); cout<<"\n Op1: "; Op1.Show_Name(); cout<<"\n Op2: "; Op2.Show_Name(); cout<<"\n Op3: "; Op3.Show_Name(); getch(); }
Output:
Constructor Called.
Op1: Manoj
Op2: Pandey
Op3: Pandey
Categories: Cpp
Constructor Overloading, Cpp, Cpp Constructors
Comments (0)
Trackbacks (0)
Leave a comment
Trackback