I am back LOL... I am trying to overload a previous version of HugeInteger. All methods worked and such before attempt to overload. I am gonna go threw this bit by bit. Since I was suppose to overload every single function in my already completed work, i figured I would start with one I thought I kind of understood. HA HA what a joke that was. Here is my attempt at overloading output << However I get four different errors. I have included the .h file and all methods up to the output << method hoping someone can tell me why I am getting these errors.
.h file
class OLHugeInteger
{
friend ostream &operator<<(ostream &, const OLHugeInteger &);
public:
OLHugeInteger(); //constructor
void input();
void copyBigNumber(int [], const int []) const ;
OLHugeInteger add(const OLHugeInteger &) const;
OLHugeInteger subtract(const OLHugeInteger &) const;
OLHugeInteger multiply(const OLHugeInteger &) const;
OLHugeInteger multiplySub(int) const;
OLHugeInteger opposite(const OLHugeInteger &) const;
bool equalTo(const OLHugeInteger &) const;
bool notEqualTo(const OLHugeInteger &) const;
bool greaterThan(const OLHugeInteger &) const;
bool greaterThanOrEqualTo(const
OLHugeInteger &) const;
bool lessThan(const OLHugeInteger &) const;
bool lessThanOrEqualTo(const OLHugeInteger &) const;
bool isZero() const;
private:
int const arraySize; //const array size
bool isNegative; //determines if array of integers is negative
char line[41];
int bigNumber[40]; //array to hone users inputted integer
void copyBigNumber(int [], const int []); //creates copy of bigNumber[]
}; //End class OLHugeInteger
#endif
.cpp up to output<<
#include <iostream>
using namespace std;
using std::cout;
using std::cin;
using std::endl;
#include <string> //for string length (strlen)
#include "OLHugeInteger.h" //include definition of class HugeInteger
int inputSize = 0; //default size of users integer
//default constructor const arraySize = 40
OLHugeInteger::OLHugeInteg
er() :arraySize(40)
{
for (int loopSize = 0; loopSize < arraySize; loopSize++)
//initialize array with 0's
bigNumber[loopSize] = 0;
//set bool isNegative to false
isNegative = false;
}//end constructor
void OLHugeInteger::input()
{
//characters read in to hold integer values
char line[41];
//ask for usre input and make sure no more than 40 digits where entered
//if more than 40 digits are entered, drop extra from bigNumber
cout << "Enter Huge Integer (Max: 40 digits, extra digits will be dropped!): " << endl;
cin.getline(line, sizeof line);
cin.sync();
cin.clear();
//determine size of users integer
inputSize = strlen(line);
//check for negative integer value and set bool
if (inputSize > 0)
{
int negative = '-';
if (line[0] == negative)
isNegative = true;
}
//set negative to zero
if (isNegative)
line[0] = '0';
//check that all digits entered where integer values
for (int loopSize = 0; loopSize < inputSize; loopSize++)
if (!isdigit(line[(inputSize - 1) - loopSize]))
{
cout << "Not all digits entered where integers. Array initialized to zero" << endl;
return;
}
//add digits to array bigNumber
for (int loopSize = 0; loopSize < inputSize; loopSize++)
//subtract ASCII value for '0' to get raw value store digits at
//end of 40 digit array all non initialized parts of array stay a 0
bigNumber[(arraySize - 1) - loopSize] = line[(inputSize - 1) - loopSize] - '0';
}//end input function
ostream &operator<<(ostream &output, const OLHugeInteger &bigNumber2)
{
// Display negative sign if isNegative is set.
if (isNegative)
output << '-';
//if array isZero then print a single zero
if(isZero())
output << '0';
bool leadingZero = true;
//avoid printing all leading zero'
for (int digitIndex = 0; digitIndex < arraySize; digitIndex++)
{
int digit = bigNumber[digitIndex];
//if it is not a zero, print it, and set leadingZero to false;
if (digit != 0)
{
leadingZero = false;
output << digit;
}//end if
else
//else if digit is zero, print only if not leading
if (!leadingZero)
output << digit;
}//end for
return output;
}//end output function