#include #include #include //for setw() #include //for class string using namespace std; int main() { const char sun {1 << 0}; //00000001 const char mon {1 << 1}; //00000010 const char tue {1 << 2}; //00000100 const char wed {1 << 3}; //00001000 const char thu {1 << 4}; //00010000 const char fri {1 << 5}; //00100000 const char sat {1 << 6}; //01000000 const char shutdown {0x00}; struct restaurant { string name; char days; //which days of the week the restaurant is open }; const restaurant a[] { {"Katz's Delicatessen", sun | mon | tue}, //00000111 0x07 {"Tavern on the Green", sat | sun}, //01000001 0x41 {"Wo Hop", sun | mon | tue | wed | thu | fri | sat}, //01111111 0x7F {"Luchow's", mon | tue | wed}, //00001110 0x0E {"Delmonico's", thu | fri | sun}, //00110001 0x31 {"Fake Restaurant", shutdown} //00000000 }; const size_t n {size(a)}; //how many restaurants for (int i {0}; i < n; ++i) { int count {0}; for (int k {0}; k < 7; ++k) { //Loop through the 7 low bits of a[i].days if ((a[i].days >> k) & 0x1) { //if bit number k is not 0 ++count; } } cout << a[i].name << setw(23-a[i].name.length()) << count << "\n"; } return EXIT_SUCCESS; }