Solved

Create a class using an array to represent an integer of upto 40 digits, allow for basic math + - as well as multiplication = == < > etc

Posted on 2007-11-29
22
359 Views
Last Modified: 2013-12-14
I am working on an assignemnet and I have some issues with my code it isn't compiling for me and I am a bit stumped.  I still need to add multiplication (which I am lost on) and equality operators but what i have is below. Essentially I need to use an array to store an integer of upto 40 digits and be able to perform basic operations on them.

Here is my code ifyou can help I'd appreciate it, been fighting with this for a little over a week.  Looked for other examples but none seemed to be doing it the same way I was.  they were using character arrays
-------------------------
#include <iostream>
#include <string>

using std::string;

class HugeInteger
{

public:
      
      HugeInteger( int startValue );
      HugeInteger( HugeInteger &operand2 );      
      HugeInteger addition( HugeInteger &operand2 );
      void setElement( const int index, const int newElement );
      void operator++();       
      string outputInteger();
      int getElement( int index );
      friend ostream &operator<<( ostream &output, HugeInteger &operand2 );
      friend istream &operator>>( istream &input, HugeInteger &operand2 );
      
      static const int SIZE= 40;

private:
      int bigInteger[SIZE];

};
------------------------------------------------------------
#include <iostream>
#include "HugeInteger.h"
#include <string>

using std::cout;
using std::endl;


HugeInteger::HugeInteger( HugeInteger &operand2 )
{
      for ( int i = 0; i < SIZE; i++ )
      {
            bigInteger[ i ] = &operand2.getElement( i );
      }
}

// Constructor that accepts a passed integer value
HugeInteger::HugeInteger( int passedValue )
{
      int newValue = passedValue;

      for ( int index = 0; index <= SIZE; index++ )
      {
            bigInteger[index] = 0;
      }

      if ( passedValue < 0 )
      {
            passedValue = 0;
      }

      for ( int index = SIZE - 1; index >= 0 ; index-- )
      {
            bigInteger[index] = newValue % 10;
            newValue /= 10;
      }
}

int HugeInteger::getElement( int element )
{
      if ( ( element < 0 ) || ( element > SIZE - 1 ) )
      {
            element = 0;
      }

      return bigInteger[element];
}

// Sets the index value of the array to newElement value
void HugeInteger::setElement( const int element, const int newElement )
{
      if ( ( element >= 0 ) && ( element < SIZE ) )
      {
            bigInteger[element] = newElement;
      }

      return;
}




void HugeInteger:operator++( )
{
      HugeInteger hugeInteger( 1 );

      cout << "*this: " << *this << endl;

      *this = (*this).addition( hugeInteger);

      cout << "*this: " << *this << endl;

      return;
}

// This function will addition to HugeIntegers together
HugeInteger HugeInteger::additionition( HugeInteger &operand2 )
{
      HugeInteger newHugeInt( 0 );
      int newElement = 0;
      int carry = 0;

      for ( int i = SIZE - 1; i >= 0; i-- )
      {
            newElement = bigInteger[ i ] + operand2.getElement( i ) + carry;

            // Once carry is used, reset to 0
            carry = 0;

            // Checks to see if newElement is greater than 10
            if ( newElement >= 10 )
            {
                  newElement = newElement - 10;
                  carry = 1;
            }

            // Sets new element into the HugeInteger
            newHugeInt.setElement( i, newElement );

      }


return newHugeInt;
}

ostream &operator<<( ostream &output, HugeInteger &operand2 )
{
      output << hugeInt.printHelper();

      return output;
}


string HugeInteger:printHelper()
{
      string output(" ");
      bool flag = false;

      for ( int i = 0; i < SIZE; i++ )
      {
            // check for null
            if ( ( bigInteger[ i ] == 0 ) && ( !flag ) )
            {
            }
            else
            {
                  flag = true;
                  char ch1[2];
                  ch1[0] = bigInteger[ i ] + '0';
                  ch1[1] = '\0';
                  string appendString(ch1);
                  output.append(appendString);
            }
      }


      return output;
}
0
Comment
Question by:urobins
  • 12
  • 5
  • 5
22 Comments
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 20374434
Hi urobins,

What errors are you getting?

A few observations:

The HugeInteger method within the HugeInteger class is executed at instantiation.  You have two HugeInteger methods defined which suggests that you want to create a HugeInteger and initialize it based on an integer value or another HugeInteger value.  Is this correct?

I don't think that you really want:

  static const int SIZE = 40;


And I've also got reservations about:

  int bigInteger[SIZE];


Kent
0
 

Author Comment

by:urobins
ID: 20374502
I am getting 40 errors so quite a few.  

Yeah I'd like to either create a blank object or be able to instantiate it with set number of elelments

II was thinking I should use a static to set the size of the array instead of dynamicaly but again I really don't have any idea :) I am open to any and all ideas to get this thing going :)
0
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 20374600
Hi Kdo,

One of the "gospels according to C programming" is that compilation errors need to be resolved from the first one encountered down.  It's often true that correcting one or two errors can eliminate dozens (or hundreds) of errors.

What are the first 5 or 6 errors?


Kent
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:urobins
ID: 20374677
Here is the first block  Thanks for the help.  I am so sick of looking at this code :)

error C2143: syntax error : missing ';' before '&'
hugeinteger.h(18) : error C2433: 'ostream' : 'friend' not permitted on data declarations
hugeinteger.h(18) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
hugeinteger.h(18) : error C2061: syntax error : identifier 'ostream'
hugeinteger.h(18) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
hugeinteger.h(18) : error C2805: binary 'operator <<' has too few parameters
hugeinteger.h(19) : error C2143: syntax error : missing ';' before '&'
hugeinteger.h(19) : error C2433: 'istream' : 'friend' not permitted on data declarations
hugeinteger.h(19) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
hugeinteger.h(19) : error C2061: syntax error : identifier 'istream'
hugeinteger.h(19) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
hugeinteger.h(19) : error C2805: binary 'operator >>' has too few parameters
0
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 20374792
Hi urobins,

Try replacing the line

  using std::string;

with

  using namespace std;


Good Luck,
Kent
0
 

Author Comment

by:urobins
ID: 20374980
okay that gets me to this, I don't know what an i-value is

hugeinteger.cpp(13) : error C2102: '&' requires l-value
hugeinteger.cpp(108) : error C2065: 'hugeInt' : undeclared identifier
hugeinteger.cpp(108) : error C2228: left of '.printHelper' must have class/struct/union
1>        type is ''unknown-type''
hugeinteger.cpp(114) : error C2039: 'printHelper' : is not a member of 'HugeInteger'
hugeinteger.h(7) : see declaration of 'HugeInteger'
hugeinteger.cpp(115) : error C2365: 'printHelper' : redefinition; previous definition was 'formerly unknown identifier'
test project 4\hugeinteger.cpp(119) : error C2065: 'SIZE' : undeclared identifier
test project 4\hugeinteger.cpp(122) : error C2065: 'bigInteger' : undeclared identifier
0
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 20376258
Hi urobins,

In the function headers, use '*' instead of '&'.


Good Luck,
Kent
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 20376296
>>>> In the function headers, use '*' instead of '&'.
No, the operators have to be defined with reference type and reference return.

It was the 'using' clause only what makes the errors.

Regards, Alex
0
 

Author Comment

by:urobins
ID: 20376809
?????
0
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 20379108

Repost the source.  Let's see what you've got now.

0
 

Author Comment

by:urobins
ID: 20379356
#include <iostream>
#include "HugeInteger.h"
#include <string>

using std::cout;
using std::endl;


HugeInteger::HugeInteger( HugeInteger &operand2 )
{
      for ( int i = 0; i < SIZE; i++ )
      {
            bigInteger[ i ] = &operand2.getElement( i );
      }
}

// Constructor that accepts a passed integer value
HugeInteger::HugeInteger( int passedValue )
{
      int newValue = passedValue;

      for ( int index = 0; index <= SIZE; index++ )
      {
            bigInteger[index] = 0;
      }

      if ( passedValue < 0 )
      {
            passedValue = 0;
      }

      for ( int index = SIZE - 1; index >= 0 ; index-- )
      {
            bigInteger[index] = newValue % 10;
            newValue /= 10;
      }
}

int HugeInteger::getElement( int element )
{
      if ( ( element < 0 ) || ( element > SIZE - 1 ) )
      {
            element = 0;
      }

      return bigInteger[element];
}

// Sets the index value of the array to newElement value
void HugeInteger::setElement( const int element, const int newElement )
{
      if ( ( element >= 0 ) && ( element < SIZE ) )
      {
            bigInteger[element] = newElement;
      }

      return;
}




void HugeInteger::operator++( )
{
      HugeInteger hugeInteger( 1 );

      cout << "*this: " << *this << endl;

      *this = (*this).addition( hugeInteger);

      cout << "*this: " << *this << endl;

      return;
}

// This function will addition to HugeIntegers together
HugeInteger HugeInteger::addition( HugeInteger &operand2 )
{
      HugeInteger newHugeInt( 0 );
      int newElement = 0;
      int carry = 0;

      for ( int i = SIZE - 1; i >= 0; i-- )
      {
            newElement = bigInteger[ i ] + operand2.getElement( i ) + carry;

            // Once carry is used, reset to 0
            carry = 0;

            // Checks to see if newElement is greater than 10
            if ( newElement >= 10 )
            {
                  newElement = newElement - 10;
                  carry = 1;
            }

            // Sets new element into the HugeInteger
            newHugeInt.setElement( i, newElement );

      }


return newHugeInt;
}

ostream &operator<<( ostream &output, HugeInteger &operand2 )
{
      output << hugeInt.printHelper();

      return output;
}


string HugeInteger::printHelper()
{
      string output(" ");
      bool flag = false;

      for ( int i = 0; i < SIZE; i++ )
      {
            // check for null
            if ( ( bigInteger[ i ] == 0 ) && ( !flag ) )
            {
            }
            else
            {
                  flag = true;
                  char ch1[2];
                  ch1[0] = bigInteger[ i ] + '0';
                  ch1[1] = '\0';
                  string appendString(ch1);
                  output.append(appendString);
            }
      }


      return output;
}

-----------------
#include <iostream>
#include <string>

using namespace std;

class HugeInteger
{

public:
      
      HugeInteger( int startValue );
      HugeInteger( HugeInteger &operand2 );      
      HugeInteger addition( HugeInteger &operand2 );
      void setElement( const int index, const int newElement );
      void operator++();       
      string outputInteger();
      int getElement( int index );
      friend ostream &operator<<( ostream &output, HugeInteger &operand2 );
      friend istream &operator>>( istream &input, HugeInteger &operand2 );
      
      static const int SIZE= 40;

private:
      int bigInteger[SIZE];

};
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 20380537
Some remarks:

A. HugeInteger.h

1. You should protect the header from being included twice

#ifndef HUGEINTEGER_H
#define HUGEINTEGER_H

// put her the current contents of the header

#endif

That matters if you add another header that included hugeinteger.h and have some cpp that includes both headers.

2. #include <string>

The string class wasn't used in the header. Then, you should omit the include.

3. using namespace std;

Omit that statement in the header. The using clauses should only be used in the .cpp files. That is to get conflicts when including third party libraries using the same names as in namespace std.

To prevent from compile errors you have to use the std:: prefix for STL classes in the header:

   friend std::ostream &operator<<( std::ostream &output, HugeInteger &operand2 );
   friend std::istream &operator>>( std::istream &input, HugeInteger &operand2 );

4. static const int SIZE= 40;

Some compilers do not accept const initializaion in class definition. You could use enum which was valid for all compilers:

   
      // static const int SIZE= 40;
      enum { SIZE = 40 };  // equivalent


B. HugeInteger.cpp

1. using std::cout;  using std::endl;

Here you can use

    using namespace std;

which is more comfortable.

2. bigInteger[ i ] = &operand2.getElement( i );

That is wrong syntax. You don't want to store the 'address'  (the & means the address) but the integer at position i.


     bigInteger[ i ] = operand2.getElement( i );


3. output << hugeInt.printHelper();

Must be

       output << operand2.printHelper();


4. output << operand2.printHelper();

The printHelper was not declared in the class definition.

You have to include <string>  (now it was needed!) and put the declaration to class HugeInteger:

   class HugeInteger
   {
           ...
           std::string printHelper();
 

That should compile.

Regards, Alex
0
 

Author Comment

by:urobins
ID: 20381664
I made these changes and still have 21 errors.... I am  pretty confused at this point.  Am I addressing this properly?  Here is my current code.

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

using std::cout;
using std::endl;


HugeInteger::HugeInteger( HugeInteger &operand2 )
{
      for ( int i = 0; i < SIZE; i++ )
      {
            bigInteger[ i ] = operand2.getElement( i );
      }
}

// Constructor that accepts a passed integer value
HugeInteger::HugeInteger( int passedValue )
{
      int newValue = passedValue;

      for ( int index = 0; index <= SIZE; index++ )
      {
            bigInteger[index] = 0;
      }

      if ( passedValue < 0 )
      {
            passedValue = 0;
      }

      for ( int index = SIZE - 1; index >= 0 ; index-- )
      {
            bigInteger[index] = newValue % 10;
            newValue /= 10;
      }
}

int HugeInteger::getElement( int element )
{
      if ( ( element < 0 ) || ( element > SIZE - 1 ) )
      {
            element = 0;
      }

      return bigInteger[element];
}

// Sets the index value of the array to newElement value
void HugeInteger::setElement( const int element, const int newElement )
{
      if ( ( element >= 0 ) && ( element < SIZE ) )
      {
            bigInteger[element] = newElement;
      }

      return;
}




void HugeInteger::operator++( )
{
      HugeInteger hugeInteger( 1 );

      cout << "*this: " << *this << endl;

      *this = (*this).addition( hugeInteger);

      cout << "*this: " << *this << endl;

      return;
}

// This function will addition to HugeIntegers together
HugeInteger HugeInteger::addition( HugeInteger &operand2 )
{
      HugeInteger newHugeInt( 0 );
      int newElement = 0;
      int carry = 0;

      for ( int i = SIZE - 1; i >= 0; i-- )
      {
            newElement = bigInteger[ i ] + operand2.getElement( i ) + carry;

            // Once carry is used, reset to 0
            carry = 0;

            // Checks to see if newElement is greater than 10
            if ( newElement >= 10 )
            {
                  newElement = newElement - 10;
                  carry = 1;
            }

            // Sets new element into the HugeInteger
            newHugeInt.setElement( i, newElement );

      }


return newHugeInt;
}

ostream &operator<<( ostream &output, HugeInteger &operand2 )
{
      output << operand2.printHelper();

      return output;
}


string HugeInteger::printHelper()
{
      string output(" ");
      bool flag = false;

      for ( int i = 0; i < SIZE; i++ )
      {
            // check for null
            if ( ( bigInteger[ i ] == 0 ) && ( !flag ) )
            {
            }
            else
            {
                  flag = true;
                  char ch1[2];
                  ch1[0] = bigInteger[ i ] + '0';
                  ch1[1] = '\0';
                  string appendString(ch1);
                  output.append(appendString);
            }
      }


      return output;
}
-----------------------
#include <iostream>


class HugeInteger
{

public:
      
      HugeInteger( int startValue );
      HugeInteger( HugeInteger &operand2 );      
      HugeInteger addition( HugeInteger &operand2 );
      void setElement( const int index, const int newElement );
      void operator++();       
      std::string printHelper();
      int getElement( int index );
      friend std::ostream &operator<<( ostream &output, HugeInteger &operand2 );
      friend std::istream &operator>>( istream &input, HugeInteger &operand2 );
      
      static const int SIZE= 40;

private:
      int bigInteger[SIZE];

};

0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 20381908
>>>> I made these changes and still have 21 errors....

Hmmm. You didn't apply the changes I suggested properly ...

The problems were in the header.

1. in the header was no header protection
2. You didn't include <string> what I described in B4.
3. ostream and istream *arguments* must be declared with std:: prefix
4. (change 'static const int SIZE= 40;' to 'enum (SIZE = 40);'

The point 4 is not essential if you get noc compiler error.

point 1 is essential if including the hugeinteger.h in another header.

point 2: <string> must be included when you were using std::string as a return type. Here I first thought you don't need it, but later it turns out that you have functions returning a string.

point 3: copy the istream and ostream functions I posted.


As it is an assignment I cannot post you full code. But I compiled your code with my changes and there is nothing left if you apply what I told with A 1/2/3/4 and B 1/2/3/4
in the previous comment.

0
 

Author Comment

by:urobins
ID: 20382211
Sorry, let me try again :)  I must not have saved changes before shutting down and coming into work :)
0
 

Author Comment

by:urobins
ID: 20382412
Sorry, but I must be missing something or misinterpreting what you're suggesting.  here is what I have.  I am getting 19 errors, I know I'm missing something... Thanks so much for your help.

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

using std::cout;
using std::endl;


HugeInteger::HugeInteger( HugeInteger &operand2 )
{
      for ( int i = 0; i < SIZE; i++ )
      {
            bigInteger[ i ] = operand2.getElement( i );
      }
}

