// lab2.cpp: to add two English measurements. #include class Distance { // English Distance class private: int feet; float inches; public: Distance() // get length from user { cout << "\nEnter feet: "; cin >> feet; cout << "Enter inches: "; cin >> inches; } Distance(int f, float i) { feet = f; inches = i; } int getFeet() { return feet; } int getInches() { return inches; } void showDist() // display distance { cout << feet << "\'" << inches << "\""; } Distance addDist(Distance d) { float myi = 12*feet + inches; float giveni = 12*d.feet + d.inches; float toti = myi + giveni; int newf = toti/12; float newi = toti - 12*newf; Distance temp(newf, newi); return temp; } }; Distance addDist2(Distance dx, Distance dy) { /* int feet; float inches; inches = dx.getInches() + dy.getInches(); // add the inches feet = dx.getFeet() + dy.getFeet(); // add the feet if(inches >= 12.0) { // if total exceeds 12.0, inches -= 12.0; // then decrease inches by 12.0 and feet++; // increase feet by 1 } Distance temp(feet,inches); return temp; */ return dx.addDist(dy); } void main() { Distance dist1, dist2; // define two lengths cout << endl; cout << "Using addDist2\n"; cout << "--------------\n"; dist1.showDist(); cout << " + "; dist2.showDist(); cout << " = "; addDist2(dist1, dist2).showDist(); cout << endl << endl; cout << "Using addDist\n"; cout << "-------------\n"; dist1.showDist(); cout << " + "; dist2.showDist(); cout << " = "; dist1.addDist(dist2).showDist(); } /* Expected Output C:\cs2\labs>lab2ans Enter feet: 1 Enter inches: 1 Enter feet: 2 Enter inches: 2 Using addDist2 -------------- 1'1" + 2'2" = 3'3" Using addDist ------------- 1'1" + 2'2" = 3'3" C:\courses\cs2\labs> */