structions. subtractBigInteger() – When an integer has more than a certain number of digits, it is represented using scientific notation. The int type itself cannot be used to store numbers with more than 10 digits. In some cases, this may be inconvenient as people usually expect complete numbers and doing big integer computations are inevitable. This method takes two numbers as CharStacks num1 and num2, and subtract the number stored in num2 from the one stored in num1, i.e., num1 - num2. To simply implementation, you can assume that the number stored in num1 is no less than the number stored in num2. For example, when subtracting 181,749 from 314,739,847, the two stacks and the result stack would

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

In this programming question, you are required to implement five methods according to the

following instructions.

subtractBigInteger() – When an integer has more than a certain number of digits, it is represented using scientific notation. The int type itself cannot be used to store numbers with more than 10 digits. In some cases, this may be inconvenient as people usually expect complete numbers and doing big integer computations are inevitable. This method takes two numbers as CharStacks num1 and num2, and subtract the number stored in num2 from the one stored in num1, i.e., num1 - num2. To simply implementation, you can assume that the number stored in num1 is no less than the number stored in num2. For example, when subtracting 181,749 from 314,739,847, the two stacks and the result stack would look like the following:

'7' low digit '4'

'3' high digit '1'

'8'
'9' '9' '5' '3' '4' '5' '7' '7' '8'

'4'

'4' high digit '1' '1'

'3'

num1

'0' low digit '8' '9'

'1' '8'

num2 stackResult

In this method, you are provided with a char stack, stackResult. You will need to perform subtractions between the two operands and save the result on the result stack.

Pay attention to the order of the digits (see above figure for reference). You should compute the subtraction between the two big numbers digit by digit (from low to high). Be sure to take care of borrows. Do not create any arrays or import the java.math.BigInteger library or anything from the Character, Integer, Double, and String classes in your implementation! You are only supposed to deal with the digits at the char and int level and make use of stacks.

computePI(int n) – One remarkably simple formula for approximating the value of ? is the

?11111
so-called Madhava–Leibniz series: = 1 − + − + − ⋯ +/− . Note that the

4 3579 2?−1
result of the series is a quarter of ?. The accuracy of the approximation is dependent on

the value of n. This method takes an int parameter n and calculates the value of ?, rather than ?/4. Pay attention to the sign (positive or negative) of each term.

upperStackRec(CharStack s) – This method takes a character stack and converts all lower case letters to upper case ones. Do NOT create any auxiliary data structure, including but not limited to array(s), queue(s), and list(s). Primitive variables are okay.

reverseStringRec(String s) – This method reads a string and returns the string in the reversed order.

numOccurrencesRec(LNode node, int n, int key) – This method takes as parameters a reference to the head of a linked list, a position specified by n, and a key. It returns the number of occurrences of the key in the linked list beginning at the n-th node. If n = 0, it means you should search in the entire linked list. If n = 1, then you should skip the first node in the list. Do NOT create any additional nodes or any other auxiliary structures (for instance, an array). Do NOT alter the data field of any nodes.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY