// Program to demonstrate Distance class. // Assignment-17 // distfi.cpp, Author - Krishna Kumar Khatri. // Uncomment ONLY the following line if you are using Turbo/Borland compiler. // #define TC #ifdef TC #include #else #include using namespace std; #endif #include // For getch. class Distance { int feet; int inch; public: Distance(const int& f = 0, const int& i = 0) : feet(f), inch(i) { } Distance add(const Distance&, const Distance&); void display(); }; Distance Distance::add(const Distance& dst1, const Distance& dst2) { Distance dist; dist.feet = dst1.feet + dst2.feet; if (dst1.inch + dst2.inch > 12) { dist.feet++; dist.inch = dst1.inch + dst2.inch - 12; } else dist.inch = dst1.inch + dst2.inch; return dist; } void Distance::display() { cout << feet << "\" " << inch << "'"; } int main() { #ifdef TC clrscr(); #endif Distance d1(5, 12); Distance d2(6, 2); Distance d3, dummy; cout << "First distance - "; d1.display(); cout << endl << "Second distance - "; d2.display(); d3 = dummy.add(d1, d2) ; cout << endl << "Summed up - "; d3.display(); cout << endl << endl << "Program over. Press any key to exit..."; getch(); return 0; // Successful termination. }