Question: (2) Addition and Subtraction Write an addition function add(x, y) and a subtraction function subtract(x, y) Suppose we have two positive pqnumber objects x

(2) Addition and Subtraction Write an addition function add(x, y) and a

(2) Addition and Subtraction Write an addition function add(x, y) and a subtraction function subtract(x, y) Suppose we have two positive pqnumber objects x and y. The function to calculate the sum of x and y is computed as the following decimal representation. x + y = (x + y) 10s s=-p 2 . However, because we can have x + ys > 9, this decimal representation cannot be used directly. So we need a carry-over function that moves the extra digits in the appropriate way. Same as one would do when adding two large numbers on paper. Also we need a special provision for overflow, because the sum of two pqnumber objects can be too big to be a pqnumber 3. Likewise, a subtraction function should have a borrowing function that borrows 10 in the same way as you would do a subtraction with pencil-and-paper. Your functions should work for both positive and negative pqnumber objects. Both functions should return a pqnumber object with enough p and q to carry the result. This question accounts for 60% of this assignment.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Mathematics Questions!