سلام.من اپراتور / رو پیاده سازی کردم.روش هم اینه که تا زمانی که عدد اول از عدد دوم بزرگتره ، دو عدد رو از هم کم کنه به شمارنده اضافه کنه.شمارنده ی من از نوع string هست.برنامه ی من خطای زمان اجرا میده و وقتی برنامه رو دیباگ میکنم داخل حلقه ی while که داره شمارنده رو اضافه میکنه برای بار دوم برنامه متوقف میشه.یعنی دقیقا خط
A=sub(A,B);
اینم کد من
string BigNumber::sub(string &x,string &y)
{
string min=x,max=y;
string z=" ";
if(compare(x,y)==1)
{
max=x;
min=y;
}
else if(compare(x,y)==-1)
{
min=x;
max=y;
}
else
{
z="0";
return z;
}
int i,temp=0;
int carry=0;
for(i=min.length()-1;i>=0;i--)
{
int different=max.length()-min.length();
temp=max[i+different]-min[i]+carry;
if(temp<0)
{
int j;
if(max[i+different-1]=='0')
{
for(j=i+different-1;max[j]=='0';j--)
{
max[j]='9';
}
max[j]-=1;
}
else
{
max[i+different-1]-=1;
}
carry=10;
i++;
continue;
}
else
carry=0;
if(i !=0 || temp !=0 ||max.length()!= min.length())
z.insert(z.begin(),temp + '0');
}
i = max.length() - min.length()-1;
while(i>=0)
{
if(i !=0 || max[i] != '0')
z.insert(z.begin(),max[i]+carry);
i--;
}
return z;
}
BigNumber BigNumber::operator /(const BigNumber &other)
{
string A,B;
string temp="1";
A=data;
B=other.data;
string count;
if((data[0]=='-')&&(other.data[0]=='-'))
{
A=A.erase(0,1);
B=B.erase(0,1);
if(compare(A,B)==-1)
{
count="0";
}
else if(compare(A,B)==1)
{
while((compare(A,B)==1)||(compare(A,B)==0))
{
A=sub(A,B);
count=add(count,temp);
}
}
else
{
count="1";
}
}
else if((data[0]=='-')&&(other.data[0]!='-'))
{
A=A.erase(0,1);
if(compare(A,B)==-1)
{
count="0";
}
else if(compare(A,B)==1)
{
while((compare(A,B)==1)||(compare(A,B)==0))
{
A=sub(A,B);
count=add(count,temp);
}
count.insert(count.begin(),'-');
}
else
{
count="-1";
}
}
else if((data[0]!='-')&&(other.data[0]=='-'))
{
B=B.erase(0,1);
if(compare(A,B)==-1)
{
count="0";
}
else if(compare(A,B)==1)
{
while((compare(A,B)==1)||(compare(A,B)==0))
{
A=sub(A,B);
count=add(count,temp);
}
count.insert(count.begin(),'-');
}
else
{
count="-1";
}
}
else
{
if(compare(A,B)==-1)
{
count="0";
}
else if(compare(A,B)==1)
{
while((compare(A,B)==1)||(compare(A,B)==0))
{
A=sub(A,B);
count=add(count,temp);
}
}
else
{
count="1";
}
}
BigNumber n(count);
return n;
}
int main()
{
string a="144";
string b="4";
BigNumber num1(a);
BigNumber num2(b);
num1/num2;
{
با تشکر