175k views
3 votes
Type the program's output// "New" means new compared to previous level#include using namespace std;class InchSize {public:InchSize(int wholeInches = 0, int sixteenths = 0);void Print() const;InchSize operator+(InchSize rhs);InchSize operator+(int sixteenthsOfInch);private:int inches;int sixteenths;};InchSize InchSize::operator+(InchSize rhs) {InchSize totalSize;totalSize.inches = inches + rhs.inches;totalSize.sixteenths = sixteenths + rhs.sixteenths;// If sixteenths is greater than an inch, carry 1 to inches.if (totalSize.sixteenths >= 16) {totalSize.inches += 1;totalSize.sixteenths -= 16;}return totalSize;}// New: Overloaded + operator adding integers.InchSize InchSize::operator+(int sixteenthsOfInch) {InchSize totalSize;totalSize.inches = inches;totalSize.sixteenths = sixteenths + sixteenthsOfInch;// While sixteenths is greater than an inch, carry to inches.while (totalSize.sixteenths >= 16) {totalSize.inches += 1;totalSize.sixteenths -= 16;}return totalSize;}InchSize::InchSize(int wholeInches, int sixteenthsOfInch) {inches = wholeInches;sixteenths = sixteenthsOfInch;}void InchSize::Print() const {cout << inches << " " << sixteenths << "/16 inches" << endl;}int main() {InchSize size1(4, 13);InchSize size2(3, 11);InchSize sumSize;InchSize totalSize;sumSize = size1 + size2;totalSize = sumSize + 18;totalSize.Print();return 0;

}

1 Answer

3 votes

Answer:

The output of the code is "2 10/16 inches".

Step-by-step explanation:

It first declares size1 as that of an InchSize object to 1 and 16 cm as 12. InchSize object size2 to four and sixteenth inches as 11 inches

Whenever users add size1 and size2 in sumSize, it will become 5 inches as well as 23 and 16ths, however, the size will be reduced as well as the sixteenths larger than 16 will be converted to 1 inch. So 6 inches, 7 sixteenths, will become it. Then you're trying to subtract the amount of room left (which is 9 inches and 1 sixteenths)

It would first be 3-6 inches -6 16th, but the shape is reduced although it will take 2 inches - 10 sixteenths. It's the response.

User Anne Schuessler
by
2.6k points