Question

In this hormework, you will implement a simple caledar application The implernentation shauld include a class narned Calendar

The Calendar Class This class will be a container class for the Event objects. It will implement a linked list where each lis

Do that with C++ and please add more comment that make it understandable

In this hormework, you will implement a simple caledar application The implernentation shauld include a class narned Calendar, an abstract class named Event and two concrete classes narmed Task and Appointment which irherit from the Evernt class. The Event Class This will be an abstract class. It will have four private integer members called year, month, day and hour which desigate the tirne of the event. It shauld also have ar integer member called id which should be a unique id for the event. The id should start from zero and should incrernent by 1 for each new event generated. The event class should have a constructor that sets the evet tie (year, month, day and hour mernbers) and should also have get methods for its private mermbers. The event class will have a pure irtual function called print with the following prototype: virtual void printO const; The Task Class This class will derive fror the Event class. On top of the base class, it should have an extra private string mernber called taskname which includes the task to be performed. It should have a constructor, and set/get methods for its private member. Its print function should the print function of Event class which shauld print the tasknarne and event tirme irn the following format: Task with id 20 at 22/04/2019, 23:00: Submit CP homework 1 The Appointment Class This class will derive frorm the Event class. On top of the base class, it should have an extra private string merber clled personnarne with whorn the appointment is and a private string member place where the appointment ll be. It should have a constructor and set/get methods for its private members. Its prit function should iriplernent the print function of Event class which should print the appointment details in the following format: Appointment with id 21 at 16/04/2019,18:00: Dr. George Wilson, Marnara University
The Calendar Class This class will be a container class for the Event objects. It will implement a linked list where each list elerment can be one of Task or Appointrment objects. It should have the following methods Event addEventnt eventType, t year, kt month, int day,int hur Alocates a new event object, azes it and ados the event to the end of the inkedist. t returns a pointer to the alocated event. eventTyoe is for a Task and 1 for an Appointment. deleteEventfint id); Remaves the event with the given id from the ist and deallocates the event object. void listEvents: Lists the events in the ist For each event in the list event should cal the oin function for that void filterEvents int year, int month Lists the events that are scheduled in the gven yearand month. For each event, it shouid a the print function for that event. The main function Implement a main function that does the following: 7. Adds 5 Task Events and 5 Appointment Events with various times to the calendar. Set the Task and Appointment details as you wisth. 2. Lists all events in the calendar. 3. Deletes an appointment you wish from the calendar. 4. Filters and lists all events scheduled at a certain day you designate.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <List>
#include <iostream>
#include <string>
#include <algorithm>

class Event
{
   int m_hour;
   int m_day;
   int m_month;
   int m_year;
   static int id;
   int m_id;

public:
   Event(int hour, int day, int month, int year):m_hour(hour),m_day(day),m_month(month),m_year(year)
   {
       m_id = id++;
   }

   virtual void print() = 0;

   int getId()
   {
       return m_id;
   }
   int getDay()
   {
       return m_day;
   }

   int getHour()
   {
       return m_hour;
   }

   int getMonth()
   {
       return m_month;
   }

   int getYear()
   {
       return m_year;
   }
};

int Event::id = 0;

class Task:public Event
{
   std::string m_taskname;

public:
   Task(std::string taskName, int hour, int day, int month, int year) :m_taskname(taskName),Event(hour,day,month,year)
   {

   }

   void print()
   {
       std::cout << "Task with id " << getId() << " at " << getDay() << "/" << getMonth() << "/" << getYear() << "," << getHour() << ":00;" << std::endl;
       std::cout << m_taskname;
       std::cout << std::endl;
   }
};

class Appointment :public Event
{
   std::string m_personName;

public:
   Appointment(std::string personName, int hour, int day, int month, int year) :m_personName(personName), Event(hour, day, month, year)
   {

   }

   void print()
   {
       std::cout << "Appointment with id " << getId() << " at " << getDay() << "/" << getMonth() << "/" << getYear() << "," << getHour() << ":00;" << std::endl;
       std::cout << m_personName;
       std::cout << std::endl;
   }
};


class Calendar
{
   std::list<Event*> m_listofEvents;

public:
   Event* addEvent(int eventType, int year, int month, int day, int hour)
   {
       static int count = 0;
       Event* anEvent = nullptr;
       switch(eventType)
       {
       case 0:
       {
           count++;
           std::string taskName;
           std::cout << "Enter the Task Name for Task "<<count<<" ";
           std::getline(std::cin, taskName);
           std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
           anEvent = new Task(taskName, hour, day, month, year);
           break;
       }
       case 1:
       {
           count++;
           std::string personName;
           std::cout << "Enter the Person Name for Appointment" << count<<" ";
           std::getline(std::cin, personName);
           std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
           anEvent = new Appointment(personName, hour, day, month, year);
           break;
       }
       default:
           break;
       }
      
       m_listofEvents.push_back(anEvent);
       return anEvent;
   }

   void deleteEvent(int id)
   {
       m_listofEvents.remove_if([&](Event* anEvent)->bool {
           return (anEvent->getId() == id);
       });
   }

   void listEvents()
   {
       for (Event* anEvent : m_listofEvents)
       {
           if (anEvent)
               anEvent->print();
       }
   }

   void filterEvents(int year, int month)
   {
       for (Event* anEvent : m_listofEvents)
       {
           if ((anEvent->getMonth() == month)
               && (anEvent->getYear() == year))
           {
               anEvent->print();
           }
       }
   }
};

void main()
{
   Calendar calendar;
  
   calendar.addEvent(0, 2019, 4, 10, 23);
   calendar.addEvent(0, 2019, 5, 6, 22);
   calendar.addEvent(0, 2019, 4, 5, 20);
   calendar.addEvent(0, 2019, 2, 19, 19);
   calendar.addEvent(0, 2019, 5, 1, 21);

   calendar.addEvent(1, 2019, 4, 1, 23);
   calendar.addEvent(1, 2019, 5, 16, 22);
   calendar.addEvent(1, 2019, 4, 15, 20);
   calendar.addEvent(1, 2019, 2, 9, 19);
   calendar.addEvent(1, 2019, 5, 1, 21);

   std::cout << "\n Listing Events \n";
   calendar.listEvents();

   calendar.deleteEvent(3);

   std::cout << "\n Listing Events after Filtering \n";

   calendar.filterEvents(2019, 4);

}

OUTPUT:

Enter the Task Name for Task 1 Assignment 1 Enter the Task Name for Task 2 Assignment 2 Enter the Task Name for Task 3 Assign

Add a comment
Know the answer?
Add Answer to:
In this hormework, you will implement a simple caledar application The implernentation shauld inc...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • its about in C++ You will implement a simple calendar application The implementation should include a class named Calendar, an abstract class named Event and two concrete classes named Task an...

    its about in C++ You will implement a simple calendar application The implementation should include a class named Calendar, an abstract class named Event and two concrete classes named Task and Appointment which inherit from the Event class The Event Class This will be an abstract class. It will have four private integer members called year, month, day and hour which designate the time of the event It should also have an integer member called id which should be a...

  • Create an abstract class “Appointment” that represents an event on a calendar. The “Appointment” class will...

    Create an abstract class “Appointment” that represents an event on a calendar. The “Appointment” class will have four instance variables: • An instance variable called “year” which will be of type int • An instance variable called “month” which will be of type int • An instance variable called “day” which will be of type int • An instance variable called “description” which will be of type String The “Appointment” class must also implement the following methods: • A getter...

  • You are to create a class Appointment.java that will have the following: 5 Instance variables: private...

    You are to create a class Appointment.java that will have the following: 5 Instance variables: private String month private int day private int year private int hour private int minute 1 default constructor public Appointment() 1 non-default constructor that accepts arguments for all instance variables, your constructor must call the setter methods below to set the values of the instance variables public Appointment(String monthPassed, int dayPassed, int yearPassed, int hourPassed, int minutePassed) 5 setter methods (one for each instance variable)...

  • The class dateType is designed to implement the date in a program, but the member function...

    The class dateType is designed to implement the date in a program, but the member function setDate and the constructor do not check whether the date is valid before storing the date in the data members. Rewrite the definitions of the function setDate and the constructor so that the values for the month, day, and the year are checked before storing the date into the data members. Add a function member, isLeapYear, to check whether a year is a leap...

  • Design and implement a C++ class called Date that has the following private member variables month...

    Design and implement a C++ class called Date that has the following private member variables month (int) day (nt) . year (int Add the following public member functions to the class. Default Constructor with all default parameters: The constructors should use the values of the month, day, and year arguments passed by the client program to set the month, day, and year member variables. The constructor should check if the values of the parameters are valid (that is day is...

  • C++ This exercise will introduce static member variables and static methods in class to you. Class...

    C++ This exercise will introduce static member variables and static methods in class to you. Class Department contain information about universities departments: name students amount in addition it also stores information about overall amount of departments at the university: departments amount class Department { public: Department(string i_name, int i_num_students); ~Department(); int get_students(); string get_name(); static int get_total(); private: string name; int num_students; static int total_departments; }; Carefully read and modify the template. You have to implement private static variable "total...

  • c++ Part 1 Consider using the following Card class as a base class to implement a...

    c++ Part 1 Consider using the following Card class as a base class to implement a hierarchy of related classes: class Card { public: Card(); Card (string n) ; virtual bool is_expired() const; virtual void print () const; private: string name; Card:: Card() name = ""; Card: :Card (string n) { name = n; Card::is_expired() return false; } Write definitions for each of the following derived classes. Derived Class Data IDcard ID number CallingCard Card number, PIN Driverlicense Expiration date...

  • C++ Practice: Answer Whichever you can & it'll help a lot. Thank you! Question 1. Implement...

    C++ Practice: Answer Whichever you can & it'll help a lot. Thank you! Question 1. Implement the constructors and member function of each of the classes (Marks 15) class Fraction{ private: int numerator; int denominator; public: Fraction(int, int); float fractionValue();//determines the value of numerator/denominator }; class Problem{ private: Fraction f[3]; public: Problem(int, int, int, int, int, int); Fraction largestFraction();//Returns the fraction having largest fraction value }; Question 2: In the following Inheritance problem #include<iostream> #include<string> using namespace std; class Animal{...

  • Create a class called Flower. Add one member variables color. Add only one getter function for the color. The get function returns color. Implement a constructor that expects color value and assigns it to the member variable. Create a subclass of Flower

    Create a class called Flower. Add one member variables color. Add only one getter function for the color. The get function returns color. Implement a constructor that expects color value and assigns it to the member variable. Create a subclass of Flower named Rose. The Rose class has one member variable name.  Add a constructor which expects color and  name. Pass color to the base constructor and set name to it's member variable.Write a program that has an array of ...

  • C++ Could you check my code, it work but professor said that there are some mistakes(check...

    C++ Could you check my code, it work but professor said that there are some mistakes(check virtual functions, prin() and others, according assignment) . Assignment: My code: #include<iostream> #include<string> using namespace std; class BasicShape { //Abstract base class protected: double area; private:    string name; public: BasicShape(double a, string n) { area=a; name=n; } void virtual calcArea()=0;//Pure Virtual Function virtual void print() { cout<<"Area of "<<getName()<<" is: "<<area<<"\n"; } string getName(){    return name; } }; class Circle : public...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT