Write a program to use copy constructor

  /* Write a program to use  copy constructor*/   #include<iostream.h> #include<conio.h> class counter { private: int count; public: counter(int x) { count=x; } counter(counter &ob) { count=ob.count; } void show() { cout<<“count=”<<count<<endl; }}; void main() { clrscr(); counter c1(10); counter c2(c1); c1.show(); c2.show(); getch(); } output: count=10 count=10 Continue reading →

Write a program to adding a member function of class

  /* Write a program to adding a member function of class*/ #include<iostream.h> #include<conio.h> class rectangle { private: int l,b; public: void setdata(int x,int y) { l=x; b=y; } void area() { int ar; ar=l*b; cout<<ar; }}; void main() { rectangle r1,r2; clrscr(); r1.setdata(5,6); cout<<“area=”; r1.area(); cout<<“\narea=”; r2.setdata(10,11); r2.area(); getch(); } output: area is=30 area […] Continue reading →

Write a program of pass by reference

  /* Write a program of pass by reference*/ #include<iostream.h> #include<conio.h> #include<iomanip.h> void main() { clrscr(); int a,b; void sW.A.P.(int &,int &); cout<<“enter two numbers=”; cin>>a>>b; cout<<“\n before calling a=”<<a<<“b=”<<b; sW.A.P.(a,b); cout<<“\n after calling a=”<<a<<“b=”<<b; getch(); } void sW.A.P.(int &x,int &y) { int z; z=x; x=y; y=z; cout<<“\n after modification x=”<<x<<“y=”<<y; } output: enter two […] Continue reading →

Write a program of pass by value

  /* Write a program of pass by value*/ #include<iostream.h> #include<conio.h> #include<iomanip.h> void main() { int a,b; clrscr(); void swap(int,int); cout<<“enter two numbers=”; cin>>a>>b; cout<<“\n before calling a=”<<a<<“b=”<<b; swap(a,b); cout<<“\n after calling a=”<<a<<“b=”<<b; getch(); } void swap(int x,int y) { int z; z=x; x=y; y=z;  cout<<“\n after modification of x=”<<x<<“y=”<<y; } output: enter two numbers=10 […] Continue reading →