// Constructor that accepts a passed integer value
HugeInteger::HugeInteger( int passedValue )
{
      int newValue = passedValue;

      for ( int index = 0; index <= SIZE; index++ )
      {
            bigInteger[index] = 0;
      }

      if ( passedValue < 0 )
      {
            passedValue = 0;
      }

      for ( int index = SIZE - 1; index >= 0 ; index-- )
      {
            bigInteger[index] = newValue % 10;
            newValue /= 10;
      }
}

int HugeInteger::getElement( int element )
{
      if ( ( element < 0 ) || ( element > SIZE - 1 ) )
      {
            element = 0;
      }

      return bigInteger[element];
}

// Sets the index value of the array to newElement value
void HugeInteger::setElement( const int element, const int newElement )
{
      if ( ( element >= 0 ) && ( element < SIZE ) )
      {
            bigInteger[element] = newElement;
      }

      return;
}




void HugeInteger::operator++( )
{
      HugeInteger hugeInteger( 1 );

      cout << "*this: " << *this << endl;

      *this = (*this).addition( hugeInteger);

      cout << "*this: " << *this << endl;

      return;
}

// This function will addition to HugeIntegers together
HugeInteger HugeInteger::addition( HugeInteger &operand2 )
{
      HugeInteger newHugeInt( 0 );
      int newElement = 0;
      int carry = 0;

      for ( int i = SIZE - 1; i >= 0; i-- )
      {
            newElement = bigInteger[ i ] + operand2.getElement( i ) + carry;

            // Once carry is used, reset to 0
            carry = 0;

            // Checks to see if newElement is greater than 10
            if ( newElement >= 10 )
            {
                  newElement = newElement - 10;
                  carry = 1;
            }

            // Sets new element into the HugeInteger
            newHugeInt.setElement( i, newElement );

      }


return newHugeInt;
}

std::ostream& operator<<( ostream &output, HugeInteger &operand2 )
{
      output << operand2.printHelper();

      return output;
}

std::istream& operator>>( istream &input, HugeInteger &operand2 );
{

}

string HugeInteger::printHelper()
{
      string output(" ");
      bool flag = false;

      for ( int i = 0; i < SIZE; i++ )
      {
            // check for null
            if ( ( bigInteger[ i ] == 0 ) && ( !flag ) )
            {
            }
            else
            {
                  flag = true;
                  char ch1[2];
                  ch1[0] = bigInteger[ i ] + '0';
                  ch1[1] = '\0';
                  string appendString(ch1);
                  output.append(appendString);
            }
      }


      return output;
}
----------------


#ifndef HUGEINTEGER_H
#define HUGEINTEGER_H

#include <iostream>


class HugeInteger
{

public:
      
      HugeInteger( int startValue );
      HugeInteger( HugeInteger &operand2 );      
      HugeInteger addition( HugeInteger &operand2 );
      void setElement( const int index, const int newElement );
      int getElement( int index );      
      std::string printHelper();
      void operator++();       
      friend std::ostream &operator<<( ostream &output, HugeInteger &operand2 );
      friend std::istream &operator>>( istream &input, HugeInteger &operand2 );
      
      //static const int SIZE= 40;
      enum { SIZE = 40 };

private:
      int bigInteger[SIZE];


};
#endif
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 20382715
>>> #ifndef HUGEINTEGER_H
>>> #define HUGEINTEGER_H

>>> #include <iostream>

Here you have to add

#include <string>

below #include <iostream>


>>>> friend std::ostream &operator<<( ostream &output, HugeInteger &operand2 );
Here the std:: is missing

      (std::ostream &output


>>>> friend std::istream &operator>>( istream &input, HugeInteger &operand2 );

Here the std:: is missing

      (std::istream &input


0
 

Author Comment

by:urobins
ID: 20382771
doh! I'll make those now!  Thanks!
0
 

Author Comment

by:urobins
ID: 20382830
Okay I changed those locations. Do I need to at the std:: to the .cpp functions as well?  I still get six errors I am getting.
hugeinteger.cpp(106) : error C2065: 'ostream' : undeclared identifier
hugeinteger.cpp(106) : error C2065: 'output' : undeclared identifier
hugeinteger.cpp(106) : error C2065: 'operand2' : undeclared identifier
hugeinteger.cpp(106) : error C2275: 'HugeInteger' : illegal use of this type as an expression

Any ideas?
Here is my code with what i believe were the corrections you recommended

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

using std::cout;
using std::endl;


HugeInteger::HugeInteger( HugeInteger &operand2 )
{
      for ( int i = 0; i < SIZE; i++ )
      {
            bigInteger[ i ] = operand2.getElement( i );
      }
}

// Constructor that accepts a passed integer value
HugeInteger::HugeInteger( int passedValue )
{
      int newValue = passedValue;

      for ( int index = 0; index <= SIZE; index++ )
      {
            bigInteger[index] = 0;
      }

      if ( passedValue < 0 )
      {
            passedValue = 0;
      }

      for ( int index = SIZE - 1; index >= 0 ; index-- )
      {
            bigInteger[index] = newValue % 10;
            newValue /= 10;
      }
}

int HugeInteger::getElement( int element )
{
      if ( ( element < 0 ) || ( element > SIZE - 1 ) )
      {
            element = 0;
      }

      return bigInteger[element];
}

// Sets the index value of the array to newElement value
void HugeInteger::setElement( const int element, const int newElement )
{
      if ( ( element >= 0 ) && ( element < SIZE ) )
      {
            bigInteger[element] = newElement;
      }

      return;
}




void HugeInteger::operator++( )
{
      HugeInteger hugeInteger( 1 );

      cout << "*this: " << *this << endl;

      *this = (*this).addition( hugeInteger);

      cout << "*this: " << *this << endl;

      return;
}

// This function will addition to HugeIntegers together
HugeInteger HugeInteger::addition( HugeInteger &operand2 )
{
      HugeInteger newHugeInt( 0 );
      int newElement = 0;
      int carry = 0;

      for ( int i = SIZE - 1; i >= 0; i-- )
      {
            newElement = bigInteger[ i ] + operand2.getElement( i ) + carry;

            // Once carry is used, reset to 0
            carry = 0;

            // Checks to see if newElement is greater than 10
            if ( newElement >= 10 )
            {
                  newElement = newElement - 10;
                  carry = 1;
            }

            // Sets new element into the HugeInteger
            newHugeInt.setElement( i, newElement );

      }


return newHugeInt;
}

std::ostream& operator<<( ostream &output, HugeInteger &operand2 )
{
      output << operand2.printHelper();

      return output;
}

std::istream& operator>>( istream &input, HugeInteger &operand2 );
{

}

string HugeInteger::printHelper()
{
      string output(" ");
      bool flag = false;

      for ( int i = 0; i < SIZE; i++ )
      {
            // check for null
            if ( ( bigInteger[ i ] == 0 ) && ( !flag ) )
            {
            }
            else
            {
                  flag = true;
                  char ch1[2];
                  ch1[0] = bigInteger[ i ] + '0';
                  ch1[1] = '\0';
                  string appendString(ch1);
                  output.append(appendString);
            }
      }
-------------------------
#ifndef HUGEINTEGER_H
#define HUGEINTEGER_H

#include <iostream>
#include <string>

class HugeInteger
{

public:
      
      HugeInteger( int startValue );
      HugeInteger( HugeInteger &operand2 );      
      HugeInteger addition( HugeInteger &operand2 );
      void setElement( const int index, const int newElement );
      int getElement( int index );      
      std::string printHelper();
      void operator++();       
      friend std::ostream &operator<<( std::ostream &output, HugeInteger &operand2 );
      friend std::istream &operator>>( std::istream &input, HugeInteger &operand2 );
      
      //static const int SIZE= 40;
      enum { SIZE = 40 };

private:
      int bigInteger[SIZE];


};
#endif
0
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 500 total points
ID: 20382982
>>>> using std::cout;
>>>> using std::endl;

Make

   using namespace std;

instead. With that you can omit std::  in the cpp.


>>>> std::istream& operator>>( istream &input, HugeInteger &operand2 );
>>>> {
>>>>
>>>> }

You have to remove the semicolon in the first line

You have to return at least the input you got.

istream& operator>>( istream &input, HugeInteger &operand2 )
{
      // todo make the streaming here

      return input;
}
 
0
 

Author Comment

by:urobins
ID: 20383013
Thanks, I'll give this a shot.
0
 

Author Comment

by:urobins
ID: 20383024
Thanks!  Got me compiling!  Now to actually make it work :)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
c++ syntax question 9 52
Windows Updates failing due to Diskpart not configured correctly 8 129
Raspberry Pi 3 to send text message 9 147
Visual Studio 2013 and Eclipse Neon 6 48
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question