Array Add Program

Hey everyone,
I'm completely new to C++ and my professor wants me to write a program where two strings are input by the user, both are converted to int arrays and then added together. She has written the header file and the main file and wants us to write the method file and implement it into her classes but when I compile I keep getting the error " Undefined Reference to 'LargeInteger::LargeInteger()' " I'm using code::blocks as my IDE. I know some of my algorithms are incorrect so I might need help fixing those too. I dont even know how to write the print method xD so please take a look and give me any input.

Thanks!


Heres the code my professor gave us:



Header:

#ifndef LargeInteger_h
#define LargeInteger_h

class LargeInteger
{
private:
int length, number[100];

public:
LargeInteger();
void insertDigit( int );
bool isEqual ( LargeInteger other );
LargeInteger add ( LargeInteger other );
void printNumber ();
};

#endif





MAIN:

#include "LargeInteger.h"
#include <iostream>
#include <string>
using namespace std;

int main()
{
LargeInteger x,y,z;
string num, num2;
int digit, i, s;


cout << "Enter the first whole number ";
getline(cin, num);

s = num.size();

for ( i = s-1; i >=0; i-- )
{
digit = num[i] - '0';
x.insertDigit ( digit );
}

cin.ignore();

cout << "Enter the second whole number ";
getline(cin, num2);

s = num2.size();

for ( i = s-1; i >=0; i-- )
{
digit = num2[i] - '0';
y.insertDigit ( digit );
}

z = x.add(y);

if (x.isEqual(y))
cout << "The two numbers are the same\n";
else cout<< "The two numbers are different\n";

cout<<"\n";
x.printNumber();
cout<<" + ";
y.printNumber();
cout<<" = ";
z.printNumber();
cout<<"\n";

cout << "\nThe sum of the two numbers is : ";
z.printNumber();

return 0;
}





And heres the code that I wrote:


Source:


#include "LargeInteger.h"
#include <iostream>
using namespace std;


LargeInteger::LargeInteger()
{
length=0
for(int i=0; i>=100; i++)
{
num[i]=0;
}
}



void LargeInteger::insertDigit(int num)
{
for(int i=length; i>=0; i--)
number[i]=digit;

}

bool LargeInteger::isEqual(LargeInteger other)
{
int s=num.size();
for(int i=0; i<=s; i++)
{
if (number[i]==other[i]
return true;
else return false;
}
}

LargeInteger::LargeInteger add(LargeInteger other)
{
int i, counter, p, remainder;
i=length;
counter=0;

for(counter; counter<=i; counter++)
{
p=number[counter]+other[counter]

if (p>9)
{
p++;
remainder=p-10;
}
// else
// {
// p+number[counter++];
// p+
// }



remainder+number[counter++];
// remainder+other[counter++];
}

return z;


}



void LargeInteger::printNumber()
{
int i, q;
q=z.size();

for(i=q-1; i>=0; i--)
{


}
}
Did you link all of the files in the project correctly? With C::B you'll need to click Project > Properties > Build Targets and make sure everything you need is in the "Build target files" section at the bottom of the "Build Targets" tab. Also make sure everything is checked.
Last edited on
Hahaha wow thanks so much. So that got rid of that error! Now I have other things to fix. Hopefully I can work most of them out if not, I may ask you computergeek =D Thanks again!
Topic archived. No new replies allowed.