Write a 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...

1 answer below »

Write a 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 getValue1 to return the first value of the object.

• A function named getValue2 to return the second value of 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). You may come up with a more meaningful declaration for this function!

• 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). You may come up with a more meaningful declaration for this function!

Use a client code to test the orderedPair ADT:

1. Declare 2 orderedPair instances pOne, and pTwo (101, 201).

2. Set the values of pOne to (1009, 1011).

3. Display the values of pOne and pTwo.

4. Get Next values of both pOne and pTwo and save the results to pOneNext and pTwoNext.

5. Get previous values of both pOne and pTwo and save the results to pOnePrevious and pTwoPrevious.

6. Save the result of pOne + pOneNext - pOnePrevious in pOneResult.

7. Save the result of pTwoNext - pTwoPrevious +pTwo in pTwoResult.

8. Compare pOneResult with the next values of pOneNext and display whether or not they are equal.

9. Compare pTwoPrevious + (6, 6) with pTwoResult and display whether or not they are equal.
Answered Same DayNov 09, 2022

Answer To: Write a C++ program that defines an abstract data type orderedPair for modeling ordered pairs of two...

Nidhi answered on Nov 10 2022
52 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here