#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() { const dining_option a[] { {"Argo Tea", mon | tue | wed | thu | sat}, {"Community Dining Hall",mon | tue | wed | thu | fri | sat|sun}, {"Ram Caf", mon | tue | wed | thu | sat} }; const size_t n {size(a)}; //the number of elements in the array //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 address of each structure to the function f. for (int i {0}; i < n; ++i) { f(a+i, current_day); //a+i means &a[i] } 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"; }