figured out the bigNumber error, but now instead of that error my fourth error is this:
1>d:\homework\visual studio 2005\projects\olhugeintege
Main Topics
Browse All TopicsI 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
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
{
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
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
figured out the bigNumber error, but now instead of that error my fourth error is this:
1>d:\homework\visual studio 2005\projects\olhugeintege
ok now I did input, and I get two errors. Here is my input>>
istream &operator>>(istream &input, OLHugeInteger &bigNumber)
{
//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)
bigNumber.isNegative = true;
}
//set negative to zero
if (bigNumber.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
input >> bigNumber[(bigNumber.array
return input;
}//end input function
Here are my errors:
1>d:\homework\visual studio 2005\projects\olhugeintege
1> d:\homework\visual studio 2005\projects\olhugeintege
1>d:\homework\visual studio 2005\projects\olhugeintege
The first error is the line which just has:
return;
You need to return an istream. For instance:
return input;
The next error is on the line:
input >> bigNumber[(bigNumber.array
First of all, you need something more like:
input >> bigNumber.bigNumber[(bigNu
(notice the bigNumber.bigNumber).
This still won't compile though. I think it would help you to break this line into smaller chunks to help you understand what the code is doing. For instance is this what you meant to do?
int i;
input >> i;
bigNumber.bigNumber[(bigNu
I see what you mean aobut the int, i did int digit = bigNumber.bigNumber blah blah blah, but as for the first error, the return originally was in place for the error, and if I do return input, the program just keeps doing blank lines after I input an integer, for example 12, then hit enter it just goes to the next line with no print out. I don't know if it helps but here is the part of main that pertains to it.
//input huge integer one
OLHugeInteger one;
cin >> one;
//input huge integer two
OLHugeInteger two;
cin >> two;
as you can see it should repeat meaning ask for an integer twice, but without return input I get the above error and with return input it goes to the next line and it is blank rather then asking for another integer. Hope this makes sense.
I'm not sure what the goal of that function is. Do you want each integer placed in the bigNumber array?
So if the user enters "1234", do you want the bigNumber array to look like:
bigNumber[0] = 1;
bigNumber[0] = 3;
bigNumber[0] = 3;
bigNumber[0] = 4;
?
Also, you definitely want to change:
cin.getline(line, sizeof line);
cin.sync();
cin.clear();
to
input.getline(line, sizeof line);
input.sync();
input.clear();
ok here is input from top to bottom. as I said this program was completed already however, we now have to take our completed HugeInteger and overload everything. Final assignment.
ask user for input
get line
determine size
if size is greater then 0 check for negative
if negative set bool isNegative to true
if bigNumber is negative
set line[0] to '0'
check all digits are integers now
if they are not
set all digits to 0 and tell user
add digits to array (so 1234 would be)
bigNumber[36]=1
bigNumber[37]=2
bigNumber[38]=3
bigNumber[39]=4
I need the program to tell user they did not enter all integers for example they want to type 1234 but type 12e4 or 1w34 then it is set to all zeros
so there is no confusion this is my input>>
istream &operator>>(istream &input, OLHugeInteger &bigNumber)
{
//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;
input.getline(line, sizeof line);
input.sync();
input.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)
bigNumber.isNegative = true;
}
//set negative to zero
if (bigNumber.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;
for (int digitIndex = 0; digitIndex < bigNumber.arraySize; digitIndex++)
bigNumber.bigNumber[digitI
return input;
}
//add digits to array bigNumber
for (int loopSize = 0; loopSize < inputSize; loopSize++)
{
int digit = bigNumber.bigNumber[(bigNu
//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.bigNumber[(bigNu
input >> digit;
}
return input;
}//end input function
wow, lots of errors here, first, does this look right from .h in public part:
OLHugeInteger operator+(const OLHugeInteger &) const;
second, here is add, I haven't changed anything yet:
OLHugeInteger operator+(const OLHugeInteger &bigNumber2) const
{
OLHugeInteger result;
//if both bigNumbers are positive or both are negative, add together
if (this.isNegative == bigNumber2.isNegative)
{
int carry = 0; //holds carry over
//add all digits in array
for (int loopSize = arraySize - 1; loopSize >= 0; loopSize--)
{
int temp = bigNumber[loopSize];
result.bigNumber[loopSize]
carry = (temp + bigNumber2.bigNumber[loopS
}//end for
result.isNegative = isNegative;
return result;
}//end if
//else subtract because neg + pos and pos + neg needs to be subtracted
else
return subtract(opposite(bigNumbe
}//end add function
Nevermind, got it, moving on!
Is it better to do the equalities in .h or do them in .cpp? I could do this:
bool operator==(const HugeInteger &) const; //test bn1 == bn2
bool operator>(const HugeInteger &) const; //test bn1 > bn2
//test bn1 != bn2
bool operator!=(const HugeInteger &bigNumber2) const
{
return !(*this == bigNumber2);
}
//test bn1 >= bn2
bool operator>=(const HugeInteger &bigNumber2) const
{
return !(bigNumber2 > *this);
}
//test bn1 < bn2
bool operator<(const HugeInteger &bigNumber2) const
{
return bigNumber2 > *this;
}
//test bn1 <= bn2
bool operator<=(const HugeInteger &bigNumber2) const
{
return !(*this > bigNumber2);
}
or should I do them insde the .cpp file that I have already?
bool OLHugeInteger::equalTo(con
{
//if one is positive and one is negative
if (isNegative != bigNumber2.isNegative)
return false;
for (int digitIndex = 0; digitIndex < arraySize; digitIndex++)
//if any integers from first array does not equal integers
//from second array, return false
if(bigNumber[digitIndex] != bigNumber2.bigNumber[digit
return false;
return true;
}//end equalTo predicate function
bool OLHugeInteger::notEqualTo(
{
//if all first array integers are not equal to second array integers
//return true
if(!equalTo(bigNumber2))
return true;
return false;
}//end notEqualTo predicate function
bool OLHugeInteger::greaterThan
{
//if equal return false
if (equalTo(bigNumber2))
return false;
else
{
//If the two numbers are of the same sign
if (isNegative == bigNumber2.isNegative)
{
//If both are positve
if (!isNegative)
{
//the first 1st array int > 2nd array int return true
//logic( 200 is greater than 100 {bigger = greater})
for (int digitIndex = 0; digitIndex < arraySize; digitIndex++)
{
if (bigNumber[digitIndex] == bigNumber2.bigNumber[digit
continue;
if (bigNumber[digitIndex] <= bigNumber2.bigNumber[digit
return false;
else
return true;
}
}
//else both are negative
else
{
// When both are negative, use the both-are-positive logic to
//get the job done flipflop with opposite and check again
if (isNegative && bigNumber2.isNegative)
{
OLHugeInteger positveThis = opposite(*this); // Positive copy of this number
OLHugeInteger positveThat = opposite(bigNumber2); // Positive copy of bigNumber2
if (positveThis.greaterThan(p
return false;
else
return true;
}
}
}
//else the two numbers are of differing signs
else
{
//if (-)*this and (+)bigNumber2
if (isNegative && !(bigNumber2.isNegative))
return false;
//else (+)*this and (-)bigNumber2
else
return true;
}
return true;
}
}//end greaterThan predicate function
bool OLHugeInteger::greaterThan
{
//if equal to or greater than return true
if (equalTo(bigNumber2) || greaterThan(bigNumber2))
return true;
return false;
}//end greaterThanOrEqualTo predicate function
bool OLHugeInteger::lessThan(co
{
//if not equal to and not greater than return true
if (!equalTo(bigNumber2) && !greaterThan(bigNumber2))
return true;
else
return false;
}// end lessThan function
bool OLHugeInteger::lessThanOrE
{
//if equal to or less than return true
if (equalTo(bigNumber2) || lessThan(bigNumber2))
return true;
return false;
}//end lessThanOrEqualTo predicate function
Business Accounts
Answer for Membership
by: rebelcowgirl_73Posted on 2008-04-29 at 18:00:27ID: 21467425
The errors would probably help!
r\olhugein teger\olhu geinteger. cpp(89) : error C2065: 'isNegative' : undeclared identifier r\olhugein teger\olhu geinteger. cpp(93) : error C3861: 'isZero': identifier not found r\olhugein teger\olhu geinteger. cpp(99) : error C2065: 'arraySize' : undeclared identifier r\olhugein teger\olhu geinteger. cpp(101) : error C2065: 'bigNumber' : undeclared identifier
Here they are!
1>d:\homework\visual studio 2005\projects\olhugeintege
1>d:\homework\visual studio 2005\projects\olhugeintege
1>d:\homework\visual studio 2005\projects\olhugeintege
1>d:\homework\visual studio 2005\projects\olhugeintege