1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
#include <iostream>
#include <string>
#include <stack>
#include <cstdlib>
#include "VVLIver1.h"
using namespace std;
void VVLI::equalizeLength(string& num1 , string& num2, char pad = '0')
{
if(num1.size() < num2.size()){
unsigned int diff = num2.size() - num1.size();
string temp;
while(diff--) //add starting zeros
temp += pad;
temp += num1;
num1 = temp;
}
else if(num2.size() < num1.size()){
unsigned int diff = num1.size() - num2.size();
string temp;
while(diff--) //add starting zeros
temp += pad;
temp += num2;
num2 = temp;
}
}
VVLI VVLI::operator +(VVLI& INT)
{
equalizeLength(num,INT.num);
short numb1 = (num[0] - '0'), numb2 = (INT.num[0] - '0');
string num1 = addLargeNumbers(num,INT.num);
string num2 = subtractLargeNumbers(num,INT.num);
if( negfuncnum1 == true && negfuncnum2 == true)
{
//cout << "-" << addLargeNumbers(num1, num2) << endl;
num1.insert(0, "-"); VVLI a(num1); return a;
}
if( numb1 >= numb2 && negfuncnum1 != true && negfuncnum2 == true)
{
//cout << subtractLargeNumbers(num1, num2) << endl;
VVLI b(num2); return b;
}
if( numb1 >= numb2 && negfuncnum1 == true && negfuncnum2 != true)
{
//cout << "-" << subtractLargeNumbers(num1, num2) << endl;
num2.insert(0, "-"); VVLI b(num2); return b;
}
if( negfuncnum1 != true && negfuncnum2 != true)
{
//cout << addLargeNumbers(num1, num2) << endl;
VVLI a(num1); return a;
}
if( numb1 <= numb2 && negfuncnum1 != true && negfuncnum2 == true)
{
//cout << "-" << subtractLargeNumbers(num1, num2) << endl;
num2.insert(0, "-"); VVLI b(num2); return b;
}
if( numb1 <= numb2 && negfuncnum1 == true && negfuncnum2 != true)
{
//cout << subtractLargeNumbers(num1, num2) << endl;
VVLI b(num2); return b;
}
}
|