Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream.h>
- #include<string.h>
- class string
- {
- char str[100];
- public:
- void enter()
- {
- cout<<"Enter the string ";
- cin>>str;
- }
- void display()
- {
- cout<<"Entered string is \" "<<str<<"\""<<endl;
- }
- void operator=(string &a)
- {
- int b=strcmp(str,a.str);
- if(b)
- {
- cout<<"\nStrings are not equal\n";
- }
- else
- {
- cout<<"\nString are equal\n";
- }
- }
- };
- int main()
- {
- string a,b;
- a.enter();
- b.enter();
- cout<<"\n"<<"\n";
- a.display();
- b.display();
- a=b;
- return 0;
- }
- Output:
- Enter the string dhruv
- Enter the string Dhruv
- Entered string is " dhruv"
- Entered string is " Dhruv"
- Strings are not equal
- Press any key to continue
- #include<iostream.h>
- class complex
- {
- int real;
- int img;
- public:
- complex()
- {
- real=0;
- img=0;
- cout<<"Default constructor called\n";
- }
- complex(int r,int i)
- {
- real=r;
- img=i;
- cout<<"\nParametrized constructor called\n";
- }
- complex(complex &a)
- {
- real=a.real;
- img=a.img;
- cout<<"\nCopy constructor called\n";
- }
- ~complex()
- {
- cout<<"Destructor called\n";
- }
- void enter()
- {
- cout<<"Enter real part ";
- cin>>real;
- cout<<"Enter imaginary part ";
- cin>>img;
- }
- void add(complex &a)
- {
- real+=a.real;
- img+=a.img;
- }
- void display()
- {
- cout<<"The no is"<<real<<"+i"<<img<<endl;
- }
- };
- int main()
- {
- complex a;
- a.enter();
- complex b(2,3);
- complex c(b);
- a.display();
- cout<<"Parametrized constructor objects";
- b.display();
- cout<<"Copy constructor objects";
- c.display();
- cout<<"\nAdd c+a";
- c.add(a);
- c.display();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment