Skip to content

Commit

Permalink
fix:注释
Browse files Browse the repository at this point in the history
  • Loading branch information
JalorOo committed Nov 16, 2020
1 parent 4d4e242 commit cc5e4ad
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 40 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
filePath = "ADT/BIGNUM.cpp"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "71"
endingLineNumber = "71"
startingLineNumber = "70"
endingLineNumber = "70"
landmarkName = "BigNum::operator +(another)"
landmarkType = "7">
</BreakpointContent>
Expand All @@ -78,8 +78,8 @@
filePath = "ADT/BIGNUM.cpp"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "82"
endingLineNumber = "82"
startingLineNumber = "84"
endingLineNumber = "84"
landmarkName = "BigNum::operator +(another)"
landmarkType = "7">
</BreakpointContent>
Expand All @@ -94,8 +94,8 @@
filePath = "ADT/BIGNUM.cpp"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "112"
endingLineNumber = "112"
startingLineNumber = "114"
endingLineNumber = "114"
landmarkName = "BigNum::operator -(another)"
landmarkType = "7">
</BreakpointContent>
Expand All @@ -110,8 +110,8 @@
filePath = "ADT/BIGNUM.cpp"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "125"
endingLineNumber = "125"
startingLineNumber = "127"
endingLineNumber = "127"
landmarkName = "BigNum::operator -(another)"
landmarkType = "7">
</BreakpointContent>
Expand All @@ -126,8 +126,8 @@
filePath = "ADT/BIGNUM.cpp"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "113"
endingLineNumber = "113"
startingLineNumber = "115"
endingLineNumber = "115"
landmarkName = "BigNum::operator -(another)"
landmarkType = "7">
</BreakpointContent>
Expand All @@ -142,8 +142,8 @@
filePath = "ADT/BIGNUM.cpp"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "108"
endingLineNumber = "108"
startingLineNumber = "110"
endingLineNumber = "110"
landmarkName = "BigNum::operator -(another)"
landmarkType = "7">
</BreakpointContent>
Expand All @@ -158,8 +158,8 @@
filePath = "ADT/BIGNUM.cpp"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "106"
endingLineNumber = "106"
startingLineNumber = "108"
endingLineNumber = "108"
landmarkName = "BigNum::operator -(another)"
landmarkType = "7">
</BreakpointContent>
Expand All @@ -174,8 +174,8 @@
filePath = "ADT/BIGNUM.cpp"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "119"
endingLineNumber = "119"
startingLineNumber = "121"
endingLineNumber = "121"
landmarkName = "BigNum::operator -(another)"
landmarkType = "7">
</BreakpointContent>
Expand All @@ -190,8 +190,8 @@
filePath = "ADT/BIGNUM.cpp"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "66"
endingLineNumber = "66"
startingLineNumber = "65"
endingLineNumber = "65"
landmarkName = "BigNum::operator +(another)"
landmarkType = "7">
</BreakpointContent>
Expand Down Expand Up @@ -254,8 +254,8 @@
filePath = "ADT/BIGNUM.cpp"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "91"
endingLineNumber = "91"
startingLineNumber = "93"
endingLineNumber = "93"
landmarkName = "BigNum::operator -(another)"
landmarkType = "7">
</BreakpointContent>
Expand Down
38 changes: 21 additions & 17 deletions ADT/BIGNUM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,23 @@ BigNum BigNum::setBigNum(string s){
待实现:负+负、正+负
*/
BigNum BigNum::operator +(BigNum& another){
bool originFlag = true;
if((*this).flag == false && another.flag == false){//判断符号位,若是 (-x) + (-y) = - (y + x);
bool originFlag = true;//记录原来的符号位
if((*this).flag == false && another.flag == false){//若是 (-x) + (-y) 则转化为 - (y + x);
this->flag = true;
another.flag = true;
originFlag = false;

} else if((*this).flag == false) {//判断符号位,若是 (-x) + y = y - x;
originFlag = false;//原来的符号位为负
} else if((*this).flag == false) {//若是 (-x) + y 则转换为 y - x;
this->flag = true;
return another - (*this);

} else if(another.flag == false) {
} else if(another.flag == false) {//若是 x + (-y) 则转化为 x - y
another.flag = true;
return (*this) - another;
}

int maxBit = max(this->length, another.length);//获得最少的位数

/* 加法运算 */
for (int i = 0; i < maxBit; i++) {//位相加
int c = this->C ? 1 : 0;//判断是否有进位
int bitAns = this->bit[i] + another.bit[i] + c;
Expand All @@ -79,8 +80,9 @@ BigNum BigNum::operator +(BigNum& another){
}
this->bit[i] = bitAns%10;
}

this->length = maxBit;//设置长度
this->flag = originFlag;
this->flag = originFlag;//设置符号位
return (*this);
}

Expand All @@ -89,33 +91,33 @@ BigNum BigNum::operator +(BigNum& another){
*/
BigNum BigNum::operator -(BigNum& another){

if((*this).flag == false && another.flag == false){//判断符号位
if((*this).flag == false && another.flag == false){//当(-x) - (-y),则转化为 y - x;
another.flag = true;
(*this).flag = true;
return another - (*this);
}else if((*this).flag == true && another.flag == false) {
}else if((*this).flag == true && another.flag == false) {//当x - (-y), 则转化为x + y;
another.flag = true;
return (*this) + another;
}else if ((*this).flag == false && another.flag == true) {
}else if ((*this).flag == false && another.flag == true) {//当 (-x) - y, 则转化为 (-x) + (-y)
(another).flag = false;
return (*this) + another;
}


/*第一次获得位数*/
/* 获得大的数、小的数 */
BigNum& big = this->length < another.length ? another : (*this);//大位数
BigNum& small = this->length < another.length ? (*this) : another;//小位数

/*设置符号位*/
if(big.length > (*this).length){//若大数不是本数
/* 若小的数为自己这个数 */
if (big.length > (*this).length) {//若大数不是本数
big.flag = false;//设置符号位为负
}else if(small.length == (*this).length){
} else if(small.length == big.length) {//若位数相等,逐一比对每位
for (int i = big.length - 1;
(big.flag == true) && i >= 0;
i--) {//位相加
if(big.bit[i] >= small.bit[i]){
continue;
} else {
} else {//大数与小数交换
small.flag = false;
BigNum temp = big;
big = small;
Expand All @@ -126,7 +128,7 @@ BigNum BigNum::operator -(BigNum& another){

int maxBit = max(this->length, another.length);//获得最大的位数

for (int i = 0; i < big.length; i++) {//位相加
for (int i = 0; i < big.length; i++) {//位相减
int c = big.C ? 1 : 0;//判断是否有借位
int bitAns = big.bit[i] - small.bit[i] - c;
if(bitAns < 0){//设置进位位
Expand All @@ -141,12 +143,14 @@ BigNum BigNum::operator -(BigNum& another){
this->length = maxBit;//设置长度
return big;
}


//BigNum operator *(const BigNum&);
//BigNum operator /(const BigNum&);


/*
输出大整数
输出 大整数
*/
ostream& operator<<( ostream &output,const BigNum &num){
bool cantOutZero = true;
Expand Down
8 changes: 5 additions & 3 deletions ADT/BIGNUM.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,23 @@

#include <iostream>
using namespace std;
//大整数
class BigNum{
private:
int bit[100];//计算位
bool C = false;//进位标志位
int length = 0 ;//当前数字的位数
bool flag = true;//符号位
public:
/*定义加减乘除、输入输出*/
/* 定义加减乘除、输入输出 */
BigNum(string s);
BigNum setBigNum(string s);
BigNum();
BigNum operator +(BigNum&);
BigNum operator -(BigNum&);
BigNum operator *(const BigNum&);
BigNum operator /(const BigNum&);
// BigNum operator *(const BigNum&);
// BigNum operator /(const BigNum&);
/* 输入输出 */
friend ostream & operator <<(ostream &output,const BigNum &);
friend istream & operator >>( istream &input,BigNum &);
};
Expand Down

0 comments on commit cc5e4ad

Please sign in to comment.