I am currently doing a school assignment (I am sorry that my question is about my assignment, but I am not asking about the algorithms used in the codes). I am now currently doing the arithmetic part, addition and subtract. Since there are only two operators, there are 8 combinations of operation. In my program, I can do these four cases:
(+a)+(+b)
(-a)+(-b)
(-a)-(+b)
(+a)-(-b)
However, I cannot figure out the way to do the other four cases, I.e.
(+a)+(-b)
(-a)+(+b)
(-a)-(-b)
(+a)-(+b)
I sincerely hope that you guys can provide suggestions and advice on how to deal with these four cases.
Here is my code:
linkedListType.h: It is a common linked list header file therefore I don't post the whole code here.
bigInteger.h: The functions in this are quite long. Therefore, I skipped posting them out.
#ifndef BIG_INTEGER_H
#define BIG_INTEGER_H
#include <stack>
#include <iostream>
#include "linkedListType.h"
using namespace std;
class bigInteger
{
private:
int sign; // set 0 for positive, 1 for negative
linkedListType<int> digits; // internal linked-list for storing digits in reverse order
public:
bigInteger(); // default constructor
bigInteger(const bigInteger& other); // copy constructor
// Overload constructor
// Use an numerical string to construct this bigInteger
// For negative number, the first char in the string is '-'
// e.g. "-12345"
bigInteger(const string& number);
// overload the assignment operator
const bigInteger& operator= (const bigInteger& other);
// Return a new bigInteger that is equal to *this + other
// The contents of this and other should not be modified
bigInteger& operator+ (bigInteger& other);
// Return a new bigInteger that is equal to *this - other
// The contents of this and other should not be modified
bigInteger& operator- (bigInteger& other);
// Print a big integer
// Since the digits are stored in reverse order in the internal
// list, you should print in reverse order
// Print "undefined" if the digits list is empty
friend ostream& operator<<(ostream& os, bigInteger& n);
};