upsidedown

PARAT AMCHO PROGRAMMM!!! :-p

Mar 9th, 2012
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. #include<iostream.h>
  2. #include<string.h>
  3. class string
  4. {
  5.     char str[100];
  6.  
  7. public:
  8.     void enter()
  9.     {
  10.         cout<<"Enter the string ";
  11.         cin>>str;
  12.     }
  13.  
  14.     void display()
  15.     {
  16.         cout<<"Entered string is \" "<<str<<"\""<<endl;
  17.     }
  18.  
  19.     void operator=(string &a)
  20.     {
  21.         int b=strcmp(str,a.str);
  22.         if(b)
  23.         {
  24.             cout<<"\nStrings are not equal\n";
  25.         }
  26.         else
  27.         {
  28.             cout<<"\nString are equal\n";
  29.         }
  30.     }
  31. };
  32. int main()
  33. {
  34.     string a,b;
  35.     a.enter();
  36.     b.enter();
  37.  
  38.     cout<<"\n"<<"\n";
  39.     a.display();
  40.     b.display();
  41.     a=b;
  42.    
  43.     return 0;
  44. }
  45.  
  46. Output:
  47. Enter the string dhruv
  48. Enter the string Dhruv
  49.  
  50. Entered string is " dhruv"
  51. Entered string is " Dhruv"
  52.  
  53. Strings are not equal
  54. Press any key to continue
  55.  
  56. #include<iostream.h>
  57. class complex
  58. {
  59.     int real;
  60.     int img;
  61. public:
  62.     complex()
  63.     {
  64.         real=0;
  65.         img=0;
  66.         cout<<"Default constructor called\n";
  67.     }
  68.  
  69.     complex(int r,int i)
  70.     {
  71.         real=r;
  72.         img=i;
  73.         cout<<"\nParametrized constructor called\n";
  74.     }
  75.     complex(complex &a)
  76.     {
  77.         real=a.real;
  78.         img=a.img;
  79.         cout<<"\nCopy constructor called\n";
  80.     }
  81.     ~complex()
  82.     {
  83.         cout<<"Destructor called\n";
  84.     }
  85.     void enter()
  86.     {
  87.         cout<<"Enter real part ";
  88.         cin>>real;
  89.         cout<<"Enter imaginary part ";
  90.         cin>>img;
  91.     }
  92.     void add(complex &a)
  93.     {
  94.         real+=a.real;
  95.         img+=a.img;
  96.     }
  97.     void display()
  98.     {
  99.         cout<<"The no is"<<real<<"+i"<<img<<endl;
  100.     }
  101. };
  102.  
  103. int main()
  104. {
  105.     complex a;
  106.     a.enter();
  107.     complex b(2,3);
  108.     complex c(b);
  109.     a.display();
  110.     cout<<"Parametrized constructor objects";
  111.     b.display();
  112.     cout<<"Copy constructor objects";
  113.     c.display();
  114.     cout<<"\nAdd c+a";
  115.     c.add(a);
  116.     c.display();
  117.  
  118.     return 0;
  119. }
Advertisement
Add Comment
Please, Sign In to add comment