Question

its about in C++

You will implement a simple calendar application The implementation should include a class named Calendar, an abstract class

deleted is not found in the event list void listEvents Lists the events in the list. For each event in the list, it should ca

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 unique id for the event. The id should start from zero and should increment by 1 for each new event generated. The event class should have a constructor that sets the event time (year, month, day and hour members) and should also have get methods for its private members. The event class will have a pure virtual function called print0 with the following prototype virtual void print0 const:; The Task Class This class will derive from the Event class. On top of the base class, it should have an extra private string member 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 implement the print function of Event class which should print the taskname and event time in the following format: Task with id 20 at 10/02/2018, 12:00: Submit Homework The Appointment Class This class will derive from the Event class. On top of the base class, it should have an extra private string member called personname with whom the appointment is and a private string mermber place where the appointment will be. It should have a constructor and set/get methods for its private members. Its print function should implement the print function of Event class which should print the appointment details in the following format: Appointment with id 21 at 10/11/2018, 10:00: George Wilson, Istanbul Technical University The Calendar Class This class will be a container class for the Event objects. It will implement a linked list where each list element can be one of Task or Appointment objects. It should have the following methods: Event addEvent(int eventType, int year, int month, int day, int hour); Allocates a new event object, initializes it and adds the event to the end of the linked list. It returns a pointer to the allocated event. eventType is O for a Task and 1 for an Appointment. deleteEvent (int id); Removes the event with the given id from the list and deallocates the event object. The deleteEvent method will throw an "EventNotFound" string exception if the event to be
deleted is not found in the event list void listEvents Lists the events in the list. For each event in the list, it should call the print function for that event. The listEvent method will throw a "ListEmpty" string exception if the event list is empty. void filterEvents(int year, int month); Lists the events that are scheduled in the given year and month. For each event, it should call the print function for that event. The filterEvent method will throw a "NoMatchingEvent string exception if the list doesn't have any matching events The exception handlers should print the corresponding error message from the exception to the screen The main function Implement a main function that does the following: 1. Adds 5 Task Events and 5 Appointment Events with various times to the calendar. Set the Task and Appointment details as you wish. 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. 5. Demonstrates the three exceptions above.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

C++ code:

#include<iostream>
using namespace std;
int start_id=0;
class Event
{
private:
int year;
int month;
int day;
int hour;
int id;
public:
Event *next;
Event(int y,int m,int d,int h)
{
year=y;
month=m;
day=d;
hour=h;
id=start_id;
start_id++;
}
int getId()
{
return id;
}
int getYear()
{
return year;
}
int getMonth()
{
return month;
}
int getDay()
{
return day;
}
int getHour()
{
return hour;
}
virtual void print()=0;
};
class Task:public Event
{
private:
string taskname;
public:
Task(string t,int y,int m,int d,int h):Event(y,m,d,h)
{
taskname=t;
}
void setTaskname(string t)
{
taskname=t;
}
string getTaskname()
{
return taskname;
}
void print()
{
cout<<"Task with id "<<getId()<<" at "<<getDay()<<"/"<<getMonth()<<"/"<<getYear()<<", "<<getHour()<<":00:"<<endl;
cout<<taskname<<endl;
}
};
class Appointment:public Event
{
private:
string personname;
public:
Appointment(string p,int y,int m,int d,int h):Event(y,m,d,h)
{
personname=p;
}
void setPersonname(string p)
{
personname=p;
}
string getPersonname()
{
return personname;
}
void print()
{
cout<<"Appointment with id "<<getId()<<" at "<<getDay()<<"/"<<getMonth()<<"/"<<getYear()<<", "<<getHour()<<":00:"<<endl;
cout<<personname<<endl;
}
};
class Calendar
{
private:
Event *head;
public:
Calendar()
{
head=NULL;
}
Event *addEvent(int eventType,string name,int year,int month,int day,int hour)
{
Event *temp;
if(eventType==0)
{
temp=new Task(name,year,month,day,hour);
}
else if(eventType==1)
{
temp=new Appointment(name,year,month,day,hour);
}
temp->next=NULL;
if(head==NULL)
{
head=temp;
return temp;
}
Event *p=head;
while(p->next!=NULL)
p=p->next;
p->next=temp;
return temp;
}
void deleteEvent(int id)
{
try
{
Event *p=head;
Event *q=NULL;
if(head->getId()==id)
{
head=p->next;
delete p;
cout<<"Deleted event with id="<<id<<endl;
return;
}
while(p->getId()!=id)
{
q=p;
p=p->next;
if(p==NULL)
break;
}
if(p==NULL)
{
string c="Event not found\n";
throw c;
}
else
{
q->next=p->next;
delete p;
cout<<"Deleted";
return;
}
}
catch(string c)
{
cout<<c;
return;
}
}
void listEvents()
{
try
{
if(head==NULL)
{
string s="ListEmpty\n";
throw s;
}
Event *temp=head;
while(temp!=NULL)
{
temp->print();
temp=temp->next;
}
}
catch(string s)
{
cout<<s;
}
}
void filterEvents(int year,int month)
{
try
{
int c=0;
Event *temp=head;
while(temp!=NULL)
{
if(temp->getYear()==year&&temp->getMonth()==month)
{
temp->print();
c++;
}
temp=temp->next;
}
if(c==0)
{
string s="No matching event\n";
throw s;
}
}
catch(string s)
{
cout<<s;
}
}
};
int main()
{
Calendar c;
c.addEvent(0,"Eat",2018,9,11,12);
c.addEvent(0,"Bath",2019,10,13,14);
c.addEvent(0,"Walk",2018,11,15,16);
c.addEvent(0,"Work",2019,12,17,18);
c.addEvent(0,"Mail",2019,1,19,20);
c.addEvent(1,"George",2018,2,21,22);
c.addEvent(1,"Sia",2019,3,23,1);
c.addEvent(1,"Katherine",2018,4,25,3);
c.addEvent(1,"John",2019,5,27,5);
c.addEvent(1,"Peter",2018,6,29,7);
c.listEvents();
cout<<endl;
c.deleteEvent(9);
cout<<endl;
c.filterEvents(2019,10);
cout<<endl;
//Now demonstrate 3 exceptions
c.deleteEvent(11);
c.filterEvents(2020,1);
for(int i=0;i<9;i++)
{
c.deleteEvent(i);
}
c.listEvents();
return 0;
}

output:

Task with id 0 at 11/9/2018, 12:00: Eat Task with id 1 at 13/10/2019, 14:00: ath ask with id 2 at 15/11/2018, 16:00: alk ask

Add a comment
Know the answer?
Add Answer to:
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...
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
  • In this hormework, you will implement a simple caledar application The implernentation shauld inc...

    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...

  • 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...

  • About Classes and OOP in C++ Part 1 Task 1: Create a class called Person, which...

    About Classes and OOP in C++ Part 1 Task 1: Create a class called Person, which has private data members for name, age, gender, and height. You MUST use this pointer when any of the member functions are using the member variables. Implement a constructor that initializes the strings with an empty string, characters with a null character and the numbers with zero. Create getters and setters for each member variable. Ensure that you identify correctly which member functions should...

  • C++ program, item.cpp implementation. Implementation: You are supposed to write three classes, called Item, Node and In...

    C++ program, item.cpp implementation. Implementation: You are supposed to write three classes, called Item, Node and Inventory respectively Item is a plain data class with item id, name, price and quantity information accompanied by getters and setters Node is a plain linked list node class with Item pointer and next pointer (with getters/setters) Inventory is an inventory database class that provides basic linked list operations, delete load from file / formatted print functionalities. The majority of implementation will be done...

  • Create a C++ project with 2 classes, Person and Birthdate. The description for each class is...

    Create a C++ project with 2 classes, Person and Birthdate. The description for each class is shown below: Birthdate class: private members: year, month and day public members: copy constructor, 3 arguments constructor, destructor, setters, getters and age (this function should return the age) Person class: private members: firstName, lastName, dateOfBirth, SSN public members: 4 arguments constructor (firstName, lastName, datOfBirth and SNN), destructor and printout Implementation: - use the separated files approach - implement all the methods for the 2...

  • 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++ 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...

  • 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...

  • I need the following written in Java please, thank you ' We want you to implement...

    I need the following written in Java please, thank you ' We want you to implement a java class that will show details on users and throw exceptions where needed. The following requirements specify what fields you are expected to implement in your User class: - A private String firstName that specifies the first name of the user - A private String lastName that specifies the last name of the user - A private int age that specifies user's age...

  • 1a. Create a class named Computer - Separate declaration from implementation (i.e. Header and CPP files)...

    1a. Create a class named Computer - Separate declaration from implementation (i.e. Header and CPP files) 1b. Add the following private member variables - an int variable named year - a string variable named model - a string variable named purpose 1c Add the following public functions: - Default constructor which sets numeric members to -1 and string members to the empty string - Destructor to print "Removing instance from memory" - A non-default constructor to set the year and...

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