Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 3

//program to use arithmetic assignment operator #include<iostream.h> #include<conio.

h> class A { int p; public: A(int r) { p=r; } void operator +=(A z) { p=p+z.p; } void show() { cout<<"p is"<<p; } }; int main() { A a(3),a1(4); a+=a1; cout<<"now"; a.show(); getch(); }

//program to print info of tallest student with overloading og rlational and assignment operator #include<iostream.h> #include<conio.h> #include<string.h> class height { char name[20]; float feet; public: void input() {

cout<<"enter name"; //gets(name); cin>>name; cout<<"enter height"; cin>>feet; } void output() { cout<<"name is:"<<name<<endl<<"height is:"<<feet<<endl; } int operator>(height h) { if(feet>h.feet) { return 1; } else return 0; } void operator=(height h) { strcpy(name,h.name); feet=h.feet; } }; int main() { height f[50],temp; int i,n; cout<<"total no:"; cin>>n; cout<<"enter elements:"; for(int i=0;i<n;i++) { f[i].input(); } temp=f[0]; for(i=0;i<n;i++) { if(f[i]>temp) temp=f[i]; } cout<<"unfo is:"<<endl;

temp.output(); getch(); } //program to implement overloading with strings with logical and #include<iostream.h> #include<conio.h> class A { public: char s[30]; void input() { cin>>s; } void print() { cout<<s; } A operator && (A a) { A a1; strcpy(a1.s,s); strcat(a1.s,a.s); return a1; }

}; int main() { A a,b,c; cout<<"enter first string:"; a.input(); cout<<"enter second string:"; b.input(); c=a&&b; c.print(); getch(); }

You might also like