Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<iomanip>
- using namespace std;
- struct node {
- string title, description, month;
- int date=0;
- node* next=NULL;
- }*first = NULL, * last = NULL;
- void month(string month[], int x) {
- month[0] = "January"; month[1] = "February"; month[2] = "March"; month[3] = "April"; month[4] = "May";
- month[5] = "June"; month[6] = "July"; month[7] = "August"; month[8] = "September"; month[9] = "October";
- month[10] = "November"; month[11] = "December";
- }
- int check(string a) {
- int d=0;
- if (a == "Sunday") {d = 0;} else if (a == "Monday") {d = 1;} else if (a == "Tuesday") {d = 2;}
- else if (a == "Wednesday") {d = 3;} else if (a == "Thursday") {d = 4;} else if (a == "Friday") {d = 5;}
- else if (a == "Saturday") {d = 6;}
- return d;
- }
- int check1(string month,int date, struct node* p) {
- while (p != NULL) {
- if (p->month == month && p->date == date) {
- return date;
- }
- else {
- p = p->next;
- }
- }
- return 0;
- }
- void insert() {
- node* t;
- t = new node;
- cout << "a.Reminder title" << endl;
- getline(cin, t->title);
- cout << "b.Reminder description" << endl;
- getline(cin, t->description);
- cout << "c.Date" << endl;
- cin >> t->date;
- cout << "d.Month" << endl;
- cin >> t->month;
- t->next = NULL;
- if (first == NULL) {
- first = last= t;
- }
- else {
- last->next = t;
- last = t;
- }
- }
- void day() {
- string** day = new string * [1];
- *day = new string[7];
- day[0][0] = "Sun";
- day[0][1] = "Mon";
- day[0][2] = "Tue";
- day[0][3] = "Wed";
- day[0][4] = "Thu";
- day[0][5] = "Fri";
- day[0][6] = "Sat";
- for (int i = 0; i < 7; i++) {
- cout << right << setw(4) << day[0][i];
- }
- cout << endl;
- delete[] day[0];
- delete[] day;
- }
- int date(int starting_day,int total_day,string month) {
- int n = 1,day=0;
- int row;
- if (starting_day == 5 && total_day == 31) {
- row = 6;
- }
- else if (starting_day == 5 && total_day == 30) {
- row = 5;
- }
- else if (starting_day == 6) {
- row = 6;
- }
- else {
- row = 5;
- }
- int** date = new int*[row];
- for (int i = 0; i < row; i++) {
- if (day >0 && day<7) {
- date[i] = new int[day];
- for (int j = 0; j<day ; j++) {
- date[i][j] = n;
- n++;
- }
- }
- else {
- date[i] = new int[7];
- for (int j = 0; j < 7; j++) {
- if (i == 0 && j < starting_day) {
- date[i][j] = NULL;
- }
- else {
- date[i][j] = n;
- day = total_day - n;
- n++;
- }
- }
- }
- }
- for (int i = 0; i < row; i++) {
- for (int j = 0; j < 7; j++) {
- if (i == 0 && j < starting_day) {
- cout<<" ";
- }
- else {
- int k=check1(month,date[i][j],first);
- if (k == date[i][j]) {
- if (k < 10) {
- cout << right << setw(3) << "*" << date[i][j];
- }
- else {
- cout << right << setw(2) << "*" << date[i][j];
- }
- }
- else {
- cout << right << setw(4) << date[i][j];
- }
- }
- if (date[i][j] == total_day) {
- cout << endl;
- starting_day = j + 1;
- if (starting_day == 7) {
- starting_day = 0;
- }
- break;
- }
- }
- cout << endl;
- }
- cout << endl;
- for (int i = 0; i < row; i++) {
- delete[] date[i];
- }
- delete[] date;
- return starting_day;
- }
- void calendar(string a, int year,string month[],int x) {
- int starting_day, total_day;
- starting_day = check(a);
- cout << "-----------"<<month[0]<<"-------------" << endl;
- total_day = 31;
- day();
- starting_day = date(starting_day, total_day,month[0]);
- cout << "------------" << month[1] << "-------------" << endl;
- if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
- total_day = 29;
- }
- else {
- total_day = 28;
- }
- day();
- starting_day = date(starting_day, total_day,month[1]);
- cout << "------------" << month[2] << "-------------" << endl;
- total_day = 31;
- day();
- starting_day = date(starting_day, total_day,month[2]);
- cout << "------------" << month[3] << "-------------" << endl;
- total_day = 30;
- day();
- starting_day = date(starting_day, total_day,month[3]);
- cout << "------------" << month[4] << "-------------" << endl;
- total_day = 31;
- day();
- starting_day = date(starting_day, total_day,month[4]);
- cout << "------------" << month[5] << "-------------" << endl;
- total_day = 30;
- day();
- starting_day = date(starting_day, total_day, month[5]);
- cout << "------------" << month[6] << "-------------" << endl;
- total_day = 31;
- day();
- starting_day = date(starting_day, total_day, month[6]);
- cout << "------------" << month[7] << "-------------" << endl;
- total_day = 31;
- day();
- starting_day = date(starting_day, total_day, month[7]);
- cout << "------------" << month[8] << "-------------" << endl;
- total_day = 30;
- day();
- starting_day = date(starting_day, total_day, month[8]);
- cout << "------------" << month[9] << "-------------" << endl;
- total_day = 31;
- day();
- starting_day = date(starting_day, total_day, month[9]);
- cout << "------------" << month[10] << "-------------" << endl;
- total_day = 30;
- day();
- starting_day = date(starting_day, total_day, month[10]);
- cout << "------------" << month[11] << "-------------" << endl;
- total_day = 31;
- day();
- starting_day = date(starting_day, total_day, month[11]);
- }
- void update(struct node*p) {
- string a, b;
- int c;
- cout << "a.Reminder title" << endl;
- getline(cin, a);
- cout << "c.Date" << endl;
- cin >> c;
- cin.ignore();
- cout << "d.Month" << endl;
- cin >> b;
- while (p != NULL) {
- if (p->title == a && p->date == c && p->month == b) {
- cout << "Update your reminder: " << endl;
- cout << "a.Reminder title" << endl;
- cin.ignore();
- getline(cin, p->title);
- cout << "b.Date" << endl;
- cin >> p->date;
- cin. ignore();
- cout << "c.Reminder description" << endl;
- getline(cin,p->description);
- cout << "d.Month" << endl;
- cin >> p->month;
- return;
- }
- else {
- p = p->next;
- }
- }
- }
- void delete1(struct node*p) {
- string a, b;
- int c;
- cout << "a.Reminder title" << endl;
- getline(cin, a);
- cout << "c.Date" << endl;
- cin >> c;
- cin.ignore();
- cout << "d.Month" << endl;
- cin >> b;
- node* q = NULL;
- int index = 1;
- while (p != NULL) {
- if (p->title == a && p->date == c && p->month == b) {
- break;
- }
- else {
- index++;
- p = p->next;
- }
- }
- p = first;
- while (p != NULL) {
- if (index==1) {
- q = first;
- first = first->next;
- delete q;
- return;
- }
- else {
- for (int i = 0; i < index-1; i++) {
- q = p;
- p = p->next;
- }
- q->next = p->next;
- delete p;
- return;
- }
- }
- }
- void reminders_of_a_specific_month() {
- string x;
- cout << "Enter the month name: " << endl;
- cin >> x;
- struct node* p = first;
- while (p != NULL) {
- if (p->month == x) {
- cout << "a.Reminder title:" << endl;
- cout << p->title << endl;
- cout << "b.Reminder description:" << endl;
- cout << p->description << endl;
- cout << "c.Date" << endl;
- cout << p->date << endl;
- cout << "d.Month" << endl;
- cout << p->month << endl;
- }
- p = p->next;
- }
- }
- int main() {
- int year;
- string a;
- cout << "Input:" << endl;
- cout << "Year: ";
- cin >> year;
- cout << "Starting day of the year : ";
- cin >> a;
- string mon[12];
- month(mon, 12);
- calendar(a,year,mon,12);
- for (int i = 1; ; i++) {
- cout << "You can perform the following operation: " << endl;
- cout << "Press 1 if you want to add reminder" << endl;
- cout << "Press 2 if you want to update reminder" << endl;
- cout << "Press 3 if you want to delete a specific reminder" << endl;
- cout << "Press 4 if you want to view all the reminders of a specific month" << endl;
- cout << "Press 5 if you want to exit from the calendar" << endl;
- int b;
- cin >> b;
- cin.ignore();
- if (b == 1) {
- insert();
- calendar(a, year, mon, 12);
- }
- else if (b == 2) {
- update(first);
- calendar(a, year, mon, 12);
- }
- else if (b == 3) {
- delete1(first);
- calendar(a, year, mon, 12);
- }
- else if (b == 4) {
- reminders_of_a_specific_month();
- }
- else if (b == 5) {
- return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement