its about in C++
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:
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...
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 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 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 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 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 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 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 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 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) 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...