#include <iostream>
using namespace std;
class Money
{
private:
int rupees,paise;
public:
Money()
{
cin>>rupees>>paise;
}
Money operator +(Money &M)
{
Money temp;
temp.rupees=rupees+M.rupees;
temp.paise=paise+M.paise;
return temp;
}
Money operator -(Money &M)
{
Money temp;
temp.rupees=rupees-M.rupees;
temp.paise=paise-M.paise;
return temp;
}
void display()
{
cout<<"Rs="<<rupees<<" and "<<paise<<" Paise"<<endl;
}
};
int main()
{
Money M1,M2,M3,M4,M5;
M4=M2-M3;
M5=M1+M4;
M5.display();
return 0;
}
using namespace std;
class Money
{
private:
int rupees,paise;
public:
Money()
{
cin>>rupees>>paise;
}
Money operator +(Money &M)
{
Money temp;
temp.rupees=rupees+M.rupees;
temp.paise=paise+M.paise;
return temp;
}
Money operator -(Money &M)
{
Money temp;
temp.rupees=rupees-M.rupees;
temp.paise=paise-M.paise;
return temp;
}
void display()
{
cout<<"Rs="<<rupees<<" and "<<paise<<" Paise"<<endl;
}
};
int main()
{
Money M1,M2,M3,M4,M5;
M4=M2-M3;
M5=M1+M4;
M5.display();
return 0;
}
SESSION: Operator Overloading
ReplyDeleteQ. 34: Play with Fraction
#include
using namespace std;
class Fraction
{
public:
int numerator,denominator;
Fraction()
{
numerator=0;
denominator=0;
}
void getinput()
{
cin>>numerator>>denominator;
}
Fraction operator + (Fraction obj)
{
Fraction temp;
temp.numerator=(numerator*obj.denominator)+(denominator*obj.numerator);
temp.denominator=denominator*+obj.denominator;
return temp;
}
};
int main()
{
Fraction f1,f2,add;
f1.getinput();
f2.getinput();
//+obj;
add=f1+f2;
cout<<add.numerator<<"/"<<add.denominator;
// add.output();
return 0;
}
question saving has error please check
ReplyDelete#include
ReplyDeleteusing namespace std;
class Money
{
private:
int rupees,Paise;
public:
Money()
{
cin>>rupees>>Paise;
}
Money operator +(Money o)
{
Money temp;
temp.rupees=rupees+o.rupees;
temp.Paise=Paise+o.Paise;
return temp;
}
Money operator -(Money o)
{
Money temp;
temp.rupees=rupees-o.rupees;
temp.Paise=Paise-o.Paise;
return temp;
}
void display()
{
cout<<"Rs="<<rupees<<" and "<<Paise<<" Paise"<<endl;
}
};
int main()
{
Money M1,M2,M3,M4,M5;
M4=M2-M3;
M5=M1+M4;
M5.display();
return 0;
}
thankx alot it worked 100%
Delete