Question
PROJECT: Add Large Integers In C++, the largest int value is 2147483647. So, an integer larger than this cannot be stored and processed as an
PROJECT: Add Large Integers
In C++, the largest int value is 2147483647. So, an integer larger than this cannot be stored and processed as an integer. Similarly, if the sum or product of two positive integers is greater than 2147483647, the result will be incorrect. One way to store and manipulate large integers is to store each individual digit of the number in an array. Write a program that inputs two positive integers of any length and outputs the sum of the numbers. Your program must, at least, contain those functions:
A function to read and store a number into a dynamic array created in the function. This function must then return the address of this dynamic array. (Must be done in the specified way. Otherwise 0 credit)
A function to add two numbers stored in arrays and return the sum result as a pointer. This means the sum result must be stored in a dynamic array created in this function. (Must be done in the specified way. Otherwise 0 credit)
A function to print out a number stored as an array of digits.
You may add additional functions when fit.
The required functions may look like this:
// read in a number
int* readNum(int& numOfDigits/*OUT*/);
// add two numbers. Store result in third
int* sumNum(const int * pNum1/*IN*/, int numOfDigits1/*IN*/,
const int * pNum2/*IN*/, int numOfDigits2/*IN*/,
int& numOfDigitsResult/*OUT*/);
// print a number stored in int array
void print(const int * pNum/*IN*/, int numOfDigits/*IN*/);
Your .cpp file should also contain:
Algorithms (pseudo code) for your main and the function to add two numbers. Add them as block comments at the beginning of your source code file. Pre- and Post- condition comments for each function.
/*IN*/, /*OUT*/, /*INOUT*/ comments to function parameters
The screenshot below shows a sample run.
Test your program with at least three different testing cases and provide matching screenshots of your running program. Explain how each testing case is different.
Comment your program appropriately. Pay attention to the standard stuff like coding style, indention, heading, and curly braces.
I am using visual studio.
Rubric:
Item | Max % | Received % |
|
|
|
Project (90%) |
|
|
Algorithm (main and the function to add) which matches your code | 10 |
|
a function to read and store a number into a dynamic array | 4 |
|
a function to add two numbers stored in arrays and return the sum result as a pointer | 4 |
|
a function to print out a number stored as an array of digits | 4 |
|
Proper Pre- and Post- condition comment for each function | 4 |
|
Function parameter type comment on each parameter | 4 |
|
|
|
|
Input a number and store in a dynamic array | 5 |
|
return the address of the dynamic array | 2 |
|
|
|
|
add two numbers | 15 |
|
correct carryings | 5 |
|
store sum result in a dynamic array | 3 |
|
return the address of the sum result | 2 |
|
|
|
|
Output the sum result stored in array of digits | 5 |
|
|
|
|
Dynamic arrays freed properly | 3 |
|
|
|
|
Three testing cases and rational | 5 |
|
|
|
|
Your project compiles and runs | 5 |
|
Programming style Meaningful names for constants and variables Correct indentation: 2 spaces for each level | 5
|
|
Comments Prolog comments Proper comments in the program | 5 |
|
|
|
|
Penalty |
|
|
using namespace std; | (- 5) |
|
Global variable(s) | (- 5) |
|
Missing .cpp source code file(s) | (- 5) |
|
Missing required screenshot(s) | (- 5) |
|
|
|
|
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