Data Structures and Algorithms in C/C++ a) Implement the addLargeNumbers function with the following prototype: void addLargeNumbers(const char *pNum1, const char *pNum2); This function should output the result of adding the two numbers passed in as strings. Here is an example call to this function with the expected output: /* Sample call to addLargeNumbers */ addLargeNumbers("592", "3784"); /* Expected output */ 4376 b)  Implement a test program that demonstrates adding at least three pairs of large numbers (numbers larger than can be represented by a long). c) (1 point) Make sure your source code is well-commented, consistently formatted, uses no magic numbers/values, follows programming best-practices, and is ANSI-compliant.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Data Structures and Algorithms in C/C++

a) Implement the addLargeNumbers function with the following prototype:

void addLargeNumbers(const char *pNum1, const char *pNum2);

This function should output the result of adding the two numbers passed in as strings. Here is an example call to this function with the expected output:

/* Sample call to addLargeNumbers */

addLargeNumbers("592", "3784");

/* Expected output */

4376

b)  Implement a test program that demonstrates adding at least three pairs of large numbers (numbers larger than can be represented by a long).

c) (1 point) Make sure your source code is well-commented, consistently formatted, uses no magic numbers/values, follows programming best-practices, and is ANSI-compliant. 

In this assignment you will implement an algorithm that uses stacks to add numbers of any size.
The largest magnitude of integers is limited. We are not able to add
18,274,364,583,929,273,748,525 and 8,129,498,165,026,350,236 because integer variables cannot
hold such large values, let alone their sum.
The problem can be solved if we treat these numbers as strings of numerals, store the numbers
corresponding to these numerals on two stacks, and then perform addition by popping from the
stacks. The pseudocode for this algorithm is as follows:
addLargeNumbers (numberl, number2)
read the numerals of the first number and store them on one stack
read the numerals of the second number and store them on another stack
var result := 0
while at least one stack is not empty
pop a numeral from each nonempty stack and add them to result
push the unit part of addition onto a new stack called the result stack
store the carry part of the addition in result
push result onto the result stack if it is not zero
pop numbers from the result stack and display them
The following diagram shows an example of adding numbers 592 and 3,784:
1
2
9.
1
592
+3784
4376
+ 4
+ 8
+ 7
+3
6.
17
13
4
2
operand-
Stack1
9.
4
8.
8.
operand-
Stack2
7
7
3
3
3
result-
7
7
Stack
6.
6.
6.
1
Transcribed Image Text:In this assignment you will implement an algorithm that uses stacks to add numbers of any size. The largest magnitude of integers is limited. We are not able to add 18,274,364,583,929,273,748,525 and 8,129,498,165,026,350,236 because integer variables cannot hold such large values, let alone their sum. The problem can be solved if we treat these numbers as strings of numerals, store the numbers corresponding to these numerals on two stacks, and then perform addition by popping from the stacks. The pseudocode for this algorithm is as follows: addLargeNumbers (numberl, number2) read the numerals of the first number and store them on one stack read the numerals of the second number and store them on another stack var result := 0 while at least one stack is not empty pop a numeral from each nonempty stack and add them to result push the unit part of addition onto a new stack called the result stack store the carry part of the addition in result push result onto the result stack if it is not zero pop numbers from the result stack and display them The following diagram shows an example of adding numbers 592 and 3,784: 1 2 9. 1 592 +3784 4376 + 4 + 8 + 7 +3 6. 17 13 4 2 operand- Stack1 9. 4 8. 8. operand- Stack2 7 7 3 3 3 result- 7 7 Stack 6. 6. 6. 1
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Declaring and Defining the Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education