Huge Integers

Pages: 12
Create a list of functions that uses a 64-element array of digits to store integers as large as 64 digits each (we will call these integers Huge Integers).

requirements

The program must contain the following functions:
char* add( char* A , char* B, char* C );
char* subtract( char* A, char* B, char* C );
void negate( char* A, char* B );
void copy( char* A, char*B );
void read( char* A );
void print( char* A );
int getSign( char* A );
int getLength( char* A );

You must also write a main to test these functions.

Description of the functions above
add Adds two Huge Integers (A, B) and returns the result in C. You must take into consideration that the numbers are signed.
subtract Same as above but the operation is subtract.
negate Returns –A in B.
copy Copies A to B.
read Reads A from the keyboard.
print Displays A.
int getSign( char* A ) Returns 0 for positive, 1 for negative.
int getLength( char* A ) Returns the number of valid digits in A.

The numbers are considered signed so a position in the array must be reserved for the sign.

The following C++ libraries functions manipulating strings could be used:
strlen -- returns the length of a given string
#include <cstring>
size_t strlen( char *str );
The strlen() function returns the length of str (determined by the number of characters before null termination). Str may not be null.
strcpy -- copies one string to another
#include <cstring>
char *strcpy( char *dest, const char *src );
The strcpy() function copies characters in the string src to the string dest, including the null termination. The return value is dest. Note that strcpy() does not perform bounds checking, and thus risks overrunning from or to. For a similar (and safer) function that includes bounds checking, see strncpy().
strncpy -- copies one string to another
#include <cstring>
char *strncpy( char *to, const char *from, size_t count );
The strncpy function copies at most count characters of from to the string to. If from has less than count characters, the remainder is padded with '\0' characters. The return value is the resulting string.
You can use the following test to check the validity of a digit i in the Huge Integer number :
If( number[ i ] <= '9' && number[ i ] >= '0' )
You better get to it.
man i should submit this homework by tomorrow and i m not getting to something
if any one can help in solving it will be gr8
I can help, post what you have done so far...

There's a clue in there ^^ it's got something to do with character arrays, not actual "HUGE INTS".
Last edited on
k look this is a sample about the function we should use

#include <iostream>
#include <string.h>

using namespace std;

// This function fills an array of characters of size 65 with a string
// of characters composed of digits. The digits values (not codes) are
// copied to the array the least significant (smallest weight) being the
// first element in tha array. For example if the string is "123", the
// array will be filled with {3,2,1,'\0'} not {'3','2','1','\0'}
void build( char const* strNumber, char* str )
{
int length = strlen( strNumber );
cout << length << endl;
for( int i = length - 1 ; i >= 0 ; i-- )
{
if( strNumber[ i ] < '0' || strNumber[ i ] > '9' )
break;
else
str[ length - 1 - i ] = strNumber[ i ] - '0';
}
str[ length ] = '\0';
}

// This functions reads a string of digits from the keyboard and uses it to create
// an array of digit values (see build above)
void read( char* str )
{
char* s = new char[ 65 ];
cout << "Type a number";
cin >> s;
build( s, str );
}

int main ()
{
char* s = new char[ 65 ];
read( s );
cout << s;

return 0;
}
You should be able to implement the other functions, things like copy() is easy, the teacher has already given you the answer: char *strncpy( char *to, const char *from, size_t count );
man i m bad in those stuff :( i m not getting anything , and its a graded assignment , can u write the whole thing plzzzzzzzzzzz
lol sure, pay me $2000 up front.
heh ur kidding yeah ??
i thought people help these days
How would doing your work for you be helping? What would you learn from that?

chichi wrote:
heh ur kidding yeah ??

no not rly
Last edited on
This isn't a homework service. If you have problems with something in particular, we'll help, but we're not going to do your homework for you.
u know my major is civil eng not programing so helping in this HW will help me getting a good grade for that i wont get a lower GPA, because C++ is only for civil an introductory course

hope u can help, u will made my day
u know my major is civil eng

I don't think I want you working on buildings and bridges and things people depend on if you won't take the time to learn anything.
hehe man i m in eng stuff one of the best students trust me on this , but programing not my stuff, so man if u want to help i appreciate it , thank u for your time man ))
I do want to help, I think it's just unfortunate you don't want to help yourself....

anyway I'm out of this thread, going to bed..
Last edited on
any 1 can help because i need it , if i dnt need it i wont posted her
I recommend that you re-read the "Welcome -- read before posting!" announcement on this list; specifically the section on homework.
Last edited on
mm i did but i have no other solution, so...
guys i m not understanding anything no one can help in solving???
Pages: 12