design a program(C++) to overload "+=" operator to add 2 distances given in feet %26amp; inches.{here operator overloading is to be used}
Please help me work out with the following c++ program!?
There are 12inches to a foot so you need to check that the sum of the inches value for the two numbers exceeds twelve and if so add one to the foot sum otherwise don't.
x = 1.11 //1 foot 11 inches
y = 4.4 //4 feet 4 inches
x += y;
so now x = 6.3 should be displayed but since the values are base 10 not 12, this doesn't occur without a function or intervention.
So lets say that you have two values of a class Distance with parameters feet and inches:
Distance c1 = new Distance(3, 11);
Distance c2 = new Distance(2, 4);
now to add the two distances:
Distance c1plusc2 = c1.operator + c2.operator;
the class is here:
class Distance
{
public:
Distance(double ft, double in = 0);
Distance operator+(const Distance%26amp; rhs);
private:
double ft, in;
};
clematis
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment