#include #include #include using namespace std; const int sun {1 << 0}; //00000000000000000000000000000001 const int mon {1 << 1}; //00000000000000000000000000000010 const int tue {1 << 2}; //00000000000000000000000000000100 const int wed {1 << 3}; //00000000000000000000000000001000 const int thu {1 << 4}; //00000000000000000000000000010000 const int fri {1 << 5}; //00000000000000000000000000100000 const int sat {1 << 6}; //00000000000000000000000001000000 struct dining_option { string name; int days; //what day(s) of the week this restaurant is open }; void f(const dining_option *p, int current_day); int main() { //00000000000000000000000001011110 The vertical bar is "bitwise or". const dining_option Argo {"Argo Tea", mon | tue | wed | thu | sat}; //00000000000000000000000001111111 const dining_option Community {"Community Dining Hall", mon | tue | wed | thu | fri | sat | sun}; //00000000000000000000000001011110 const dining_option RamCaf {"Ram Caf", mon | tue | wed | thu | sat}; //Ask the operating system for the current day of the week. const time_t t {time(nullptr)}; const tm *const localTime {localtime(&t)}; const int current_day {localTime->tm_wday}; //day of week (0-6) //Pass the addresses of the structures to the function f(&Argo, current_day); f(&Community, current_day); f(&RamCaf, current_day); return EXIT_SUCCESS; } //Check if the bit for current_day is turned on in p->days. void f(const dining_option *p, int current_day) { cout << p->name << " is "; if (p->days >> current_day & 1) { cout << "open"; } else { cout << "closed"; } cout << " today.\n"; }