Advertisement
dirtydevil123

Calendar Project

Aug 6th, 2021
1,017
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.93 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<iomanip>
  4. using namespace std;
  5. struct node {
  6.     string title, description, month;
  7.     int date=0;
  8.     node* next=NULL;
  9. }*first = NULL, * last = NULL;
  10. void month(string month[], int x) {
  11.     month[0] = "January"; month[1] = "February"; month[2] = "March"; month[3] = "April"; month[4] = "May";
  12.     month[5] = "June"; month[6] = "July"; month[7] = "August"; month[8] = "September"; month[9] = "October";
  13.     month[10] = "November"; month[11] = "December";
  14. }
  15. int check(string a) {
  16.     int d=0;
  17.     if (a == "Sunday") {d = 0;} else if (a == "Monday") {d = 1;} else if (a == "Tuesday") {d = 2;}
  18.     else if (a == "Wednesday") {d = 3;} else if (a == "Thursday") {d = 4;} else if (a == "Friday") {d = 5;}
  19.     else if (a == "Saturday") {d = 6;}
  20.     return d;
  21. }
  22. int check1(string month,int date, struct node* p) {
  23.  
  24.     while (p != NULL) {
  25.         if (p->month == month && p->date == date) {
  26.             return date;
  27.            
  28.         }
  29.         else {
  30.             p = p->next;
  31.         }
  32.     }
  33.     return 0;
  34. }
  35. void insert() {
  36.     node* t;
  37.     t = new node;
  38.     cout << "a.Reminder title" << endl;
  39.     getline(cin, t->title);
  40.     cout << "b.Reminder description" << endl;
  41.     getline(cin, t->description);
  42.     cout << "c.Date" << endl;
  43.     cin >> t->date;
  44.     cout << "d.Month" << endl;
  45.     cin >> t->month;
  46.     t->next = NULL;
  47.     if (first == NULL) {
  48.         first = last= t;
  49.  
  50.     }
  51.     else {
  52.         last->next = t;
  53.         last = t;
  54.     }
  55. }
  56. void day() {
  57.     string** day = new string * [1];
  58.     *day = new string[7];
  59.     day[0][0] = "Sun";
  60.     day[0][1] = "Mon";
  61.     day[0][2] = "Tue";
  62.     day[0][3] = "Wed";
  63.     day[0][4] = "Thu";
  64.     day[0][5] = "Fri";
  65.     day[0][6] = "Sat";
  66.     for (int i = 0; i < 7; i++) {
  67.         cout << right << setw(4) << day[0][i];
  68.     }
  69.     cout << endl;
  70.     delete[] day[0];
  71.     delete[] day;
  72. }
  73.  
  74. int date(int starting_day,int total_day,string month) {
  75.     int  n = 1,day=0;
  76.     int row;
  77.     if (starting_day == 5 && total_day == 31) {
  78.         row = 6;
  79.     }
  80.     else if (starting_day == 5 && total_day == 30) {
  81.         row = 5;
  82.     }
  83.     else if (starting_day == 6) {
  84.         row = 6;
  85.     }
  86.     else {
  87.         row = 5;
  88.     }
  89.     int** date = new int*[row];
  90.     for (int i = 0; i < row; i++) {
  91.         if (day >0  && day<7) {
  92.             date[i] = new int[day];
  93.             for (int j = 0; j<day ; j++) {
  94.                 date[i][j] = n;
  95.                         n++;
  96.             }
  97.         }
  98.         else {
  99.             date[i] = new int[7];
  100.             for (int j = 0; j < 7; j++) {
  101.                 if (i == 0 && j < starting_day) {
  102.                     date[i][j] = NULL;
  103.                 }
  104.                 else {
  105.                     date[i][j] = n;
  106.                     day = total_day - n;
  107.                     n++;
  108.                 }
  109.             }
  110.         }
  111.  
  112.     }
  113.     for (int i = 0; i < row; i++) {
  114.         for (int j = 0; j < 7; j++) {
  115.             if (i == 0 && j < starting_day) {
  116.                 cout<<"    ";
  117.             }
  118.             else {
  119.                 int k=check1(month,date[i][j],first);
  120.                 if (k == date[i][j]) {
  121.                     if (k < 10) {
  122.                         cout << right << setw(3) << "*" << date[i][j];
  123.                     }
  124.                     else {
  125.                         cout << right << setw(2) << "*" << date[i][j];
  126.                     }
  127.                 }
  128.                 else {
  129.                     cout << right << setw(4) << date[i][j];
  130.                 }
  131.             }
  132.             if (date[i][j] == total_day) {
  133.                 cout << endl;
  134.              starting_day = j + 1;
  135.              if (starting_day == 7) {
  136.                  starting_day = 0;
  137.              }
  138.              break;
  139.             }
  140.         }
  141.         cout << endl;
  142.     }
  143.     cout << endl;
  144.    
  145.     for (int i = 0; i < row; i++) {
  146.         delete[] date[i];
  147.     }
  148.     delete[] date;
  149.     return starting_day;
  150. }
  151. void calendar(string a, int year,string month[],int x) {
  152.     int starting_day, total_day;
  153.     starting_day = check(a);
  154.     cout << "-----------"<<month[0]<<"-------------" << endl;
  155.     total_day = 31;
  156.     day();
  157.     starting_day = date(starting_day, total_day,month[0]);
  158.  
  159.  
  160.     cout << "------------" << month[1] << "-------------" << endl;
  161.     if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
  162.         total_day = 29;
  163.     }
  164.     else {
  165.         total_day = 28;
  166.     }
  167.     day();
  168.     starting_day = date(starting_day, total_day,month[1]);
  169.  
  170.     cout << "------------" << month[2] << "-------------" << endl;
  171.     total_day = 31;
  172.     day();
  173.     starting_day = date(starting_day, total_day,month[2]);
  174.  
  175.  
  176.     cout << "------------" << month[3] << "-------------" << endl;
  177.     total_day = 30;
  178.     day();
  179.     starting_day = date(starting_day, total_day,month[3]);
  180.  
  181.  
  182.     cout << "------------" << month[4] << "-------------" << endl;
  183.     total_day = 31;
  184.     day();
  185.     starting_day = date(starting_day, total_day,month[4]);
  186.  
  187.  
  188.     cout << "------------" << month[5] << "-------------" << endl;
  189.     total_day = 30;
  190.     day();
  191.     starting_day = date(starting_day, total_day, month[5]);
  192.  
  193.  
  194.     cout << "------------" << month[6] << "-------------" << endl;
  195.     total_day = 31;
  196.     day();
  197.     starting_day = date(starting_day, total_day, month[6]);
  198.  
  199.  
  200.     cout << "------------" << month[7] << "-------------" << endl;
  201.     total_day = 31;
  202.     day();
  203.     starting_day = date(starting_day, total_day, month[7]);
  204.     cout << "------------" << month[8] << "-------------" << endl;
  205.     total_day = 30;
  206.     day();
  207.     starting_day = date(starting_day, total_day, month[8]);
  208.     cout << "------------" << month[9] << "-------------" << endl;
  209.     total_day = 31;
  210.     day();
  211.     starting_day = date(starting_day, total_day, month[9]);
  212.     cout << "------------" << month[10] << "-------------" << endl;
  213.     total_day = 30;
  214.     day();
  215.     starting_day = date(starting_day, total_day, month[10]);
  216.     cout << "------------" << month[11] << "-------------" << endl;
  217.     total_day = 31;
  218.     day();
  219.     starting_day = date(starting_day, total_day, month[11]);
  220.  
  221. }
  222. void update(struct node*p) {
  223.     string a, b;
  224.     int c;
  225.     cout << "a.Reminder title" << endl;
  226.     getline(cin, a);
  227.     cout << "c.Date" << endl;
  228.     cin >> c;
  229.     cin.ignore();
  230.     cout << "d.Month" << endl;
  231.     cin >> b;
  232.     while (p != NULL) {
  233.         if (p->title == a && p->date == c && p->month == b) {
  234.             cout << "Update your reminder: " << endl;
  235.             cout << "a.Reminder title" << endl;
  236.             cin.ignore();
  237.             getline(cin, p->title);
  238.             cout << "b.Date" << endl;
  239.             cin >> p->date;
  240.             cin. ignore();
  241.             cout << "c.Reminder description" << endl;
  242.             getline(cin,p->description);
  243.             cout << "d.Month" << endl;
  244.             cin >> p->month;
  245.             return;
  246.         }
  247.         else {
  248.             p = p->next;
  249.         }
  250.     }
  251.  
  252. }
  253. void delete1(struct node*p) {
  254.     string a, b;
  255.     int c;
  256.     cout << "a.Reminder title" << endl;
  257.     getline(cin, a);
  258.     cout << "c.Date" << endl;
  259.     cin >> c;
  260.     cin.ignore();
  261.     cout << "d.Month" << endl;
  262.     cin >> b;
  263.     node* q = NULL;
  264.     int index = 1;
  265.     while (p != NULL) {
  266.         if (p->title == a && p->date == c && p->month == b) {
  267.             break;
  268.         }
  269.         else {
  270.             index++;
  271.             p = p->next;
  272.         }
  273.     }
  274.     p = first;
  275.     while (p != NULL) {
  276.             if (index==1) {
  277.                 q = first;
  278.                 first = first->next;
  279.                 delete q;
  280.                 return;
  281.             }
  282.             else {
  283.                 for (int i = 0; i < index-1; i++) {
  284.                     q = p;
  285.                     p = p->next;
  286.                 }
  287.                 q->next = p->next;
  288.                 delete p;
  289.                 return;
  290.             }
  291.     }
  292. }
  293. void reminders_of_a_specific_month() {
  294.     string x;
  295.     cout << "Enter the month name: " << endl;
  296.     cin >> x;
  297.     struct node* p = first;
  298.     while (p != NULL) {
  299.         if (p->month == x) {
  300.             cout << "a.Reminder title:" << endl;
  301.             cout << p->title << endl;
  302.             cout << "b.Reminder description:" << endl;
  303.             cout << p->description << endl;
  304.             cout << "c.Date" << endl;
  305.             cout << p->date << endl;
  306.             cout << "d.Month" << endl;
  307.             cout << p->month << endl;
  308.         }
  309.         p = p->next;
  310.     }
  311. }
  312. int main() {
  313.     int year;
  314.     string a;
  315.     cout << "Input:" << endl;
  316.     cout << "Year: ";
  317.     cin >> year;
  318.     cout << "Starting day of the year : ";
  319.     cin >> a;
  320.     string mon[12];
  321.     month(mon, 12);
  322.     calendar(a,year,mon,12);
  323.     for (int i = 1; ; i++) {
  324.         cout << "You can perform the following operation: " << endl;
  325.         cout << "Press 1 if you want to add reminder" << endl;
  326.         cout << "Press 2 if you want to update reminder" << endl;
  327.         cout << "Press 3 if you want to delete a specific reminder" << endl;
  328.         cout << "Press 4 if you want to view all the reminders of a specific month" << endl;
  329.         cout << "Press 5 if you want to exit from the calendar" << endl;
  330.         int b;
  331.         cin >> b;
  332.         cin.ignore();
  333.         if (b == 1) {
  334.             insert();
  335.             calendar(a, year, mon, 12);
  336.         }
  337.         else if (b == 2) {
  338.             update(first);
  339.             calendar(a, year, mon, 12);
  340.         }
  341.         else if (b == 3) {
  342.             delete1(first);
  343.             calendar(a, year, mon, 12);
  344.         }
  345.         else if (b == 4) {
  346.             reminders_of_a_specific_month();
  347.         }
  348.         else if (b == 5) {
  349.             return 0;
  350.         }
  351.     }
  352. }
  353.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement