そのため、大きな整数を処理するために BigNum クラスを実装しており、現在、文字列コンストラクタ クラスを修正しようとしています。「-345231563567」などの文字列を配列で読み取れるようにする必要があり、数値は逆方向に読み取られます (つまり、765365132543)。添付されたコードの最初の部分では、最初の文字が正か負かを確認し、正または負を true または false に設定します。コードの次の部分では、発生する可能性のある数値の先行ゼロと、数値自体がゼロであるかどうかをチェックします。最後の部分は、数値を配列にロードしているものであり、何らかの理由でコードを機能させることができません。解決策の助けをいただければ幸いです。
BigNum::BigNum(const char strin[])
{
size_t size = strlen(strin);
positive = true;
used=0;
if(strin[0] == '+')
{
positive = true;
used++;
}
else if(strin[0] == '-')
{
positive = false;
used++;
}
else
{
positive = true;
}
// While loop that trims off the leading zeros
while (used < size)
{
if (strin[used] != '0')
{
break;
}
used++;
}
// For the case of the number having all zeros
if(used == size)
{
positive = true;
digits = new size_t[1];
capacity = 1;
digits[0] = 0;
used = 1;
}
// Reads in the digits of the number in reverse order
else
{
int index = 0;
digits = new size_t[DEFAULT_CAPACITY];
capacity = size - used;
while(used < size)
{
digits[index] = strin[size - 1] - '0';
index++;
size--;
}
used = index + 1;
}
}
BigNum.h は http://csel.cs.colorado.edu/%7Eekwhite/CSCI2270Fall2011/hw2/revised/BigNum.hにあります。
使用しようとしているテストファイルはここにあります。テスト 7 に失敗し ましたhttp://csel.cs.colorado.edu/%7Eekwhite/CSCI2270Fall2011/hw2/revised/TestBigNum.cxx