Assignment Operator Overloading ( +=)
"Nice One Program"
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class rv{ public:
int inch,feet;
rv(){ inch=0,feet=0;
}
void operator +=(rv dis)
{
feet=feet+dis.feet;
inch=inch+dis.inch;
if(inch>=12)
{ feet+=inch/12;
inch%=12;
}
}};
void main()
{ clrscr();
rv dis1,dis2;
cout<<"Enter dis1: ";
cin>>dis1.feet;
cin>>dis1.inch;
cout<<"\nEnter dis2: ";
cin>>dis2.feet;
cin>>dis2.inch;
dis1+=dis2;
cout<<"\n Value of feet: "<<dis1.feet;
cout<<"\n value of inch:"<<dis1.inch;
getch();
}
"Nice One Program"
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class rv{ public:
int inch,feet;
rv(){ inch=0,feet=0;
}
void operator +=(rv dis)
{
feet=feet+dis.feet;
inch=inch+dis.inch;
if(inch>=12)
{ feet+=inch/12;
inch%=12;
}
}};
void main()
{ clrscr();
rv dis1,dis2;
cout<<"Enter dis1: ";
cin>>dis1.feet;
cin>>dis1.inch;
cout<<"\nEnter dis2: ";
cin>>dis2.feet;
cin>>dis2.inch;
dis1+=dis2;
cout<<"\n Value of feet: "<<dis1.feet;
cout<<"\n value of inch:"<<dis1.inch;
getch();
}
No comments:
Post a Comment