Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

(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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microeconomics An Intuitive Approach with Calculus

Authors: Thomas Nechyba

1st edition

538453257, 978-0538453257

More Books

Students also viewed these Mathematics questions

Question

What is negotiation? What are its characteristics?

Answered: 1 week ago

Question

Prepare a checklist for ensuring effective meetings.

Answered: 1 week ago

Question

What information is contained in the agenda of a meeting?

Answered: 1 week ago