Project #75418 - C++ homework

need to complete the code to work, instructions are commented in the code presented

 

//Purpose: to sum two large integers (up to 20 digits each).

 

//

 

//Input: digits of two integers

 

// It appears that a "partially filled array structure"

 

//from the text will be of value here.

 

//Output: the sum of the two large integers is written to the

 

//screen

 

//

 

//algorithm: computer version of the traditional paper and

 

// pencil algorithm.

 

//add low order digits, record carry.

 

//while digits remain,

 

// add next higher order digits and the carry, recording

 

// the carry

 

//If the sum is beyond the capacity of a 20 digit array to

 

//represent, the program, then report overflow.

 

#include <iostream>

 

#include <cstdlib>

 

#include <cctype>

 

const int MAX_DIGITS = 20;

 

//fetches a sequence of digits from the input,

 

//converts to integer values, records size

 

void input( int number[], int& size);

 

//displays the Large_integer's digits in correct order

 

//on the screen

 

void output( const int number[], int size);

 

//input: two large integers

 

//output: a large integer that is the sum of the inputs

 

void add ( int first[], int first_size, int second[],

 

int second_size, int sum[], int& sum_size);

 

 

 

int main()

 

{

 

//Design decision: lower indices correspond

 

//to lower order digits

 

using namespace std;

 

int first[MAX_DIGITS+1];

 

int first_size; //number of digits first_size

 

int second[MAX_DIGITS +1];

 

int second_size;

 

int sum[MAX_DIGITS +1];

 

int sum_size;

 

cout << "Large integer summing program " << endl;

 

cout << "Please enter an integer, 20 digits or less "

 

<< endl;

 

input( first, first_size );

 

cout << "you entered " << endl;

 

output (first, first_size);

 

cout << endl;

 

cout << "Enter another integer, 20 digits or less" << endl;

 

input( second, second_size );

 

cout << "you entered " << endl;

 

output (second, second_size);

 

cout << endl << endl;

 

cout << "The sum is: " << endl;

 

output(first, first_size);

 

cout << endl;

 

output(second, second_size);

 

cout << endl;

 

cout << "----------------------" << endl;

 

add(first, first_size, second,

 

second_size, sum, sum_size );

 

output( sum, sum_size );

 

cout << endl;

 

return 0;

 

}

 

 

 

Subject Computer
Due By (Pacific Time) 07/02/2015 09:00 am
Report DMCA
TutorRating
pallavi

Chat Now!

out of 1971 reviews
More..
amosmm

Chat Now!

out of 766 reviews
More..
PhyzKyd

Chat Now!

out of 1164 reviews
More..
rajdeep77

Chat Now!

out of 721 reviews
More..
sctys

Chat Now!

out of 1600 reviews
More..
sharadgreen

Chat Now!

out of 770 reviews
More..
topnotcher

Chat Now!

out of 766 reviews
More..
XXXIAO

Chat Now!

out of 680 reviews
More..
All Rights Reserved. Copyright by AceMyHW.com - Copyright Policy