Advertisement
TwITe

Untitled

Aug 3rd, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <bitset>
  4. using namespace std;
  5.  
  6. bool && (bool cond1, bool cond2) {
  7.     if (!cond1) {
  8.         return false;
  9.     }
  10.     else {
  11.         return true;
  12.     }
  13. }
  14.  
  15. int & (bool cond1, bool cond2) { //тут пришлось сделать тип возвращаемой функции int, т.к. тип возвращаемого значения при перегрузке функций менять нельзя
  16.     if (!cond1) {
  17.         if (!cond2) {
  18.             return false;
  19.         }
  20.         else {
  21.             return false;
  22.         }
  23.     }
  24.     if (cond1) {
  25.         if (!cond2) {
  26.             return false;
  27.         }
  28.         else {
  29.             return true;
  30.         }
  31.     }
  32. }
  33.  
  34. int & (int num_one, int num_two) {
  35.     bitset <8> number_one(num_one);
  36.     //cout << number_one.to_ulong() << " = " << number_one << endl;
  37.     bitset <8> number_two(num_two);
  38.     //cout << number_two.to_ulong() << " = " << number_two << endl;
  39.     bitset <8> number;
  40.     for (int i = 7; i >= 0; i--) {
  41.         if (number_one[i] == 1) {
  42.             if (number_two[i] == 1) {
  43.                 number[i] = 1;
  44.             }
  45.             else {
  46.                 number[i] = 0;
  47.             }
  48.         }
  49.         else {
  50.             if (number_two[i] == 1) {
  51.                 number[i] = 0;
  52.             }
  53.             else {
  54.                 number[i] = 0;
  55.             }
  56.         }
  57.     }
  58.     //cout << endl;
  59.     //cout << number.to_ulong() << " = " << number;
  60.     return number.to_ulong();
  61.  
  62.     system("PAUSE");
  63.     return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement