Menu

[Solved]Include Include Include Using Namespace Std Feetinches Class Holds Distances Measured Feet Q37158840

#include <iostream>#include <string>#include <stdio.h>using namespace std;/** The FeetInches class holds distances measured in feet and inches.*/class FeetInches{ private: int feet; // The number of feet int inches; // The number of inches /** The simplify method adjusts the values in feet and inches to conform to a standard measurement. */ void simplify() { if (inches > 11) { feet = feet + (inches / 12); inches = inches % 12; } } /** This constructor assigns 0 to the feet and inches fields. */ public: FeetInches() { feet = 0; inches = 0; } /** This constructor accepts two arguments which are assigned to the feet and inches fields. The simplify method is then called. @param f The value to assign to feet. @param i The value to assign to inches. */ FeetInches(int f, int i) { feet = f; inches = i; simplify(); } /** The following is a copy constructor. It accepts a reference to another FeetInches object. The feet and inches fields are set to the same values as those in the argument object. @param object2 The object to copy. */ FeetInches (const FeetInches& object2) { feet = object2.feet; inches = object2.inches; } /** The setFeet method assigns a value to the feet field. @param f The value to assign to feet. */ void setFeet(int f) { feet = f; } /** The setInches method assigns a value to the inches field. @param i The value to assign to inches. */ void setInches(int i) { inches = i; simplify(); } /** getFeet method @return The value in the feet field. */ int getFeet() { return feet; } /** getInches method @return The value in the inches field. */ int getInches() { return inches; } /** print method prints the distance as feet/inches */ void print() { cout << feet << ” feet ” << inches << ” inches”; } /** The add method returns a FeetInches object that holds the sum of this object and another FeetInches object. @param object2 The other FeetInches object. @return A reference to a FeetInches object. */ FeetInches add(const FeetInches& object2) { int totalFeet, // To hold the sum of feet totalInches; // To hold the sum of inches totalFeet = feet + object2.feet; totalInches = inches + object2.inches; return FeetInches(totalFeet, totalInches); } FeetInches scale(int s) { return FeetInches(s*feet, s*inches); } /** The equals method compares this object to the argument object. If both have the same values, the method returns true. @return true if the objects are equal, false otherwise. */ bool equals(FeetInches object2) { return feet == object2.feet && inches == object2.inches; }};int main(){ FeetInches f(0, 30), g; int ft, in; cout << “Length 1 = “; f.print(); cout << endl; cout << “nEnter length 2 feet: “; cin >> ft; cout << “Enter length 2 inches: “; cin >> in; g.setFeet(ft); g.setInches(in); cout << “nLength 2 = “; g.print(); cout << endl; if (f.equals(g)) cout << “nThe lengths are the samenn”; else cout << “nThe lengths are not the samenn”; FeetInches h = f.add(g); cout << “Sum of length 1 and 2 = “; h.print(); cout << endl; cout << “2 * length 1 = “; f.scale(2).print(); cout << endl; cout << “3 * length 2 = “; g.scale(3).print(); cout << endl; getchar(); return 0;}

Programming Project 6

Change the implementation of the FeetInchesclass to use only one private data member named all_inches to storethe length. A length that would have been stores in the currentclass as feet = 2, inches = 6 will now be storedas all_inches = 30.

All class member methods must work the same as before. The mainprogram should give identical results using either the old or newversions of the class.

Expert Answer


Answer to #include #include #include using namespace std; /** The FeetInches class holds distances measured in feet and inches. *… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *