Rapunzel if you can could you comment it a little bit to helpme with seeing what
ID: 3619293 • Letter: R
Question
Rapunzel if you can could you comment it a little bit to helpme with seeing what you did throughout this project.#include <iostream>
using namespace std;
#define MAX 20
void unpack(char[],int[],int&);
void add(int[],int[],int[],int,int,int&);
void print(int[],int[],int[],int,int,int);
void printin(int[],int);
int main()
{char input[MAX];
int n1[MAX],n2[MAX],n3[MAX],l1,l2,l3;
char more='Y';
while(toupper(more)=='Y')
{cout<<"Enter number 1: ";
cin>>input;
unpack(input,n1,l1);
cout<<"Enter number 2: ";
cin>>input;
unpack(input,n2,l2);
add(n1,n2,n3,l1,l2,l3);
print(n1,n2,n3,l1,l2,l3);
cout<<"another (Y/N)? ";
cin>>more;
cout<<endl<<endl;
}
return 0;
}
void printit(int a[],int n)
{int i;
for(i=n-1;i>=0;i--)
cout<<a[i];
}
void print (int a[],int b[],int c[],int la,int lb,int lc)
{int i;
printit(a,la);
cout<<" + ";
printit(b,la);
cout<<" = ";
printit(c,lc);
cout<<endl<<endl;
}
void add(int a[],int b[],int c[],int la,int lb,int& lc)
{int i,carry=0,n,m;
n=la;
if(lb>n)
n=lb;
for(i=0;i<n;i++)
{m=a[i]+b[i]+carry;
carry=m/10;
c[i]=m%10;
}
lc=n;
if(carry!=0)
if(n==MAX)
cout<<"integeroverflow ";
else
{c[n]=carry;
lc++;
}
}
void unpack(char in[],int a[],int &n)
{int i,count;
for(i=0;in[i]!='';i++);
n=i;
for(i=0;i<n;i++)
a[i]=in[n-1-i]-48;
for(i=n;i<MAX;i++)
a[i]=0;
cout<<endl;
}
Rapunzel if you can could you comment it a little bit to helpme with seeing what you did throughout this project.
#include <iostream>
using namespace std;
#define MAX 20
void unpack(char[],int[],int&);
void add(int[],int[],int[],int,int,int&);
void print(int[],int[],int[],int,int,int);
void printin(int[],int);
int main()
{char input[MAX];
int n1[MAX],n2[MAX],n3[MAX],l1,l2,l3;
char more='Y';
while(toupper(more)=='Y')
{cout<<"Enter number 1: ";
cin>>input;
unpack(input,n1,l1);
cout<<"Enter number 2: ";
cin>>input;
unpack(input,n2,l2);
add(n1,n2,n3,l1,l2,l3);
print(n1,n2,n3,l1,l2,l3);
cout<<"another (Y/N)? ";
cin>>more;
cout<<endl<<endl;
}
return 0;
}
void printit(int a[],int n)
{int i;
for(i=n-1;i>=0;i--)
cout<<a[i];
}
void print (int a[],int b[],int c[],int la,int lb,int lc)
{int i;
printit(a,la);
cout<<" + ";
printit(b,la);
cout<<" = ";
printit(c,lc);
cout<<endl<<endl;
}
void add(int a[],int b[],int c[],int la,int lb,int& lc)
{int i,carry=0,n,m;
n=la;
if(lb>n)
n=lb;
for(i=0;i<n;i++)
{m=a[i]+b[i]+carry;
carry=m/10;
c[i]=m%10;
}
lc=n;
if(carry!=0)
if(n==MAX)
cout<<"integeroverflow ";
else
{c[n]=carry;
lc++;
}
}
void unpack(char in[],int a[],int &n)
{int i,count;
for(i=0;in[i]!='';i++);
n=i;
for(i=0;i<n;i++)
a[i]=in[n-1-i]-48;
for(i=n;i<MAX;i++)
a[i]=0;
cout<<endl;
}
Explanation / Answer
x.x."AOLMsgPart_2_b0e1a2b3-c774-4f61-a6a7-84a95a90e05f">please rate - thanks #include using namespace std; #define MAX 20 void unpack(char[],int[],int&); void add(int[],int[],int[],int,int,int&); void print(int[],int[],int[],int,int,int); void printin(int[],int); int main() {char input[MAX]; int n1[MAX],n2[MAX],n3[MAX],l1,l2,l3; //l1,l2,l3 are the number of digits(elements) in each corresponding array char more='Y'; //prime loop to keep executing while(toupper(more)=='Y') {coutinput; unpack(input,n1,l1); //break it into digits and put into array n1, which will be of length l1 coutinput; //do the same thing for number 2 unpack(input,n2,l2); add(n1,n2,n3,l1,l2,l3); //add the numbers n3=n1+n2 print(n1,n2,n3,l1,l2,l3); //print them coutmore; coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.