#include "pch.h" #include #include #include using namespace std; int printBitmask(bool *bitm, unsigned sz) { for (size_t i = 0; i < sz; i++) { cout << bitm[i]; } cout << endl; return 0; } int convertDecToBin(int n, bool * bin, unsigned sz) { for (int i = sz - 1, j = 0; i >= 0;i--, j++) { bin[j] = (n >> i) & 1; } printBitmask(bin, sz); return 0; } int printSubSet(char * set, unsigned sz, bool * bitm) { cout << "{"; bool f = false; for (size_t i = 0; i < sz; i++) { if (bitm[i]) { cout << (f ? "," : "") << set[i]; f = true; } } cout << "}" << endl; return 0; } int fillSet(char * set, unsigned sz) { for (size_t i = 0; i < sz; i++) { cin >> set[i]; } return 0; } int main() { unsigned n; cout << "Please enter power if set:"; cin >> n; char *set = new char[n]; cout << "Please enter set elements:"; fillSet(set, n); bool * bitm = new bool[n]; for (int i = 0;i < pow(2, n);i++) { convertDecToBin(i, bitm, n); printSubSet(set, n, bitm); } if (bitm != nullptr) { delete[] bitm; bitm = nullptr; } if (set != nullptr) { delete[] set; set = nullptr; } return 0; }