+1 678 648 4277 

Scheduler Creation using C++ Assignment Solution


OOP Calendar Application Creation

Description

This assignment has you creating an OOP Calendar application allowing for the user to create appointments and reminders on a custom calendar.

Programming Assignment:

Instructions:

This assignment gives you a specification for several classes to create to make this Calendar application.

The classes are described in plain language. You are expected to code the classes using good OOP Principles

  • Use of data hiding
  • Appropriate isolation of knowledge/responsibility

o “A playing card doesn’t know it’s in a game of Black Jack”

  • Creating appropriate getters/setters
  • Creating private/protected helper methods if needed

You must create a .h file for your Calendar related classes and an accompanying

.cpp file for those classes’ method definitions

Use of #include and #include are approved for this assignment.

Create a simple numerical menu-driven system to use the calendar.

Sample Output:

Note: You’ll want to make this better, this is just a basic example to show expectations of use.

Welcome to CSE240 Calendar

  1. Build a new Calendar
  2. Exit

Building a new calendar. Give your calendar a title:

How many days should this calendar have? What day does your calendar start on?

  1. Monday
  2. Tuesday
  3. Wednesday
  4. Thursday
  5. Friday
  6. Saturday
  7. Sunday

Selection >>

Your Calendar has been created. What would you like to do?

  1. Display Whole Calendar
  2. Display a Single Day
  3. Add an Errand
  4. Delete an Errand
  5. Save to a file

0. Exit

(Using a Calendar in progress -- 10 days, started Monday, an appointment and reminder added)

Option 1 chosen

Calendar “Next few days”:

  1. – Monday: 2 Errands
  2. - Tuesday: No Errands
  3. – Wednesday: No Errands
  4. – Thursday: No Errands
  5. – Friday: No Errands
  6. – Saturday: No Errands
  7. – Sunday: No Errands
  8. – Monday: No Errands
  9. - Tuesday: No Errands
  10. – Wednesday: No Errands

Option 2

Select which day to display:

Day (1 – 10) (0 - Back to the main menu)

>>

  1. – Monday:

Reminder – Write an exam

Appointment – 12:00 – 13:00 – Faculty Meeting

Option 3 Chosen

Calendar:

  1. – Monday: 2 Errands
  2. - Tuesday: No Errands
  3. – Wednesday: No Errands
  4. – Thursday: No Errands
  5. – Friday: No Errands
  6. – Saturday: No Errands
  7. – Sunday: No Errands
  8. – Monday: No Errands
  9. - Tuesday: No Errands
  10. – Wednesday: No Errands

Add an Errand

Select which day you want to add an Errand to Day (1 – 10) >>

What type of Errand?

  1. Reminder
  2. Appointment

0. Back to the main menu

>>

For reminder:

Enter reminder text:

For appointment:

Enter start time hour (24-hour clock): Enter start time minutes:

Enter end time hours (24-hour clock): Enter end time minutes:

Enter reminder text:

Option 4 Chosen

Calendar:

  1. – Monday: 2 Errands
  2. - Tuesday: No Errands
  3. – Wednesday: No Errands
  4. – Thursday: No Errands
  5. – Friday: No Errands
  6. – Saturday: No Errands
  7. – Sunday: No Errands
  8. – Monday: No Errands
  9. - Tuesday: No Errands
  10. – Wednesday: No Errands

Remove an Errand

Select which day you want to remove an Errand from Day (1 – 10) (0 - Back to the main menu)

>>

You have chosen 1 – Monday Reminder – Write an exam

Appointment – 12:00 – 13:00 – Faculty Meeting

Errands:

  1. Reminder – Write an Exam
  2. Appointment – 12:00 – 13:00 – Faculty meeting

0. Back to main menu

Which would you like to delete?

>>

“Reminder – Write an Exam” Deleted

Option 5 Chosen

Save Calendar to file

Please enter the filename to store to

>>

Example File Output:

Next Few Days

  1. – Monday: 2 Errands
  2. Reminder – Write an exam

    Appointment – 12:00 – 13:00 – Faculty Meeting

  3. - Tuesday: No Errands
  4. – Wednesday: No Errands
  5. – Thursday: No Errands
  6. – Friday: No Errands
  7. – Saturday: No Errands
  8. – Sunday: No Errands
  9. – Monday: No Errands
  10. - Tuesday: No Errands
  11. – Wednesday: No Errands

Solution:

App:

