Answered step by step
Verified Expert Solution
Question
1 Approved Answer
(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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started