#include #include using namespace std; class Distance //English Distance class { private: int feet; float inches; public: class InchesException //exception class { public: string origin; float iValue; InchesException(string org, float inc) // cosntructor { origin = org; iValue = inc; } }; Distance() //constructor (no args) { feet = 0; inches = 0.0; } Distance(int ft, float in) //constructor (two args) { if(in >= 12.0) throw InchesException("2-arg constructor", in); feet = ft; inches = in; } void getdist() //get length from user { cout << "\nEnter feet: "; cin >> feet; cout << "Enter inches: "; cin >> inches; if(inches >= 12.0) throw InchesException("getdist() function", inches); } void showdist() //display distance { cout << feet << "\'-" << inches << '\"'; } }; //////////////////////////////////////////////////////////////// int main() { char ch = 'y'; while (ch=='y') { try { Distance dist1(17, 13.5); //2-arg constructor Distance dist2; //no-arg constructor dist2.getdist(); //get value //display distances cout << "\ndist1 = "; dist1.showdist(); cout << "\ndist2 = "; dist2.showdist(); } catch(Distance::InchesException ix) //exception handler { cout << "\nInitialization error in " << ix.origin << ".\n Inches value of " << ix.iValue << " is too large." << endl; } cout << "\nWould you like to enter another distance? y or n "; cin >> ch; } // end while loop return 0; }