mm.., hello. First, i'm kinda new to this... kinda, anyway, i'm supposed to write a prog that handles large numbers, like 200 digits long, by storing them in a string of characters. it's supposed to have a class with functions for all the mathematical operations, reading, and writing, maybe into a text file. i found a prog that does this, written by someone else, but now i want to rewrite it so i can understand how it works.
The code below is supposed to store and show a number like this on screen. It's made of pieces from the one i found. i managed to eliminate compile errors but it bogs down when i try to run it.
gives these errors:
try1.obj : error LNK2001: unresolved external symbol "public: __thiscall L_No::L_No(int)" (??0L_No@@QAE@H@Z)
Debug/try1.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
can anyone help make it work?... if i have this i think i can make the rest alone:-/
#include <string>
#include <vector>
#include <iostream>
using namespace std;
class L_No
{
public:
//Default Constructor
L_No() : Sign_of_no(1) { No.push_back(0); }
//Constructor From a Number
L_No(int iNumber);
//Constructor From a String
L_No(string const& rostrNumber);
protected:
//Build from unsigned long
static void Build(unsigned uN, vector<char>& rvN);
//Build from string
static void Build(string const& rostrNumber, vector<char>& rvN);
//Cleaning
static void Clean(vector<char>& rvN);
//Comparison Function
public:
//Transform to a string
string ToString() const;
private:
//-1 - Negative, +1 - Positive or zero
char Sign_of_no;
vector<char> No;
};
//Build from unsigned long
void L_No::Build(unsigned uN, vector<char>& rvn)
{
rvn.clear();
if(0 == uN)
rvn.push_back(0);
else
for( ;uN>0; )
{
rvn.push_back(uN % 10);
uN /= 10;
}
}
//Build from string
void L_No::Build(string const& rostrNumber, vector<char>& rvn)
{
rvn.clear();
for(int i=rostrNumber.size()-1; i>=0; i--)
{
if(rostrNumber[i]<'0' || rostrNumber[i]>'9')
break;
else
rvn.push_back(rostrNumber[i]-'0');
}
Clean(rvn);
}
//Cleaning
void L_No::Clean(vector<char>& rvn)
{
//Eliminate all leading 0s
vector<char>::iterator it = rvn.end();
while(it != rvn.begin())
{
it--;
if(*it != 0)
break;
}
rvn.erase(it+1, rvn.end());
}
L_No::L_No(string const& rostrNumber)
{
//Eliminating leading and trailing blanks
int iEnd;
iEnd = rostrNumber.size()-1;
for(; (rostrNumber[iEnd]==' ')&&(iEnd>=0); iEnd--)
;
if(iEnd < 0)
{
Sign_of_no = 1;
Build(0, No);
return;
}
int iBeg;
for(iBeg=0; ' '==rostrNumber[iBeg]; iBeg++)
;
string ostrNumber = rostrNumber.substr(iBeg, iEnd-iBeg+1);
iBeg = 0;
if('-' == ostrNumber[0])
{
Sign_of_no = -1;
iBeg = 1;
}
else
Sign_of_no = 1;
Build(ostrNumber.c_str()+iBeg, No);
}
//Transform to a string
string L_No::ToString() const
{
if(0 == No.size())
return "0";
string ostr;
if(-1 == Sign_of_no)
ostr += '-';
vector<char>::const_reverse_iterator rIter = No.rbegin();
for(; rIter != No.rend(); rIter++)
ostr += *rIter+'0';
return ostr;
}
int main()
{
L_No oLN1 = L_No(1000000);
cout<<oLN1.ToString()<<endl;
return 1;
}