#include < iostream> #include "Calendar.h" #include "Reminder.h" #include "Appointment.h" int getInput(string message, int lb, int ub) { /* This function is used to get a integer input from user with validation */ int value; while (true) { std::cout << message; std::cin >> value; std::cin.ignore(); if (value >= lb && value <= ub) { std::cin.sync(); return value; } else std::cout << "You must enter a value between " << lb << " and " << ub << "."; } } int main() { std::cout << "Hello World!\n"; Calendar calendar; int option; string str; int value, value2; int startTimeH, startTimeM, endTimeH, endTimeM; string days_of_week[7] = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" }; int ndays; string title, desc; bool calendar_created = false; while (true) { if (!calendar_created) // if calendar isn't created yet, create it { // Display main menu std::cout << "Welcome to CSE240 Calendar" << std::endl << std::endl; std::cout << "1. Build a new Calendar" << std::endl; std::cout << "2. Exit" << std::endl; // Ask for option option = getInput("Enter an option: ", 1, 2); if (option == 1) // build a new calendar { // ask user for calendar title std::cout << "Building a new calendar." << std::endl; std::cout << "Give your calendar a title: "; getline(cin, title); std::cin.clear(); ndays = getInput("How many days should this calendar have? ", 1, 999); // ask for number of days in the calendar std::cout << "What day does your calendar start on?" << std::endl; std::cout << "1. Monday" << std::endl; std::cout << "2. Tuesday" << std::endl; std::cout << "3. Wednesday" << std::endl; std::cout << "4. Thursday" << std::endl; std::cout << "5. Friday" << std::endl; std::cout << "6. Saturday" << std::endl; std::cout << "7. Sunday" << std::endl; value = getInput("", 1, 7); // ask for day number new(&calendar) Calendar(title, ndays, days_of_week[value - 1]); // create new calendar object with parameters given by user std::cout << "\nYour calendar has been created." << std::endl; calendar_created = true; } else if (option == 2) { std::cout << "Good bye!" << std::endl; break; } } else // calendar already createdm then perform operations with it { std::cout << "What would you like to do?" << std::endl; std::cout << "1. Display the whole calendar" << std::endl; std::cout << "2. Display a Single Day" << std::endl; std::cout << "3. Add an Errand" << std::endl; std::cout << "4. Delete an Errand" << std::endl; std::cout << "5. Save to a file" << std::endl; std::cout << "0. Exit" << std::endl; option = getInput("", 0, 5); // ask for option between 0 and 5 if (option == 0) { std::cout << "Good Bye!" << std::endl; break; } else if (option == 1) // Display the whole calendarr { calendar.display(); } else if (option == 2) // display a single day { int max = calendar.getDaysCount(); // get the number of days in the calendar value = getInput("Day (1 - " + to_string(max) + ") (0 - Back to main menu) ", 0, max); // ask for day number if (value != 0) // if input is different than zero, show day details, else, back to main menu { calendar.getDay(value - 1).display(); // display day info } } else if (option == 3) // add errand { calendar.display(); // display calendar details (Days, number of errands, etc)ç // ask to day to add an errand std::cout << std::endl; std::cout << "Add an Errand" << std::endl; std::cout << "Select which day you want to add an Errand to:" << std::endl; int max = calendar.getDaysCount(); value = getInput("Day (1 - " + to_string(max) + ") ", 1, max); std::cout << "What type of Errand?" << std::endl; std::cout << "1. Reminder" << std::endl; std::cout << "2. Appointment" << std::endl; std::cout << "0. Back to main menu" << std::endl; value2 = getInput("", 0, 2); if (value2 == 1) // user chose reminder { std::cout << "Enter reminder text: "; getline(cin, desc); std::cin.clear(); Reminder rem(desc); calendar.addErrand(value, rem); std::cout << "Reminder \"" << desc << "\" created." << std::endl; } else if (value2 == 2) // user chose appointment { startTimeH = getInput("Enter start time hour (24 hour clock): ", 0, 23); startTimeM = getInput("Enter start time minutes: ", 0, 60); endTimeH = getInput("Enter end time hour (24 hour clock): ", 0, 23); endTimeM = getInput("Enter end time minutes: ", 0, 60); Appointment ap = Appointment(startTimeH, startTimeM, endTimeH, endTimeM); calendar.addErrand(value, ap); std::cout << "Appointment created." << std::endl; } } else if (option == 4) // remove an errand { calendar.display(); // ask for erran details std::cout << std::endl; std::cout << "Remove an Errand" << std::endl; std::cout << "Select which day you want to add an Errand to:" << std::endl; int max = calendar.getDaysCount(); value = getInput("Day (1 - " + to_string(max) + ") ", 1, max); if (value != 0) // user entered a day number { std::cout << "You have choosen "; calendar.getDay(value - 1).display(); int max = calendar.getDay(value - 1).getErrands().size(); std::cout << "Errands: " << std::endl; int counter = 1; // display reminders for that day for (std::vector::iterator it = calendar.getDay(value - 1).getErrands().begin(); it != calendar.getDay(value - 1).getErrands().end(); it++) { std::cout << to_string(counter) << ". " << it->toString() << endl; counter++; } // ask for reminder id value2 = getInput("Which would you like to delete? ", 1, max); std::cout << "\"" << calendar.getDay(value - 1).getErrands()[value2 - 1].toString() << "\" deleted." << std::endl; calendar.getDay(value - 1).removeErrand(value2); } std::cout << "What type of Errand?" << std::endl; std::cout << "1. Reminder" << std::endl; std::cout << "2. Appointment" << std::endl; std::cout << "0. Back to main menu" << std::endl; } else if (option == 5) // save to a file { // ask for file name std::cout << "Save Calendar to file" << std::endl; std::cout << "Please enter the filename to store to: " << std::endl; getline(cin, desc); calendar.saveToFile(desc); // save std::cout << "Calendar saved to file " << desc << std::endl; } } std::cout << std::endl; std::cin.clear(); } }

Appointment:

#include "Appointment.h" int Appointment::getEndTimeMinute() { return endTimeMinute; } int Appointment::getEndTimeHour() { return endTimeHour; } int Appointment::getStartTimeHour() { return startTimeHour; } int Appointment::getStartTimeMinute() { return startTimeMinute; } Appointment::Appointment(int startTimeH, int startTimeM, int endTimeH, int endTimeM) { // Constructor startTimeHour = startTimeH; startTimeMinute = startTimeM; endTimeHour = endTimeH; endTimeMinute = endTimeM; } string Appointment::toString() { // Return info about appointment string ret = "Appointment - " + getDescription(); return ret; }

Calendar:

#include "Calendar.h" #include < iostream> #include < fstream> using namespace std; Calendar::Calendar() { // Non-arguments constructor // Array that contains the name for each day string days_of_week[7] = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" }; // default vaues title = "Calendar"; days = new Day[30]; starting_day = "Monday"; ndays = 30; days[0] = Day(1, starting_day); string name; int counter = 1; int id = 2; for (int i = 1; i < ndays; i++) { name = days_of_week[counter]; days[i] = Day(id, name); id++; counter++; if (counter == 7) counter = 0; } } Calendar::Calendar(string titl, int n, string start) { // Cosntructor with arguments // set variables title = titl; days = new Day[n]; starting_day = start; ndays = n; // array with name of days string days_of_week[7] = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" }; //find index of starting day int idx = 0; for (int i = 0; i < 7; i++) { if (days_of_week[i].compare(starting_day) == 0) { idx = i; break; } } // Create the next days after the starting one. days[0] = Day(1, starting_day); string name; int counter = idx+1; if (counter == 7) counter = 0; int id = 2; for (int i = 1; i < ndays; i++) { name = days_of_week[counter]; days[i] = Day(id, name); id++; counter++; if (counter == 7) counter = 0; } } // getters string Calendar::getTitle() { return title; } string Calendar::getStartingDay() { return starting_day; } Day* Calendar::getDays() { return days; } int Calendar::getDaysCount() { return ndays; } // setters void Calendar::setTitle(string newTitle) { title = newTitle; } void Calendar::setStartingDay(string newStart) { starting_day = newStart; } // methods void Calendar::display() { std::cout << "Calendar \"" << getTitle() << "\":" << std::endl; for (int i = 0; i < getDaysCount(); i++) { Day d = days[i]; std::cout << d.toString() << std::endl; } } Day Calendar::getDay(int index) { return days[index]; } void Calendar::addErrand(int dayIdx, Reminder r) { days[dayIdx-1].addErrand(r); } void Calendar::saveToFile(string filename) { // This function saves the calendar info to a file with name: filename ofstream myfile; myfile.open(filename); myfile << "Calendar \"" << getTitle() << "\":" << std::endl; for (int i = 0; i < getDaysCount(); i++) { Day d = days[i]; myfile << d.details() << std::endl; // day info returned by function details() } myfile.close(); }

Day:

#include "Day.h" #include < iostream> // getters int Day::getDayNumber() { return N; } string Day::getDayName() { return day_of_week; } vector Day::getErrands() { return errands; } // default constructor Day::Day() { N = 1; day_of_week = "Monday"; } Day::Day(int n, string name) { N = n; day_of_week = name; } void Day::addErrand(Reminder r) { errands.push_back(r); // add new errand to this day } void Day::removeErrand(int idx) { errands.erase(errands.begin()+idx - 1); // remove errand by index } string Day::toString() { // Returns day id, name and number of errands in that day string ret; if (errands.size() > 0) ret = to_string(getDayNumber()) + " - " + getDayName() + ": " + to_string(errands.size()) + " Errands"; else ret = to_string(getDayNumber()) + " - " + getDayName() + ": No Errands"; return ret; } void Day::display() { // Prints info about this day (reminder, appointment, etc), with day id and name std::cout << to_string(N) << " - " << day_of_week << ": " << std::endl; if (errands.size() > 0) { for (std::vector::iterator i = errands.begin(); i != errands.end(); i++) { std::cout << "\t" << i->toString() << std::endl; } } } string Day::details() { // Returns info about this day string ret = ""; ret += to_string(N) + " - " + day_of_week + ": \n"; if (errands.size() > 0) { for (std::vector::iterator i = errands.begin(); i != errands.end(); i++) { ret += "\t" + i->toString() + "\n"; } } return ret; }

Reminder:

#include "Reminder.h" Reminder::Reminder() { description = ""; } Reminder::Reminder(string desc) { description = desc; } string Reminder::getDescription() { return description; } void Reminder::setDescription(string desc) { description = desc; } string Reminder::toString() { string ret = "Reminder - " + getDescription(); return ret; }