the code that i have coded is of operator overloading for incrementing and the i need some help in the operator overloading for decrementing ,mutiplication and division please send the following in a code form shall be thankful..
#include<iostream>
class Weight
{
private:
int kg,grms;
void ConvertWeight()
{
if(grms >= 1000) {
kg += grms/1000;
grms = grms%1000;
}
}
public:
Weight()
{
kg = grms = 0;
}
Weight(int k,int g)
{
kg = k;
grms = g;
// ConvertWeight();
}
void operator ++()
{
kg++;
grms+=10;
}
void operator ++(int)
{
kg++;
grms+=10;
}
void getWeight()
{
cout << endl << "Enter KG : ";cin>>kg;
cout << "Enter Grams : ";cin>>grms;
// ConvertWeight();
}
void printWeight()
{
cout << "KG : " << kg;
cout << " Grams : " << grms;
cout << endl;
}
void AddWeight(int k,int g)
{
kg += k;
grms += g;
// ConvertWeight();
}
void AddWeight(Weight w)
{
kg += w.kg;
grms += w.grms;
ConvertWeight();
}
int equals(Weight w)
{
if((kg == w.kg) && (grms == w.grms)) {
return 1;
}
else {
return 0;
}
}
};
int main()
{
Weight Marker,Duster(2,50);
Marker.AddWeight(2,5050);
cout<<"\nMarker :";
Marker.printWeight();
cout<<"\nDuster :";
Duster.printWeight();
if(Duster.equals(Marker))
cout<<"\nBoth are Equal in Weight :";
else
cout<<"\nBoth are Different in Weight :";
cout<<"\n\nAfter Adding Weights Of Marker & Duster :";
cout<<"\n\nDuster + Marker :";
Duster.AddWeight(Marker);
Duster.printWeight();
if(Duster.equals(Marker))
cout<<"\nAfter Adding Weights Of Duster And Marker Both are Equal in Weight :";
else
cout<<"\nAfter Adding Weights Of Duster And Marker Both are Different in Weight :";
cout<<"\n\n\nThe Operator function :";
cout<<"\nFor Marker";
++Marker;
Marker.printWeight();
cout<<"For Duster :";
Duster++;
Duster.printWeight();
return 0;
}