#include #include #include //for class string #include //for class system_clock #include //for the function localtime using namespace std; int main() { //A convenient name for each 1 bit. 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 }; //Use "bitwise or" to assemble the individual 1 bits into a byte. const restaurant a[] { {"Katz's Delicatessen", sun | mon | tue }, //00000111 0x07 {"Tavern on the Green", sun | sat}, //01000001 0x41 {"Wo Hop", sun | mon | tue | wed | thu | fri | sat}, //01111111 0x7F {"Luchow's", mon | tue | wed }, //00001110 0x0E {"Delmonico's", sun | thu | fri } //00110001 0x31 }; const size_t n {size(a)}; //how many restaurants const auto now {chrono::system_clock::now()}; const time_t t {chrono::system_clock::to_time_t(now)}; const tm *const p {localtime(&t)}; const int day {p->tm_wday}; //0 = Sunday, 1 = Monday, ... 6 = Saturday const string dayname[] { "Sunday", //0 "Monday", //1 "Tuesday", //2 "Wednesday", //3 "Thursday", //4 "Friday", //5 "Saturday" //6 }; cout << "Today is " << dayname[day] << ".\n"; cout << "The following restaurants are open today:\n"; for (int i {0}; i < n; ++i) { //If bit number day of the byte a[i].days is turned on, if ((a[i].days >> day) & 0x1) { cout << a[i].name << "\n"; } } return EXIT_SUCCESS; }