Modify the program 11-10 from pages 753-755 as follows: 1. To Length class files (Length.h and Length.cpp) add the operator overload for stream insertion (<<) and stream extraction (>>) from page 759. You should not use the modified version of class Length from page 759 because it contains more operator overloads. Instead of typing you can use copy/paste from Length1.h and Length1.cpp respectively. 2. In main() replace the lines 11-16 with appropriate usage of stream extraction overload (>>) to change "first" and "second" objects with values inputted by the end user. 3. In main(), replace the output on lines 21,22 and 25,26 with appropriate usage of stream insertion (<<) operator. The resulting output should be identical with the unmodified version of the program. 11-10: // This program demonstrates the Length class's overloaded // +, -, ==, and < operators. #include #include "Length.h" using namespace std; int main() { Length first(0), second(0), third(0); int f, i; cout << "Enter a distance in feet and inches: "; cin >> f >> i; first.setLength(f, i); cout << "Enter another distance in feet and inches: "; cin >> f >> i; second.setLength(f, i); // Test the + and - operators third = first + second; cout << "first + second = "; cout << third.getFeet() << " feet, "; cout << third.getInches() << " inches.\n"; third = first - second; cout << "first - second = "; cout << third.getFeet() << " feet, "; cout << third.getInches() << " inches.\n"; // Test the relational operators cout << "first == second = "; if (first == second) cout << "true"; else cout << "false"; cout << "\n"; cout << "first < second = "; if (first < second) cout << "true"; else cout << "false"; cout << "\n";   return 0; }   Length.cpp:   #include "Length.h"   //************************************* // Overloaded operator + * //************************************* Length operator+(Length a, Length b) { return Length(a.len_inches + b.len_inches); }   //************************************* // Overloaded operator - * //************************************* Length operator-(Length a, Length b) { return Length(a.len_inches - b.len_inches); }   //************************************ // Overloaded operator == * //************************************ bool operator==(Length a, Length b) { return a.len_inches == b.len_inches; }   //************************************ // Overloaded operator < * //************************************ bool operator<(Length a, Length b) { return a.len_inches < b.len_inches; }   Length.h:   #ifndef _LENGTH_H #define _LENGTH_H #include using namespace std;   class Length { private: int len_inches; public: Length(int feet, int inches) { setLength(feet, inches); } Length(int inches){ len_inches = inches; } int getFeet() const { return len_inches / 12; } int getInches() const { return len_inches % 12; } void setLength(int feet, int inches) { len_inches = 12 *feet + inches; } friend Length operator+(Length a, Length b); friend Length operator-(Length a, Length b); friend bool operator< (Length a, Length b); friend bool operator== (Length a, Length b); }; #endif

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Topic Video
Question

Modify the program 11-10 from pages 753-755 as follows:

1. To Length class files (Length.h and Length.cpp) add the operator overload for stream insertion (<<) and stream extraction (>>) from page 759. You should not use the modified version of class Length from page 759 because it contains more operator overloads. Instead of typing you can use copy/paste from Length1.h and Length1.cpp respectively.

2. In main() replace the lines 11-16 with appropriate usage of stream extraction overload (>>) to change "first" and "second" objects with values inputted by the end user.

3. In main(), replace the output on lines 21,22 and 25,26 with appropriate usage of stream insertion (<<) operator.

The resulting output should be identical with the unmodified version of the program.

11-10:

// This program demonstrates the Length class's overloaded

// +, -, ==, and < operators.

#include <iostream>

#include "Length.h"

using namespace std;

int main()

{

Length first(0), second(0), third(0);

int f, i;

cout << "Enter a distance in feet and inches: ";

cin >> f >> i;

first.setLength(f, i);

cout << "Enter another distance in feet and inches: ";

cin >> f >> i;

second.setLength(f, i);

// Test the + and - operators

third = first + second;

cout << "first + second = ";

cout << third.getFeet() << " feet, ";

cout << third.getInches() << " inches.\n";

third = first - second;

cout << "first - second = ";

cout << third.getFeet() << " feet, ";

cout << third.getInches() << " inches.\n";

// Test the relational operators

cout << "first == second = ";

if (first == second) cout << "true"; else cout << "false";

cout << "\n";

cout << "first < second = ";

if (first < second) cout << "true"; else cout << "false";

cout << "\n";

 

return 0;

}

 

Length.cpp:

 

#include "Length.h"

 

//*************************************

// Overloaded operator + *

//*************************************

Length operator+(Length a, Length b)

{

return Length(a.len_inches + b.len_inches);

}

 

//*************************************

// Overloaded operator - *

//*************************************

Length operator-(Length a, Length b)

{

return Length(a.len_inches - b.len_inches);

}

 

//************************************

// Overloaded operator == *

//************************************

bool operator==(Length a, Length b)

{

return a.len_inches == b.len_inches;

}

 

//************************************

// Overloaded operator < *

//************************************

bool operator<(Length a, Length b)

{

return a.len_inches < b.len_inches;

}

 

Length.h:

 

#ifndef _LENGTH_H

#define _LENGTH_H

#include <iostream>

using namespace std;

 

class Length

{

private:

int len_inches;

public:

Length(int feet, int inches)

{

setLength(feet, inches);

}

Length(int inches){ len_inches = inches; }

int getFeet() const { return len_inches / 12; }

int getInches() const { return len_inches % 12; }

void setLength(int feet, int inches)

{

len_inches = 12 *feet + inches;

}

friend Length operator+(Length a, Length b);

friend Length operator-(Length a, Length b);

friend bool operator< (Length a, Length b);

friend bool operator== (Length a, Length b);

};

#endif

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Instruction Format
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education