#include "iostream" using namespace std; #include "string" #include "vector" class Mint{ public: Mint(); Mint(int); Mint(const char*); Mint operator+=(const Mint &rhs); bool operator<(const Mint&); bool operator>(const Mint&); void display(); private: unsigned char* num; int size; };
#include "Mint.h" Mint::Mint() { num = new unsigned char[size= 1]; num[0] = 0; } Mint::Mint(const char* s) { num = new unsigned char[size= strlen(s)/2 + strlen(s)%2]; if(strlen(s)%2 == 1) num[0] = s[0]-'0'; unsigned int i; int j=strlen(s)%2; for(i=strlen(s)%2;i<strlen(s);i+=2) { int left = s[i] - '0'; int right = s[i+1] - '0'; num[j] = left << 4 ; num[j] |= right; j++; } } Mint Mint::operator+=(const Mint &rhs){ int i,carry=0,sum; for(i=this->size-1;i>=0;i--) { sum = ((num[i] ^ rhs.num[i]) ^ carry); carry = ((num[i] & rhs.num[i]) | (num[i] & carry)) | (rhs.num[i] & carry); num[i] = sum; } return *this; } bool Mint::operator<(const Mint& rhs) { unsigned int i; if (size < rhs.size) return true; if (size == rhs.size) for(i=0;i<size;i++) { if(num[i] < rhs.num[i]) return true; } return false; } bool Mint::operator>(const Mint& rhs) { if (*this < rhs) return false; return true; } void Mint::display() { int i; for (i=0;i<size ;i++) { int first_digit = (num[i] & '\xF0')>>4; int second_digit = (num[i] & '\x0F'); if (i || first_digit) cout << first_digit; if (i || second_digit) cout << second_digit; } }
Member 12223678 wrote: i didn't implement + either if i did i would have used it in += that is my problem i don't know how to implement + nor += please if you know how to implement it help me because i'm stuck
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)