Please help implement a '+' operator that takes two intervals and takes the smallest interval and then the largest for the end.  Example: Interval(4, 6) + Interval(5, 8) equals to Interval(4, 8), and Interval(4, 6) + Interval(7, 8) equals to Interval(4, 8). !!!!!!!This one below here is the .cpp file i need to implement, only file i can change. I worked on it but i keep getting an error which is shown in the image #include #include "interval.h" using namespace std; Interval::Interval(int lower_bound, int upper_bound) { low = lower_bound; high = upper_bound; } void Interval::print(ostream& out) const { out << "(" << low << ", " << high << ")" << endl; } Interval Interval::operator+(const Interval &other) const { int temp_low, temp_high; if(this->low <= other.low) { temp_low = this->low; } else { temp_low=other.low; } if(this->high >= other.high) { temp_high = this->high; } else { temp_high=other.high; } return Interval(temp_low,temp_high);

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

Please help implement a '+' operator that takes two intervals and takes the smallest interval and then the largest for the end. 

Example: Interval(4, 6) + Interval(5, 8) equals to Interval(4, 8), and Interval(4, 6) + Interval(7, 8) equals to Interval(4, 8).

!!!!!!!This one below here is the .cpp file i need to implement, only file i can change. I worked on it but i keep getting an error which is shown in the image

#include <iostream>
#include "interval.h"
using namespace std;

Interval::Interval(int lower_bound, int upper_bound)
{
low = lower_bound;
high = upper_bound;
}

void Interval::print(ostream& out) const
{
out << "(" << low << ", " << high << ")" << endl;
}

Interval Interval::operator+(const Interval &other) const
{
int temp_low, temp_high;
if(this->low <= other.low) { temp_low = this->low; }
else { temp_low=other.low; }
if(this->high >= other.high) { temp_high = this->high; }
else { temp_high=other.high; }
return Interval(temp_low,temp_high);
}

 

//this is the tester file i am given, cannot change ANYTHING

#include <iostream>
#include "interval.h"

using namespace std;

int main()
{
Interval result = Interval(3, 4) + Interval(7, 8);
result.print(cout);
cout << "Expected: (3, 8)" << endl;
result = Interval(7, 9) + Interval(4, 8);
result.print(cout);
cout << "Expected: (4, 9)" << endl;
result = Interval(4, 9) + Interval(7, 8);
result.print(cout);
cout << "Expected: (4, 9)" << endl;
result = Interval(4, 5) + Interval(5, 8);
result.print(cout);
cout << "Expected: (4, 8)" << endl;
return 0;
}

//this is the .h file i am given, i cannot change ANYTHING about it

#ifndef INTERVAL_H
#define INTERVAL_H
#include <iostream>

class Interval
{
public:
Interval(int lower_bound, int upper_bound);
void print(std::ostream& out) const;
Interval operator+(const Interval& other) const;
private:
int low;
int high;
};

#endif

Error:
/usr/bin/ld: /tmp/cc2SftI9.o: in function Interval::Interval (int, int)':
/tmp/codecheck/workwz7b76SLfuBISgjsQeKo/tester1/util.cpp:6: multiple definition of 'Interval::Interval (int, int)'; /tmp/ccy7X0X7.o:/tmp/codecheck/workl
/usr/bin/ld: /tmp/cc2SftI9.0: in function 'Interval::Interval (int, int)':
/tmp/codecheck/workwz7b76SLfuBISgjsQeKo/tester1/util.cpp:6: multiple definition of 'Interval::Interval (int, int)'; /tmp/ccy7X0X7.o:/tmp/codecheck/workl
/usr/bin/ld: /tmp/cc2Sft19.o: in function 'Interval::print(std::ostream&) const':
/tmp/codecheck/workWz7b76SLfuBISgjsQeKo/tester1/util.cpp:13: multiple definition of 'Interval::print(std::ostream&) const'; /tmp/ccy7X0X7.o:/tmp/codecl
collect2: error: ld returned 1 exit status
Transcribed Image Text:Error: /usr/bin/ld: /tmp/cc2SftI9.o: in function Interval::Interval (int, int)': /tmp/codecheck/workwz7b76SLfuBISgjsQeKo/tester1/util.cpp:6: multiple definition of 'Interval::Interval (int, int)'; /tmp/ccy7X0X7.o:/tmp/codecheck/workl /usr/bin/ld: /tmp/cc2SftI9.0: in function 'Interval::Interval (int, int)': /tmp/codecheck/workwz7b76SLfuBISgjsQeKo/tester1/util.cpp:6: multiple definition of 'Interval::Interval (int, int)'; /tmp/ccy7X0X7.o:/tmp/codecheck/workl /usr/bin/ld: /tmp/cc2Sft19.o: in function 'Interval::print(std::ostream&) const': /tmp/codecheck/workWz7b76SLfuBISgjsQeKo/tester1/util.cpp:13: multiple definition of 'Interval::print(std::ostream&) const'; /tmp/ccy7X0X7.o:/tmp/codecl collect2: error: ld returned 1 exit status
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY