Question: I need help with my C++ program. I want my main() program to be interactive with user to schedule and report on appointment. Appointments can
I need help with my C++ program. I want my main() program to be interactive with user to schedule and report on appointment. Appointments can start every hour or half-hour, and that makes 48 appointment objects to represent one day. (Your interactive program should be able to handle appointments that last 2 hours - by scheduling 4 appt objects, for example.)
Also implement enumeration for the days and types of appointments.Use inheritance and derive a class from appt that is used for business appointments, (adding fields for priority, deadline, location, cost, and a pay code)
/////////////////////////// main.cpp /////////////// #include "weekly.h" #include int main() { bool success; appt a1(1, 1000, "laundry", false); appt a2(1, 1300, "homework assignment", false); appt a3(2, 900, "mow lawn", false); appt a4(2, 1500, "clean room", false); appt a5(3, 1230, "lunch with friends", false); appt a6; appt *a7; appt a8(1, 1730, "dentist", false); weekly w; a6.set_day(3); a6.set_time(1800); a6.set_task("tennis lesson"); std::cout << "Testing the weekly class" << std::endl << std::endl; std::cout << "Several things will be scheduled, and then displayed." << std::endl << std::endl; success = w.schedule(a1); if (!success) { std::cout << "There was a problem scheduling that." << std::endl; } success = w.schedule(a2); if (!success) { std::cout << "There was a problem scheduling that." << std::endl; } success = w.schedule(a3); if (!success) { std::cout << "There was a problem scheduling that." << std::endl; } success = w.schedule(a4); if (!success) { std::cout << "There was a problem scheduling that." << std::endl; } success = w.schedule(a5); if (!success) { std::cout << "There was a problem scheduling that." << std::endl; } success = w.schedule(a6); if (!success) { std::cout << "There was a problem scheduling that." << std::endl; } a7 = w.lookup(1, 1000); std::cout << "The task for Monday at 10:00 is: " << a7->get_task() << std::endl; w.show_times(1, 1100, 1700); w.show_times(2, 800, 1800); w.show_times(3, 0, 2345); std::cout << "Removing a task from Wednesday and re-printing:" << std::endl; w.unschedule(a5); w.show_times(3, 0, 2345); std::cout << "Clearing the schedule and re-printing." << std::endl; w.clear(); w.show_times(3, 0, 2345); system("pause"); return 0; } /////////////////////////// appt.cpp /////////////// #include "appt.h" appt::appt(int d, int h, string i, bool done) { this->d = d; this->h = h; this->item = i; this->done = done; } appt::~appt() { } void appt::set_day(int d) { this->d = d; } void appt::set_time(int h) { this->h = h; } void appt::set_task(std::string item) { this->item = item; } void appt::set_is_done(bool done) { this->done = done; } int appt::get_day() { return d; } int appt::get_time() { return h; } std::string appt::get_task() { return (std::string) item; } bool appt::get_is_done() { return done; } void appt::clear() { this->d = 0; this->h = 0; this->item = "unset"; this->done = false; } void appt::show_appt() { std::string day[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; cout << "Day : " << day[d] << endl; cout << "Time : " << h << endl; cout << "Task : " << item << endl; cout << (!done ? "Not Finished" : "Finished") << endl; cout << endl; } /////////////////////////// appt.h /////////////// #ifndef APPT_H #define APPT_H #include using namespace std; // This is the appointment class // It should hold all information for the appointment class appt { private: int d, h; string item; bool done; public: appt(int d = 0, int h = 0000, std::string item = "unset", bool done = false); // default constructor ~appt(); // destructor // set the day of the appointment void set_day(int d); // set the time of the appointment void set_time(int h); // set the task of the appointment void set_task(std::string item); // set the status of the appointment void set_is_done(bool done); // return the day of the appointment int get_day(); // return the time of the appointment int get_time(); // return the task of the appointment std::string get_task(); // return the status of the appointment bool get_is_done(); // restores appointment information to default void clear(); // print all the appointment information void show_appt(); }; // end appt class #endif /////////////////////////// weekly.cpp /////////////// #include "weekly.h" // implementation of the weekly class weekly::weekly() { appointments = new appt*[5]; max = 5; size = 0; } weekly::~weekly() { delete appointments; } // takes an appointment object and puts it in the schedule, returning true on // success bool weekly::schedule(appt a) { if (size >= max) { appt **temp = new appt*[2*max]; max *= 2; for (int i = 0; iget_day() == day && appointments[i]->get_time() == hour) { return appointments[i]; } } return NULL; } // removes an appointment at the given day and time in appointment a // returns true on success bool weekly::unschedule(appt a) { appt *elem = lookup(a.get_day(), a.get_time()); if(elem != NULL) { int index = -1; for (int i = 0; iget_day(); int t = appointments[i]->get_time(); if((d == day) && (t >= start) && (t <= end)) { appointments[i]->show_appt(); } } } // clears the entire schedule, returning true on success bool weekly::clear() { for (int i = 0; i/////////////////////////// weekly.h/////////////// #ifndef WEEKLY_H #define WEEKLY_H #include "appt.h" #include // this is the weekly class // it should keep appointments for a week // it uses an array to keep track of every half-hour in each day // and of course keeps all of those in an array class weekly { private: appt** appointments; int max, size; public: weekly(); // default constructor ~weekly(); // destructor // takes an appointment object and puts it in the schedule, returning true on success bool schedule(appt a); // returns a pointer to an appointment object at the day and time appt* lookup(int day, int hour); // removes an appointment at the given day and time in appointment a bool unschedule(appt a); // shows all the appointments on the given day between the given times void show_times(int day, int start, int end); // clears the entire schedule bool clear(); };
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
