Access Millions of academic & study documents

A class FeetInches is defined below(Header File)#ifndef FEETINC

Content type
User Generated
Showing Page:
1/11
A class FeetInches is defined below:
(Header File)
#ifndef FEETINCHES_H
#define FEETINCHES_H
class FeetInches
{
private:
int feet;
int inches;
void simplify();
public:
FeetInches(int f = 0, int i = 0)
{
feet = f;
inches = i;
simplify();}
void setFeet(int f)
{
feet = f;
}
void setInches(int i)
{
inches = i;
simplify();
}
int getFeet() const
{
return feet;
}
int getInches() const
{
return inches;
}
FeetInches operator + (const FeetInches &);
FeetInches operator - (const FeetInches &);

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/11
};
#endif
(Program)
#include <cstdlib>
#include \"FeetInches.h\"
void FeetInches::simplify()
{
if (inches >= 12)
{
feet += (inches / 12);
inches = inches % 12;
}
else if (inches < 0)
{
feet -= ((abs(inches) / 12) + 1);
inches = 12 - (abs(inches) % 12);
}
}
FeetInches FeetInches::operator + (const FeetInches
&right)
{
FeetInches temp;
temp.inches = inches + right.inches;
temp.feet = feet + right.feet;
temp.simplify();
return temp;
}
{
FeetInches FeetInches::operator - (const FeetInches
&right)
{
FeetInches temp;
temp.inches = inches - right.inches;
temp.feet = feet - right.feet;
temp.simplify();
return temp;

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/11

Sign up to view the full document!

lock_open Sign Up
End of Preview - Want to read all 11 pages?
Access Now
Unformatted Attachment Preview
A class FeetInches is defined below: (Header File) #ifndef FEETINCHES_H #define FEETINCHES_H class FeetInches { private: int feet; int inches; void simplify(); public: FeetInches(int f = 0, int i = 0) { feet = f; inches = i; simplify();} void setFeet(int f) { feet = f; } void setInches(int i) { inches = i; simplify(); } int getFeet() const { return feet; } int getInches() const { return inches; } FeetInches operator + (const FeetInches &); FeetInches operator - (const FeetInches &); }; #endif (Program) #include #include \"FeetInches.h\" void FeetInches::simplify() { if (inches >= 12) { feet += (inches / 12); inches = inches % 12; } else if (inches < 0) { feet -= ((abs(inches) / 12) + 1); inches = 12 - (abs(inches) % 12); } } FeetInches FeetInches::operator + (const FeetInches &right) { FeetInches temp; temp.inches = inches + right.inches; temp.feet = feet + right.feet; temp.simplify(); return temp; } { FeetInches FeetInches::operator - (const FeetInches &right) { FeetInches temp; temp.inches = inches - right.inches; temp.feet = feet - right.feet; temp.simplify(); return temp; } a) Use this definition of the class and embellish it with a copy constructor and the following overloaded relational operators: == > < b) A driver program is also provided. Study the program and modify it to demonstrate the use of the copy constructor and the relational operators you added. Driver Program #include #include \"FeetInches.h\" using namespace std; int main() { int ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.
Studypool
4.7
Indeed
4.5
Sitejabber
4.4

Similar Documents