declare a hugo integer by array or string.
Please help me!

(HugeInteger Class) Create a class HugeInteger that uses a 40-element array of digits to store integers as large as 40 digits each. Provide member functions input, output, add and substract. For comparing HugeInteger objects, provide functions isEqualTo, isNotEqualTo, isGreaterThan, isLessThan, isGreaterThanOrEqualTo and isLessThanOrEqualToeach of these is a "predicate" function that simply returns TRue if the relationship holds between the two HugeIntegers and returns false if the relationship does not hold. Also, provide a predicate function isZero. If you feel ambitious, provide member functions multiply, divide and modulus.

<Exercise How to programming C++>

Create a class HugeInteger that uses a 40-element array of digits to store integers as large as 40 digits each.

> when i declare, has notice : "do'nt enought memory"
So post your attempt then, so it doesn't look like you're just dumping your assignment on us and expecting a polished answer on a plate (it won't happen).

my code.

exam : When i add:

111 + 333 =444
but
444 + 666 -> do'nt has resault.

when strlen(num1) < strlen(num2) -> program do'nt execute

Attachments
#include <iostream>
#include <conio.h>
using namespace std;

void insert(char *s1,char *s2)
{
     char *s3;
     strcpy(s3,s2);
     strcat(s3,s1);
     strcpy(s1,s3);
}

void add(char *s1,char *s2,char *s3)
{
     
     int memory=0;
     for(int i=strlen(s1)-1;i>=0;i--)
     {
             int x;
             x=s1[i]+s2[i]+memory-2*48;
             memory=x/10;
             x%=10;
             s3[i]=x+48;
     }
     s3[strlen(s1)]=0;
     if(nho>0)
     insert(s3,"1");
}

void sub(char *s1,char *s2,char *s3)
{
     int debt=0;
     for(int i=strlen(s1)-1;i>=0;i--)
     {
             if(s1[i]>s2[i]+debt)
             {
             s3[i]=s1[i]-(s2[i]+debt)+48;
             debt=0;
             }
             else 
             {
                  debt=1;
                  s3[i]=10*debt+s1[i]-s2[i]-48;
             }
     }
}
             
int main()
{
    char s1[100];
    char s2[100];
    char s3[100];
    
    cout<<"The first hugo integer = ";
               cin>>s1;                             //I do'nt know declare a hugo integer by array integer??
    cout<<"\nThe second hugo integer = ";
                 cin>>s2;
                 
//Number 1 + Number 2    	
     add(s1,s2,s3);
    cout<<"\nTotal  = ";
    cout<<s3<<endl;
    
//Number 1 - number 2    
    sub(s1,s2,s3);
    cout<<"\nSub = "<<s3<<endl<<endl;
    
    system("pause");
    return 0;
}

So where is your class?

> Create a class HugeInteger that uses a 40-element array of digits to store
> integers as large as 40 digits each.

class HugeInteger {
  private:
    char myInt[40];
  public:
};

> Provide member functions input, output, add and substract etc etc
Now try ONE of those functions with the above and post your code.

Your code doesn't even compile properly.
What is this: if(nho>0) fix it

Ok, -> if(memory>0)

So where is your class?

> Create a class HugeInteger that uses a 40-element array of digits to store
> integers as large as 40 digits each.

class HugeInteger {
  private:
    char myInt[40];
  public:
};

> Provide member functions input, output, add and substract etc etc
Now try ONE of those functions with the above and post your code.

class HugeInteger {
private:
char myInt[40];
public:
void input();
void output();
void add(char *s1,char *s2,char *s3);
void sub(char *s1,char *s2,char *s3);
void insert(char *s1,char *s2);
};

Ok, i define functions in my code (file attach above)

Why does insert need 2 params?
Why does your implementation trash memory rather than copying to the instance variable.
None of your functions are members of a class.

This article has been dead for over six months. Start a new discussion instead.