Home / Expert Answers / Computer Science / write-a-mathrm-c-program-that-defines-an-abstract-data-type-orderedpair-for-modeling-orde-pa653

(Solved): Write a \( \mathrm{C}++ \) program that defines an abstract data type orderedPair for modeling orde ...




Write a \( \mathrm{C}++ \) program that defines an abstract data type orderedPair for modeling ordered pairs of two int numbe
Write a \( \mathrm{C}++ \) program that defines an abstract data type orderedPair for modeling ordered pairs of two int numbers, e.g., \( (1,-1) \). The class contains: - Data field values of the int type that represent the values stored in the object. - A default constructor that creates an orderedPair object for the pair \( (0,0) \). - A constructor that constructs an orderedPair object with the specified values. - A function named getvalue to return the pair values for the object. - A function named setValue to set (change) the pair values for the object. - A comparison operator = to compare whether or not the two objects of the orderedPair are equal. Two pairs are equal if and only if their first elements are equal and their second elements are equal. For example, the ordered pair \( (1,2) \) is not equal to the ordered pair \( (2,1) \). - An addition operator + to return the result of adding two orderedPair objects. In an ordered pair, such as \( (x, y) \), the first value is called the \( x \)-coordinate and the second value is the \( y \) coordinate. Only values of the same coordinates are added together. For example, \( (1,2)+(2,2) \) \( =(3,4) \). - A subtraction operator - to return the result of subtracting two orderedPair objects. Only values of the same coordinates are subtracted. For example, \( (1,2)-(2,2)=(-1,0) \). - A function named getNext to return an orderedPair object that represents the next immediate pair of the two numbers after the current pair in the object. For example, \( (3,4) \) is the next immediate pair \( (2,3) \). - A function named getPrevious to return an orderedPair object that represents the previous immediate pair of the two numbers before the current pair in the object. For example, \( (3,4) \) is the previous immediate pair \( (4,5) \).


We have an Answer from Expert

View Expert Answer

Expert Answer


//Problem Solved #include using namespace std; class orderedPair { int first,second; public: orderedPair(){ first = 0; second = 0; } orderedPair(int first,int second) { this->first = first; this->se
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe