// todo.cpp: todo list as a class #include #include using namespace std; class ToDo { public: ToDo() : count{0} { } ToDo(string first_item) : count{1} { items[0] = first_item; } bool empty() { return count <= 0; } bool full() { return count >= MAXITEMS; } void add(string next_item) { if ( full() ) throw "Adding item to full todo list."; items[count] = next_item; ++count; } string next_item() { if ( empty() ) throw "Removing item from empty todo list."; string result = items[0]; for(int i = 0; i < count - 1; ++i) items[i] = items[i + 1]; --count; return result; } private: static constexpr int MAXITEMS = 100; string items[MAXITEMS]; int count; }; int main() { ToDo today("Eat breakfast."); // can't start a day without eating! today.add("Go to class."); today.add("Eat lunch."); today.add("Show up for office hours."); today.add("Go home."); cout << "Today's list:" << endl; while ( !today.empty() ) cout << today.next_item() << endl; return 0; }