Can anyone tell me or help me to build a Class that will take arbitarily long integers and do the arithmatic operation on them ?
Can anyone tell me or help me to build a Class that will take arbitarily long integers and do the arithmatic operation on them ?
We all are the components of a huge program...... the programmer is always debugging us with His debugger.
Its pretty easy to do. Use strings or character arrays and overload the arithmetic operators.
The basics:
- Store blocks of the integer in a primitive type (probably unsigned char).
- Overload the arithmetic operators (make sure to store any values that carry over).
- Include a member for the sign (bool possibly, or possibly a specific bit in the data).
There are libraries out there that have this capability (try Google). It would help if you showed what you have done so far.
The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.
you'll probably need to reference the monumental
"The Art of Computer Programming"
Volume 2 - Seminumerical Algorithms
in order to optimize the code.
I've done it only in C
to boldy code where...
I am looking for a class................
We all are the components of a huge program...... the programmer is always debugging us with His debugger.
We are telling you what needs to be included in the class. If you are looking for someone to give you a prewritten class that does everything you want, it ain't gonna happen.
Show us what you have written so far and we will help out though.
Why this not gonna heppen I don't know..........Originally posted by PJYelton
We are telling you what needs to be included in the class. If you are looking for someone to give you a prewritten class that does everything you want, it ain't gonna happen.
Show us what you have written so far and we will help out though.
I have searched in the web got few........outline and code segment.................
And I've not got that Knuth's book........not available here
Ok! You can see my just (+) operatinos code but after doing this and as it's not working as I thought ((
Code:#include<iostream.h> #include<string.h> #include<stdlib.h> #include<conio.h> char *sum(char n1[1000],char n2[1000]); int main() { char num[120]={0}; char ans[120]={0}; while(cin >> num) { if(atol(num)==0)break; strcpy(ans,sum(ans,num)); num[0]=NULL; } cout << ans << endl;getch(); return 0; } char *rev(char str[1000]) { int l=strlen(str); char tmp[1000]={0}; for(int i=0;i<l;i++) tmp[i]=str[(l-1)-i]; strcpy(str,tmp); return str; } char *sum(char n1[1000],char n2[1000]) { int l1=strlen(n1); int l2=strlen(n2); if(l1>l2) { char tmp[1000]; strcpy(tmp,n1); strcpy(n1,n2); strcpy(n2,tmp); int tl; tl=l1; l1=l2; l2=tl; } char cry='0'; char ch[1000]={0}; int lsm=(l1>l2)?l2:l1; for(int i=1;i<=lsm;i++) { if(cry=='1') ch[i-1]=(char)(*(n1+l1-i)+*(n2+l2-i)-'0'+'1'-'0'); else ch[i-1]=(char)(*(n1+l1-i)+*(n2+l2-i)-'0'); if(ch[i-1]>'9') { cry='1'; (ch[i-1]-=10); } else { cry='0'; } } int ldf=(l2-lsm); char chh[1000]={0}; for(int j=1;j<=ldf;j++) { if(cry=='1') chh[j-1]=(char)(*(n2+ldf-j)+'1'-'0'); else chh[j-1]=(char)(*(n2+ldf-j)); if(chh[j-1]>'9') { cry='1'; (chh[j-1]-=10); } else { cry='0'; } } static char ans[1000]={0}; if(cry=='1') { strcpy(ans,strcat("1",strcat(rev(chh),rev(ch)))); return (ans); } else { strcpy(ans,strcat(rev(chh),rev(ch))); return (ans); } }
We all are the components of a huge program...... the programmer is always debugging us with His debugger.
In this particular case, I would use unsigned char instead of signed (normal) char. Also, I wouldn't worry about string operations with the character arrays, but instead use the chars simply as 8-bit ints (each one capable of storing a maximum value of 256, not just a single digit). The result would be to treat your unsigned char* not as a string, but as you would an int* (for example).
The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.
Originally posted by Zach L.
In this particular case, I would use unsigned char instead of signed (normal) char. Also, I wouldn't worry about string operations with the character arrays, but instead use the chars simply as 8-bit ints (each one capable of storing a maximum value of 256, not just a single digit). The result would be to treat your unsigned char* not as a string, but as you would an int* (for example).
sounds great...............!
But if I can made a class or get one this will be very easy to use like Java's BigNumber class...........
We all are the components of a huge program...... the programmer is always debugging us with His debugger.
There are links to several libraries here.
Ahh... the power of Google.
The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.
Thanks! But these are all for Linux........
Ok! If you get links like this plz inform here
We all are the components of a huge program...... the programmer is always debugging us with His debugger.
They're most likely standard C/C++. If so, they'll work on any platform with a standard compliant compiler. GNU MP looks like a decent one, and it says its portable.
The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.