A community for students.
Here's the question you clicked on:
 0 viewing
Jas11
 2 years ago
need help finishing a code
Jas11
 2 years ago
need help finishing a code

This Question is Closed

Jas11
 2 years ago
Best ResponseYou've already chosen the best response.0#include <iostream> #include<string> using namespace std; //This program will test three functions capable of reading, adding, //and printing 100digit numbers. // Do not change these function prototypes: void readBig(int[]); void printBig(int[]); void addBig(int[], int[], int[]); // This constant should be 100 when the program is finished. const int MAX_DIGITS = 100; //There should be no changes made to the main program when you turn it in. int main() { // Declare the three numbers, the first, second and the sum: int num1[MAX_DIGITS], num2[MAX_DIGITS], sum[MAX_DIGITS]; bool done = false; char response; while (!done) { cout << "Please enter a number up to "<<MAX_DIGITS<< " digits: "; readBig(num1); cout << "Please enter a number up to "<<MAX_DIGITS<< " digits: "; readBig(num2); addBig(num1, num2, sum); printBig(num1); cout << "\n+\n"; printBig(num2); cout << "\n=\n"; printBig(sum); cout << "\n"; cout <<"test again?"; cin>>response; cin.ignore(900,'\n'); done = toupper(response)=='N'; } return 0; } void readBig(int x[]) { int length, i, oneLess, l; string number; getline(cin,number); length=number.length(); l=length1; oneLess=MAX_DIGITS1; for(i=0;i<MAX_DIGITS;i++) { x[i]=0; } for(i=0;i<length;i++) { x[oneLessl]=number[i]'0'; l; } } void printBig(int a[]) { int d, count, i, b; bool x=true; count=99; for(d=0; x && d<100 ;d++) { if(a[d]=0) { count; } else { x=false; for(i=count;i<100;i++) { cout<<a[d]; } //d=100; } for(b=count;b<100;b++) { cout<<a[d]; } } } void addBig(int a[], int b[], int c[]) { } //ReadBig will read a number as a string, //It then converts each element of the string to an integer and stores it in an integer array. //Finally, it reverses the elements of the array so that the ones digit is in element zero, //the tens digit is in element 1, the hundreds digit is in element 2, etc. //AddBig adds the corresponding digits of the first two arrays and stores the answer in the third. //In a second loop, it performs the carry operation. //PrintBig uses a while loop to skip leading zeros and then uses a for loop to print the number.

Jas11
 2 years ago
Best ResponseYou've already chosen the best response.0need help finishing the addBig and printBig functions

eSpeX
 2 years ago
Best ResponseYou've already chosen the best response.0If I understand your addBig() function, you are taking the number from the same index out of each array, adding them, then storing it in a third array. So you will have a for loop where you have array3[i] = array2[i] + array1[i]; and presumably you will do something with it there since you are neither passing by reference or returning a value.

Jas11
 2 years ago
Best ResponseYou've already chosen the best response.0@eSpeX would i start it out like inti; for(i=0;i<MAX_DIGITS;i++)

eSpeX
 2 years ago
Best ResponseYou've already chosen the best response.0Assuming MAX_DIGITS is the size of your array, yes. You want your index to step through each element of your array.

Jas11
 2 years ago
Best ResponseYou've already chosen the best response.0well this is what the code is supposed to do Write functions for doing arithmetic on 100digit integers. Include functions for input, output, and addition. The input function should not print anything. The addition function should do no reading or printing. No function should make any assumptions about how the other functions or main program work. The number of digits should be in a global constant. The function prototypes should be as follows: void readBig(int[]) void addBig(int[],int[],int[]) void printBig(int[])

eSpeX
 2 years ago
Best ResponseYou've already chosen the best response.0I see where you are getting an integer from the user, what are you doing if that number isn't as big as 100 digits?

Jas11
 2 years ago
Best ResponseYou've already chosen the best response.0well my teacher wrote us the main function and told us not to change it, he wants us to add the three add, print, and read functions

eSpeX
 2 years ago
Best ResponseYou've already chosen the best response.0Did your teacher also write the readBig() method or is that something you created?

Jas11
 2 years ago
Best ResponseYou've already chosen the best response.0i wrote the readBig function

eSpeX
 2 years ago
Best ResponseYou've already chosen the best response.0The same loop you use for setting the values of the array is the same method you will use to step through the addition. You just have two arrays and a temp, so you will need to create a temp[] and then loop through saying that temp[i] = x[i] + y[i]; you will need to add some error handling in the event the two numbers go over 10 so you can carry it on to the next iteration.
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.