Assignment No.2: solution

A.      Create a complex numbers class. Provide two consructors in it. Provide  Tostring() method(override from object class).overload all necessary operators such as *,/,+,-,==,<,,!=
Write unit tests for it.
 
B. Create a currency class. Provide two constructors and override of ToString() method.
Overload all necessary operators
Class Currency {
int dollars;
int cents;
 
public static currencyOperator+(currency lhs,currency rhs)
{
currency res=new currency();
res.cents=lhs.cents + rhs.cents;
if(res.cents=100)
{
res.cents=res.cents -100;
res.dollars=lhs.dollars+rhs.dollars +1;
}
else
res.dollars=lhs.dollars+rhs.dollars;
return res;
}
For - operator first convert to cents
int totllhscents=lhs.dollars*100+lhs.cents;
int totalrhscents=rhs.doallrs*100+rhs.cents;
int  rescents=lhstotalcents-rhstotalcents;
 res.dollars=rescents/100;
res.cents=rescents%100;
Powered by