Program of Hierarchical Inheritance

/*Program of Hierarchical Inheritance*/ #include #include class A { int q; public: void getdata(int w) { q=w; } void display() { cout<<“\n\nq=”<<q<<“\nI am the member of Class A\n”; } }; class B:public A { int e; public: void setdata(int r) { e=r; } void show() { cout<<“\n\ne=”<<e<<“\nI am the member of Class B derived from Class A\n”; } }; class C:private A { int t; public: void putdata() { t=5; cout<<“\n\nt=”<<t<<“\nI am the member of Class C derived from Class A\n”; } void output() { getdata(t); display(); } }; int main() { C c; c.putdata(); c.output(); B b; b.getdata(2); b.display(); ……

Program of Dynamic Constructor

/*Program of Dynamic Constructor*/ #include #include #include class abc { char *string; int length; public: abc() { length=0; string=new char[length+1]; strcpy(string,” “); } abc(char *s) { length=strlen(s); string=new char[length+1]; strcpy(string,s); } void display() { cout


/*Program of FUNCTION OVERLOADING*/ #include #include int add(int,int,int); // function declaration float add(float,float); // function declaration int add(int q, int w, int e) // function definition { return (q+w+e); } float add(float a, float s) // function defintion { return (a*s); } int main() { int q,w,e; float a,s; coutq>>w>>e; int p=add(q,w,e); // function calling through parameters cout

Program of BINARY OPERATOR OVERLOADING using member function

/*Program of  BINARY OPERATOR OVERLOADING using member  function*/ #include<conio.h> #include<iostream.h> class A { int a,b; public: void getdata(int p,int q) { a=p; b=q; } void display() { cout<<“\na=”<<a<<“\nb=”<<b; } A operator+(A a1) { a1.a=a1.a+a; a1.b=a1.b+b; return a1; } }; int main() { A a1,a2,a3; int f,g,h,i; cout<<“\nEnter 2 numbers\n”; cin>>f>>g; a1.getdata(f,g); a1.display(); cout<<“\nEnter 2 numbers\n”; cin>>h>>i; a2.getdata(h,i); a3.display(); a3=a2+a1; getch(); return 0; } OUTPUT    : Enter any number 5 Enter another number 7 Addition of these numbers = 12