#include #include #include //for class string #include 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 struct restaurant { string name; char days; //which days of the week the restaurant is open }; const restaurant a[] { {"Mcdonald's", sun | mon | tue}, //00000111 0x07 {"Wendy's", sat | sun}, //01000001 0x41 {"Chipotle", sun | mon | tue | wed | thu | fri | sat}, //01111111 0x7F {"Taco Bell", mon | tue | wed}, //00001110 0x0E {"Panda Express", thu | fri | sun}, //00110001 0x31 {"Chik-Fil-A",} }; const size_t n {size(a)}; cout << "How many days each restaurant is open:\n\n"; for (int i {0}; i < n; ++i) { int count {0}; //Count how many of the bits are turned on. for (int b {0}; b < 7; ++b) { if ((a[i].days >> b) & 0x1) { //if bit number b is a 1 ++count; } } cout << left << setw(13) << a[i].name << " " << count << "\n"; } return EXIT_SUCCESS; }