Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- class Bool {
- private:
- int bit;
- bool *q;
- public:
- Bool() {
- bit = 1;
- q = new bool[bit * 8];
- for (int i = 0; i < bit * 8; i++)
- q[i] = 0;
- }
- Bool(int _bit) {
- bit = _bit;
- q = new bool[bit * 8];
- for (int i = 0; i < bit * 8; i++)
- q[i] = 0;
- }
- void up_bit() {
- bool* tmp_q = new bool[(bit + 1) * 8];
- for (int i = 0; i < (bit + 1) * 8; i++) {
- if (i < bit * 8)
- tmp_q[i] = 0;
- else
- tmp_q[i] = q[i - bit * 8];
- }
- bit++;
- delete[] q;
- q = tmp_q;
- }
- void input() {
- string buffer;
- getline(cin, buffer);
- int j = 0;
- bool f;
- for (int i = 0; i < buffer.size(); i++) {
- if (buffer[buffer.size() - 1 - i] < 48 || buffer[buffer.size() - 1 - i] > 57) {
- j++;
- continue;
- }
- else {
- f = 0;
- while (i < buffer.size() && buffer[buffer.size() - 1 - i] != ' ') {
- if (buffer[buffer.size() - 1 - i] - '0' != 0)
- f = 1;
- i++;
- j++;
- }
- }
- if (!f)
- q[bit * 8 - 1 - i + j] = 0;
- else
- q[bit * 8 - 1 - i + j] = 1;
- }
- }
- Bool &operator = (const Bool& b) {
- bit = b.bit;
- q = new bool[bit * 8];
- for (int i = 0; i < bit * 8; i++)
- q[i] = b.q[i];
- return *this;
- }
- Bool operator * (Bool &b) {
- if (bit < b.bit)
- up_bit();
- else if (bit > b.bit)
- b.up_bit();
- Bool c(bit);
- for (int i = 0; i < bit * 8; i++) {
- if (b.q[i] == 1 && q[i] == 1)
- c.q[i] = 1;
- else
- c.q[i] = 0;
- }
- return c;
- }
- Bool operator + (Bool& b) {
- if (bit < b.bit)
- up_bit();
- else if (bit > b.bit)
- b.up_bit();
- Bool c(bit);
- for (int i = 0; i < bit * 8; i++) {
- if (b.q[i] == 1 || q[i] == 1)
- c.q[i] = 1;
- else
- c.q[i] = 0;
- }
- return c;
- }
- Bool operator ^ (Bool& b) {
- if (bit < b.bit)
- up_bit();
- else if (bit > b.bit)
- b.up_bit();
- Bool c(bit);
- for (int i = 0; i < bit * 8; i++) {
- if (b.q[i] ^ q[i])
- c.q[i] = 1;
- else
- c.q[i] = 0;
- }
- return c;
- }
- friend Bool operator == (Bool &a, Bool &b);
- friend Bool operator != (Bool &a, Bool &b);
- void print() {
- for (int i = 0; i < bit * 8; i++)
- cout << q[i] << ' ';
- cout << endl;
- }
- };
- Bool operator == (Bool& a, Bool& b) {
- if (a.bit < b.bit)
- a.up_bit();
- else if (a.bit > b.bit)
- b.up_bit();
- for (int i = 0; i < a.bit * 8; i++) {
- if (b.q[i] != a.q[i])
- return 0;
- }
- return 1;
- }
- Bool operator != (Bool& a, Bool& b) {
- }
- int main() {
- Bool a, b, c;
- a.input();
- a.print();
- b.input();
- b.print();
- c = a + b;
- c.print();
- c = a * b;
- c.print();
- c = a ^ b;
- c.print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement