Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- class BIGINT
- {
- public:
- friend istream& operator >> (istream& in, BIGINT &BI);
- friend ostream& operator << (ostream& out, BIGINT BI);
- BIGINT operator +(BIGINT BI);
- BIGINT operator -(BIGINT BI);
- BIGINT operator *(BIGINT BI);
- BIGINT operator /(BIGINT BI);
- private:
- string bigint;
- };
- istream& operator >> (istream& in, BIGINT &BI)
- {
- cout << "Nhap so nguyen bat ky: ";
- in >> BI.bigint;
- return in;
- }
- ostream& operator << (ostream& out, BIGINT BI)
- {
- out << "So BIGINT: ";
- out << BI.bigint;
- return out;
- }
- BIGINT BIGINT::operator +(BIGINT BI)
- {
- int r = 0;
- BIGINT KQ;
- KQ.bigint = "";
- string s = "0";
- std::string::iterator it1, it2;
- it1 = bigint.end() - 1;
- it2 = BI.bigint.end() - 1;
- while (bigint.size() > BI.bigint.size())
- {
- BI.bigint.insert(0, s);
- }
- while (bigint.size() < BI.bigint.size())
- {
- bigint.insert(0, s);
- }
- while (1)
- {
- s = *(it1) + *(it2) - 48 + r;
- r = (s[0] - 48) / 10;
- s = (s[0] - 48) % 10 + 48;
- KQ.bigint.insert(0, s);
- if (it1 == bigint.begin() || it2 == BI.bigint.begin()) break;
- it1--;
- it2--;
- }
- if (r == 1)
- {
- s = "1";
- KQ.bigint.insert(0, s);
- }
- return KQ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement