Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Linux Need help modifying this code for lab Lab instructions and code posted below #ifndef FEETINCHES_H #define FEETINCHES_H #include using namespace std; class FeetInches;

C++ Linux
Need help modifying this code for lab
Lab instructions and code posted below image text in transcribed
#ifndef FEETINCHES_H
#define FEETINCHES_H
#include
using namespace std;
class FeetInches;
// Forward Declaration
// Function Prototypes for Overloaded Stream Operators
ostream& operator
istream& operator >>(istream&, FeetInches&);
// The FeetInches class holds distances or measurements
// expressed in feet and inches.
class FeetInches {
private:
int feet; // To hold a number of feet
int inches; // To hold a number of inches
void simplify(); // Defined in FeetInches.cpp
public:
// Constructor
FeetInches(int f = 0, int i = 0) {
feet = f;
inches = i;
simplify();
}
// Mutator functions
void setFeet(int f) {
feet = f;
}
void setInches(int i) {
inches = i;
simplify();
}
// Accessor functions
int getFeet() const {
return feet;
}
int getInches() const {
return inches;
}
// Overloaded operator functions
FeetInches operator +(const FeetInches&); // Overloaded +
FeetInches operator -(const FeetInches&); // Overloaded -
FeetInches operator ++(); // Prefix ++
FeetInches operator ++(int); // Postfix ++
bool operator >(const FeetInches&); // Overloaded >
bool operator
bool operator ==(const FeetInches&); // Overloaded ==
// Friends
friend ostream& operator
friend istream& operator >>(istream&, FeetInches&);
};
#endif
// Implementation file for the FeetInches class
#include // Needed for abs()
#include "FeetInches.h"
//************************************************************
// Definition of member function simplify. This function *
// checks for values in the inches member greater than *
// twelve or less than zero. If such a value is found, *
// the numbers in feet and inches are adjusted to conform *
// to a standard feet & inches expression. For example, *
// 3 feet 14 inches would be adjusted to 4 feet 2 inches and *
// 5 feet -2 inches would be adjusted to 4 feet 10 inches. *
//************************************************************
void FeetInches::simplify() {
if (inches >= 12) {
feet += (inches / 12);
inches = inches % 12;
} else if (inches
feet -= ((abs(inches) / 12) + 1);
inches = 12 - (abs(inches) % 12);
}
}
//**********************************************
// Overloaded binary + operator. *
//**********************************************
FeetInches FeetInches::operator +(const FeetInches &right) {
FeetInches temp;
temp.inches = inches + right.inches;
temp.feet = feet + right.feet;
temp.simplify();
return temp;
}
//**********************************************
// Overloaded binary - operator. *
//**********************************************
FeetInches FeetInches::operator -(const FeetInches &right) {
FeetInches temp;
temp.inches = inches - right.inches;
temp.feet = feet - right.feet;
temp.simplify();
return temp;
}
//*************************************************************
// Overloaded prefix ++ operator. Causes the inches member to *
// be incremented. Returns the incremented object. *
//*************************************************************
FeetInches FeetInches::operator ++() {
++inches;
simplify();
return *this;
}
//***************************************************************
// Overloaded postfix ++ operator. Causes the inches member to *
// be incremented. Returns the value of the object before the *
// increment. *
//***************************************************************
FeetInches FeetInches::operator ++(int) {
FeetInches temp(feet, inches);
inches++;
simplify();
return temp;
}
//************************************************************
// Overloaded > operator. Returns true if the current object *
// is set to a value greater than that of right. *
//************************************************************
bool FeetInches::operator >(const FeetInches &right) {
bool status;
if (feet > right.feet)
status = true;
else if (feet == right.feet && inches > right.inches)
status = true;
else
status = false;
return status;
}
//************************************************************
// Overloaded
// is set to a value less than that of right. *
//************************************************************
bool FeetInches::operator
bool status;
if (feet
status = true;
else if (feet == right.feet && inches
status = true;
else
status = false;
return status;
}
//*************************************************************
// Overloaded == operator. Returns true if the current object *
// is set to a value equal to that of right. *
//*************************************************************
bool FeetInches::operator ==(const FeetInches &right) {
bool status;
if (feet == right.feet && inches == right.inches)
status = true;
else
status = false;
return status;
}
//********************************************************
// Overloaded
// directly display FeetInches objects. *
//********************************************************
ostream& operator
strm
return strm;
}
//********************************************************
// Overloaded >> operator. Gives cin the ability to *
// store user input directly into FeetInches objects. *
//********************************************************
istream& operator >>(istream &strm, FeetInches &obj) {
// Prompt the user for the feet.
cout
strm >> obj.feet;
// Prompt the user for the inches.
cout
strm >> obj.inches;
// Normalize the values.
obj.simplify();
return strm;
}
FeetInches Modification. Download the source code of Chapter 14 from code archive at MyClasses, and modify the FeetInches class so it overloads the following operators: =!= Demonstrate the class's capabilities in a simple program

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions

Question

What does stickiest refer to in regard to social media

Answered: 1 week ago