SHARE
TWEET

intMain(4)

a guest Oct 23rd, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <ctime>
  4. #include <cstring>
  5. #include <stdlib.h> //for exit() function
  6. #include <fstream>  //for creating text file
  7. using namespace std;
  8.  
  9. int total = 0;
  10. int bookingNo = 0;
  11.  
  12. class Reservation{
  13. private:
  14.   int bookingNo;
  15.   string name;
  16.   int phoneNo;
  17.   int paxNo;
  18.   int day;
  19.   int month;
  20.   int year;
  21.   int time;
  22.   int date;
  23.   long dateAndTime;
  24. public:
  25.   Reservation(){
  26.     bookingNo = 1;
  27.     name = "Tan Phit Huan";
  28.     phoneNo = 0123456777;
  29.     paxNo = 1;
  30.     day = 1;
  31.     month = 1;
  32.     year = 2019;
  33.     time = 1500;
  34.     date = 20190101;
  35.     dateAndTime = 201910201649;
  36.   }
  37.   Reservation(int bNo, string na, int phNo, int pxNo, int d, int mon, int y, int t,int da, long dNt){
  38.     bookingNo = bNo;
  39.     name = na;
  40.     phoneNo = phNo;
  41.     paxNo = pxNo;
  42.     day = d;
  43.     month = mon;
  44.     year = y;
  45.     time = t;
  46.     date = da;
  47.     dateAndTime =dNt;
  48.   }
  49.   void setBookingNo(int bNo){
  50.     bookingNo = bNo;
  51.   }
  52.   int getBookingNo(){
  53.     return bookingNo;
  54.   }
  55.   void setName(string na){
  56.     name = na;
  57.   }
  58.   string getName(){
  59.     return name;
  60.   }
  61.   void setPhoneNo(int phNo){
  62.     phoneNo = phNo;
  63.   }
  64.   int getPhoneNo(){
  65.     return phoneNo;
  66.   }
  67.   void setPaxNo(int pxNo){
  68.     paxNo = pxNo;
  69.   }
  70.   int getPaxNo(){
  71.     return paxNo;
  72.   }
  73.   void setDay(int d){
  74.     day = d;
  75.   }
  76.   int getDay(){
  77.     return day;
  78.   }
  79.   void setMonth(int m){
  80.     month = m;
  81.   }
  82.   int getMonth(){
  83.     return month;
  84.   }
  85.   void setYear(int y){
  86.       year = y;
  87.   }
  88.   int getYear(){
  89.     return year;
  90.   }
  91.   void setTime(int t){
  92.     time = t;
  93.   }
  94.   int getTime(){
  95.     return time;
  96.   }
  97.   void setDate(int da){
  98.     date = da;
  99.   }
  100.   int getDate(){
  101.     return date;
  102.   }
  103.   void setDateAndTime(long dNt){
  104.     dateAndTime = dNt;
  105.   }
  106.   long getDateAndTime(){
  107.     return dateAndTime;
  108.   }
  109. };
  110.  
  111. class linklist{
  112. private:
  113.   struct node{
  114.     Reservation info;
  115.     node *link;
  116.   }*head;
  117.  
  118. public:
  119.   linklist(){
  120.     head=NULL;
  121.   }
  122.  
  123.   void InsNewNode(int bNo, string na, int phNo, int pxNo, int d, int mon, int y, int t, long dNt){
  124.     node*newNode = new node;
  125.     node*p,*q = head;
  126.     newNode -> info.setBookingNo(bNo);
  127.     newNode -> info.setName(na);
  128.     newNode -> info.setPhoneNo(phNo);
  129.     newNode -> info.setPaxNo(pxNo);
  130.     newNode -> info.setDay(d);
  131.     newNode -> info.setMonth(mon);
  132.     newNode -> info.setYear(y);
  133.     newNode -> info.setTime(t);
  134.     newNode -> info.setDateAndTime(dNt);
  135.  
  136.     //If no records
  137.     if (head == NULL){
  138.       head = newNode;
  139.       return;
  140.     }
  141.  
  142.     //Insert at the start of list
  143.     if (head -> info.getDateAndTime() > newNode -> info.getDateAndTime()){
  144.       newNode -> link = head;
  145.       head = newNode;
  146.       return;
  147.     }
  148.  
  149.     while(q->info.getDateAndTime() < newNode -> info.getDateAndTime() && q->link != NULL){
  150.       p = q;
  151.       q = q->link;
  152.     }
  153.     //Insert at the end of the list
  154.     if(q == NULL){
  155.       q = newNode;
  156.       newNode-> link = NULL;
  157.       return;
  158.     //Insert in the middle of the list
  159.     }else{
  160.       p = q;
  161.       q = q->link;
  162.       p->link = newNode;
  163.       newNode-> link = q;
  164.       return;
  165.     }
  166.   }
  167.  
  168.   void deleteNode(int bNo){
  169.     node *current;
  170.     current = head;
  171.     while (current != NULL){
  172.       if(bNo == current->info.getBookingNo()){
  173.         if(current == head){
  174.           node*temp = head;
  175.           head = head -> link;
  176.           delete temp;
  177.  
  178.         }else if(current->link == NULL){
  179.           node*p, *q = head;
  180.           while(q -> link != NULL){
  181.             p = q;
  182.             q = q -> link;
  183.           }
  184.           p->link = NULL;
  185.           delete q;
  186.  
  187.         }else{
  188.           node*p, *q = head;
  189.           while(q -> info.getBookingNo() != bNo){
  190.             p = q;
  191.             q = q -> link;
  192.           }
  193.           p -> link = q ->link;
  194.           delete q;
  195.         }
  196.       }
  197.       current = current->link;
  198.     }
  199.     total--;
  200.   }
  201.  
  202.   void PrintList(){
  203.     node *current;
  204.     current = head;
  205.     cout<<setfill(' ')<<setw(5)<<"| No. "
  206.     <<left<<setw(30)<<"Name"
  207.     <<setw(5)<<"Phone No."
  208.     <<right<<setw(16)<<"Pax No."
  209.     <<setw(10)<<"Date"
  210.     <<setw(16)<<"Time |"<<endl
  211.     <<"|"<<right<<setfill('=')<<setw(86)<<"|"<<endl;
  212.  
  213.     while (current != NULL){
  214.       cout<<"| "<<setfill(' ')<<current->info.getBookingNo()<<"   "
  215.       <<left<<setw(30)<< current->info.getName()
  216.       <<right<<setw(10)<<setfill('0')<< current->info.getPhoneNo()
  217.       <<setw(12)<<setfill(' ')<< current->info.getPaxNo()<<setw(6)<<setfill(' ')<<" "
  218.       <<setw(2)<<setfill('0')<< current->info.getDay() <<"/"<<setw(2)<<setfill('0')<< current->info.getMonth() <<"/"<<setw(4)<<setfill('0')<< current->info.getYear()<<setw(7)<<setfill(' ')<<" "
  219.       <<setw(4)<<setfill('0')<< current->info.getTime() <<" |"<<endl;
  220.       current = current->link;
  221.     }
  222.     cout<<endl;
  223.   }
  224.  
  225.   void PrintBookingNoRecords(int bNo){
  226.     node *current;
  227.     current = head;
  228.     cout<<setfill(' ')<<setw(5)<<"| No. "
  229.     <<left<<setw(30)<<"Name"
  230.     <<setw(5)<<"Phone No."
  231.     <<right<<setw(16)<<"Pax No."
  232.     <<setw(10)<<"Date"
  233.     <<setw(16)<<"Time |"<<endl
  234.     <<"|"<<right<<setfill('=')<<setw(86)<<"|"<<endl;
  235.  
  236.     while (current != NULL){
  237.       //If there is any reservation with the same name
  238.       if(bNo == current->info.getBookingNo()){
  239.         cout<<"| "<<setfill(' ')<<current->info.getBookingNo()<<"   "
  240.         <<left<<setw(30)<< current->info.getName()
  241.         <<right<<setw(10)<<setfill('0')<< current->info.getPhoneNo()
  242.         <<setw(12)<<setfill(' ')<< current->info.getPaxNo()<<setw(6)<<setfill(' ')<<" "
  243.         <<setw(2)<<setfill('0')<< current->info.getDay() <<"/"<<setw(2)<<setfill('0')<< current->info.getMonth() <<"/"<<setw(4)<<setfill('0')<< current->info.getYear()<<setw(7)<<setfill(' ')<<" "
  244.         <<setw(4)<<setfill('0')<< current->info.getTime() <<" |"<<endl;
  245.       }
  246.       current = current->link;
  247.     }
  248.     cout<<endl;
  249.   }
  250.  
  251.   void PrintNameRecords(string name){
  252.     node *current;
  253.     current = head;
  254.     cout<<setfill(' ')<<setw(5)<<"| No. "
  255.     <<left<<setw(30)<<"Name"
  256.     <<setw(5)<<"Phone No."
  257.     <<right<<setw(16)<<"Pax No."
  258.     <<setw(10)<<"Date"
  259.     <<setw(16)<<"Time |"<<endl
  260.     <<"|"<<right<<setfill('=')<<setw(86)<<"|"<<endl;
  261.  
  262.     while (current != NULL){
  263.       //If there is any reservation with the same name
  264.       if(name == current->info.getName()){
  265.         cout<<"| "<<setfill(' ')<<current->info.getBookingNo()<<"   "
  266.         <<left<<setw(30)<< current->info.getName()
  267.         <<right<<setw(10)<<setfill('0')<< current->info.getPhoneNo()
  268.         <<setw(12)<<setfill(' ')<< current->info.getPaxNo()<<setw(6)<<setfill(' ')<<" "
  269.         <<setw(2)<<setfill('0')<< current->info.getDay() <<"/"<<setw(2)<<setfill('0')<< current->info.getMonth() <<"/"<<setw(4)<<setfill('0')<< current->info.getYear()<<setw(7)<<setfill(' ')<<" "
  270.         <<setw(4)<<setfill('0')<< current->info.getTime() <<" |"<<endl;
  271.       }
  272.       current = current->link;
  273.     }
  274.     cout<<endl;
  275.   }
  276.  
  277.   void PrintDateRecords(int date){
  278.     node *current;
  279.     current = head;
  280.     cout<<setfill(' ')<<setw(5)<<"| No. "
  281.     <<left<<setw(30)<<"Name"
  282.     <<setw(5)<<"Phone No."
  283.     <<right<<setw(16)<<"Pax No."
  284.     <<setw(10)<<"Date"
  285.     <<setw(16)<<"Time |"<<endl
  286.     <<"|"<<right<<setfill('=')<<setw(86)<<"|"<<endl;
  287.  
  288.     while (current != NULL){
  289.       //If there is any reservation with the same date
  290.       if(date == current->info.getDate()){
  291.         cout<<"| "<<setfill(' ')<<current->info.getBookingNo()<<"   "
  292.         <<left<<setw(30)<< current->info.getName()
  293.         <<right<<setw(10)<<setfill('0')<< current->info.getPhoneNo()
  294.         <<setw(12)<<setfill(' ')<< current->info.getPaxNo()<<setw(6)<<setfill(' ')<<" "
  295.         <<setw(2)<<setfill('0')<< current->info.getDay() <<"/"<<setw(2)<<setfill('0')<< current->info.getMonth() <<"/"<<setw(4)<<setfill('0')<< current->info.getYear()<<setw(7)<<setfill(' ')<<" "
  296.         <<setw(4)<<setfill('0')<< current->info.getTime() <<" |"<<endl;
  297.       }
  298.       current = current->link;
  299.     }
  300.     cout<<endl;
  301.   }
  302.  
  303.   void PrintListTextFile(){
  304.     string fileName;
  305.     int count = 0;
  306.     cout << "---------------=CREATE TEXT FILE=---------------" << endl;
  307.     //Create file with the file name user entered
  308.     cout << "Enter file name: ";
  309.     cin >> fileName;
  310.     cout << "Your .txt file can be found in the same folder where your .cpp file is saved." << endl;
  311.     fileName = fileName + ".txt";
  312.  
  313.     //output to .txt file
  314.     ofstream file(fileName.c_str());
  315.  
  316.     if (file.is_open()) {
  317.       //output all the reservation records
  318.       node *current;
  319.       current = head;
  320.       file<<setfill(' ')<<setw(5)<<"| No. "
  321.       <<left<<setw(30)<<"Name"
  322.       <<setw(5)<<"Phone No."
  323.       <<right<<setw(16)<<"Pax No."
  324.       <<setw(10)<<"Date"
  325.       <<setw(16)<<"Time |"<<endl
  326.       <<"|"<<right<<setfill('=')<<setw(86)<<"|"<<endl;
  327.  
  328.       while (current != NULL){
  329.         count++;
  330.         file<<"| "<<setfill(' ')<<count<<"   "
  331.         <<left<<setw(30)<< current->info.getName()
  332.         <<right<<setw(10)<<setfill('0')<< current->info.getPhoneNo()
  333.         <<setw(12)<<setfill(' ')<< current->info.getPaxNo()<<setw(6)<<setfill(' ')<<" "
  334.         <<setw(2)<<setfill('0')<< current->info.getDay() <<"/"<<setw(2)<<setfill('0')<< current->info.getMonth() <<"/"<<setw(4)<<setfill('0')<< current->info.getYear()<<setw(7)<<setfill(' ')<<" "
  335.         <<setw(4)<<setfill('0')<< current->info.getTime() <<" |"<<endl;
  336.         current = current->link;
  337.       }
  338.       file.close(); //close file
  339.     }        
  340.   }
  341.  
  342.   bool checker(int bNo){
  343.     node *current;
  344.     current = head;
  345.     while(current != NULL){
  346.       if(bNo == current->info.getBookingNo()){
  347.         return true;
  348.       }
  349.       current = current->link;
  350.     }
  351.     return false;
  352.   }
  353. };
  354.  
  355. linklist RList;
  356. void addRecord();
  357. void updateRecord();
  358. void deleteRecord();
  359. void viewRecord();
  360. void createTextFile();
  361. bool checkYear();
  362. bool checkMonth();
  363.  
  364.  
  365. int main() {
  366.   char choice;
  367.   cout << "===============RESTAURANT RESERVATION SYSTEM===============" << endl;
  368.   cout << "Please enter your selection" << endl <<
  369.     "1. Add Reservation Records" << endl <<
  370.     "2. Update Reservation Records" << endl <<
  371.     "3. Delete Reservation Records" << endl <<
  372.     "4. View Reservation Records  " << endl <<
  373.     "5. Create text file" << endl <<
  374.     "6. Exit" << endl;
  375.  
  376.   cout << "Choice: ";
  377.   cin >> choice;
  378.   cin.clear();
  379.   cin.ignore(1, '\n');
  380.   system("CLS");
  381.  
  382.   switch (choice) {
  383.   //Add Records
  384.   case '1':
  385.     addRecord();
  386.     break;
  387.  
  388.   //Update Records
  389.   case '2':
  390.     if (total == 0) {
  391.       cout << "No reservation records available." << endl;
  392.       main();
  393.     }
  394.     updateRecord();
  395.  
  396.     break;
  397.  
  398.   //Delete Records
  399.   case '3':
  400.     if (total == 0) {
  401.       cout << "No reservation records available." << endl;
  402.       main();
  403.     }
  404.     deleteRecord();
  405.  
  406.     break;
  407.  
  408.   //View Reservation Records
  409.   case '4':
  410.     if (total == 0) {
  411.       cout << "No reservation records available." << endl;
  412.       main();
  413.     }
  414.     viewRecord();
  415.     break;
  416.  
  417.   //Create Text File
  418.   case '5':
  419.     if (total == 0) {
  420.       cout << "No reservation records available." << endl;
  421.       main();
  422.     }
  423.     createTextFile();
  424.     break;
  425.  
  426.   case '6':
  427.     exit(1);
  428.     break;
  429.  
  430.   default:
  431.     cout << choice << " is not valid choice" << endl;
  432.     main();
  433.   }
  434.  
  435.   return 0;
  436. }
  437.  
  438. bool checkName(string name);
  439. bool checkYear(int year);
  440. bool checkMonth(int month, int year);
  441. bool checkDay(int day, int month, int year);
  442. bool checkTime(int time, int day, int month, int year);
  443.  
  444. //OPTION 1 : Add Reservation Records
  445. void addRecord(){
  446.   string name;
  447.   int phoneNo, paxNo, day, month, year, time;
  448.   long dateAndTime;
  449.   int length;
  450.   int correct = 1;
  451.   cout << "-----------------=ADD RECORD=-------------------" << endl;
  452.  
  453.   do{
  454.     cout<<"Enter name : ";
  455.     getline(cin, name);
  456.   }while(!checkName(name));
  457.  
  458.   cout<<endl<<"Enter phone number (e.g : 0123456789) : ";
  459.   cin>>phoneNo;
  460.  
  461.   correct = 1;
  462.   while (correct == 1){
  463.     length = to_string(phoneNo).length();
  464.     if (cin.fail() || phoneNo<0 || length>11){
  465.       cin.clear();
  466.       cin.ignore();
  467.       cout << "Invalid input! Enter positive numbers (maximum 11 digits)!" << endl<<endl;
  468.       cout<< "Enter phone number (e.g : 0123456789) : ";
  469.       cin >> phoneNo;
  470.     }else{
  471.         correct = 0;
  472.     }
  473.   }
  474.  
  475.   correct = 1;
  476.   cout<<endl<<"Enter number of pax (maximum : 50) : ";
  477.   cin>>paxNo;
  478.  
  479.   while (correct == 1){
  480.     if (cin.fail() || paxNo<0 || paxNo > 50){
  481.       cin.clear();
  482.       cin.ignore();
  483.       cout << "Invalid input! Enter positive numbers (maximum : 50)!" << endl<<endl;
  484.       cout<< "Enter number of pax (maximum : 50) : ";
  485.       cin >> paxNo;
  486.     }else{
  487.         correct = 0;
  488.     }
  489.   }
  490.  
  491.   correct = 1;
  492.   do{
  493.     cout<<endl<<"Enter year (e.g : 2019): ";
  494.     cin>>year;
  495.     while (correct == 1){
  496.       if (cin.fail() || year > 2021){
  497.         cin.clear();
  498.         cin.ignore();
  499.         cout << "Invalid input! Enter numbers (maximum year is 2021)!" << endl<<endl;
  500.         cout<< "Enter year (e.g : 2019) : ";
  501.         cin >> year;
  502.       }else{
  503.           correct = 0;
  504.       }
  505.     }
  506.   }while(!checkYear(year));
  507.  
  508.   correct = 1;
  509.   do{
  510.     cout<<endl<<"Enter month (e.g : January = 1) : ";
  511.     cin>>month;
  512.     while (correct == 1){
  513.       if (cin.fail()){
  514.         cin.clear();
  515.         cin.ignore();
  516.         cout << "Invalid input! Enter numbers!" << endl<<endl;
  517.         cout<< "Enter month (e.g : January = 1) : ";
  518.         cin >> month;
  519.       }else{
  520.           correct = 0;
  521.       }
  522.     }
  523.   }while(!checkMonth(month, year));
  524.  
  525.   correct = 1;
  526.   do{
  527.     cout<<endl<<"Enter day : ";
  528.     cin>>day;
  529.     while (correct == 1){
  530.       if (cin.fail()){
  531.         cin.clear();
  532.         cin.ignore();
  533.         cout << "Invalid input! Enter numbers!" << endl<<endl;
  534.         cout<< "Enter day : ";
  535.         cin >> day;
  536.       }else{
  537.           correct = 0;
  538.       }
  539.     }
  540.   }while(!checkDay(day, month, year));
  541.  
  542.   do{
  543.     cout<<endl<<"Enter time in 24hr format (e.g : 3.30pm = 1530) : ";
  544.     cin>>time;
  545.     while (correct == 1){
  546.       if (cin.fail()){
  547.         cin.clear();
  548.         cin.ignore();
  549.         cout << "Invalid input! Enter positive numbers (maximum 4 digits)!" << endl<<endl;
  550.         cout<< "Enter time in 24hr format (e.g : 3.30pm = 1530) : ";
  551.         cin >> time;
  552.       }else{
  553.           correct = 0;
  554.       }
  555.     }
  556.   }while(!checkTime(time, day, month, year));
  557.  
  558.   bookingNo++;
  559.   cout<<endl<<"Booking Number : "<<bookingNo<<endl;
  560.  
  561.   //for inserting the node in order according to date and time
  562.   dateAndTime = year*100000000 + month*1000000 + day*10000 + time;
  563.  
  564.   RList.InsNewNode(bookingNo, name, phoneNo, paxNo, day, month, year, time, dateAndTime);
  565.   total++;
  566.   cin.clear();
  567.   cin.ignore(1000, '\n');
  568.   cout << "Press enter to continue . . .";
  569.   getchar();
  570.   system("CLS");
  571.   main();
  572. }
  573.  
  574. //OPTION 2 : Update Reservation Records
  575. void updateRecord(){
  576.   string name;
  577.   int bNo, phoneNo, paxNo, day, month, year, time;
  578.   long dateAndTime;
  579.   int length;
  580.   int correct = 1;
  581.   cout << "----------------=UPDATE RECORD=-----------------" << endl;
  582.   cout << "Enter Booking Number : ";
  583.   cin >> bNo;
  584.  
  585.   if(RList.checker(bNo)){
  586.     cin.clear();
  587.     cin.ignore(1000, '\n');
  588.     cout<<"Enter name : ";
  589.     getline(cin, name);
  590.  
  591.     cout<<endl<<"Enter phone number (e.g : 0123456789) : ";
  592.     cin>>phoneNo;
  593.  
  594.     correct = 1;
  595.     while (correct == 1){
  596.       length = to_string(phoneNo).length();
  597.       if (cin.fail() || phoneNo<0 || length>11){
  598.         cin.clear();
  599.         cin.ignore();
  600.         cout << "Invalid input! Enter positive numbers (maximum 11 digits)!" << endl<<endl;
  601.         cout<< "Enter phone number (e.g : 0123456789) : ";
  602.         cin >> phoneNo;
  603.       }else{
  604.           correct = 0;
  605.       }
  606.     }
  607.  
  608.     correct = 1;
  609.     cout<<endl<<"Enter number of pax (maximum : 50) : ";
  610.     cin>>paxNo;
  611.  
  612.     while (correct == 1){
  613.       if (cin.fail() || paxNo<0 || paxNo > 50){
  614.         cin.clear();
  615.         cin.ignore();
  616.         cout << "Invalid input! Enter positive numbers (maximum : 50)!" << endl<<endl;
  617.         cout<< "Enter number of pax (maximum : 50) : ";
  618.         cin >> paxNo;
  619.       }else{
  620.           correct = 0;
  621.       }
  622.     }
  623.  
  624.     correct = 1;
  625.     do{
  626.       cout<<endl<<"Enter year (e.g : 2019): ";
  627.       cin>>year;
  628.       while (correct == 1){
  629.         if (cin.fail() || year > 2021){
  630.           cin.clear();
  631.           cin.ignore();
  632.           cout << "Invalid input! Enter numbers (maximum year is 2021)!" << endl<<endl;
  633.           cout<< "Enter year (e.g : 2019) : ";
  634.           cin >> year;
  635.         }else{
  636.             correct = 0;
  637.         }
  638.       }
  639.     }while(!checkYear(year));
  640.  
  641.     correct = 1;
  642.     do{
  643.       cout<<endl<<"Enter month (e.g : January = 1) : ";
  644.       cin>>month;
  645.       while (correct == 1){
  646.         if (cin.fail()){
  647.           cin.clear();
  648.           cin.ignore();
  649.           cout << "Invalid input! Enter numbers!" << endl<<endl;
  650.           cout<< "Enter month (e.g : January = 1) : ";
  651.           cin >> month;
  652.         }else{
  653.             correct = 0;
  654.         }
  655.       }
  656.     }while(!checkMonth(month, year));
  657.  
  658.     correct = 1;
  659.     do{
  660.       cout<<endl<<"Enter day : ";
  661.       cin>>day;
  662.       while (correct == 1){
  663.         if (cin.fail()){
  664.           cin.clear();
  665.           cin.ignore();
  666.           cout << "Invalid input! Enter numbers!" << endl<<endl;
  667.           cout<< "Enter day : ";
  668.           cin >> day;
  669.         }else{
  670.             correct = 0;
  671.         }
  672.       }
  673.     }while(!checkDay(day, month, year));
  674.  
  675.     do{
  676.       cout<<endl<<"Enter time in 24hr format (e.g : 3.30pm = 1530) : ";
  677.       cin>>time;
  678.       while (correct == 1){
  679.         if (cin.fail()){
  680.           cin.clear();
  681.           cin.ignore();
  682.           cout << "Invalid input! Enter positive numbers (maximum 4 digits)!" << endl<<endl;
  683.           cout<< "Enter time in 24hr format (e.g : 3.30pm = 1530) : ";
  684.           cin >> time;
  685.         }else{
  686.             correct = 0;
  687.         }
  688.       }
  689.     }while(!checkTime(time, day, month, year));
  690.     //for inserting the node in order
  691.     dateAndTime = year*100000000 + month*1000000 + day*10000 + time;
  692.  
  693.     RList.InsNewNode(bNo, name, phoneNo, paxNo, day, month, year, time, dateAndTime);
  694.     cout<<"Update process complete."<<endl;
  695.   }else{
  696.     cout<<"No existing record with that booking number."<<endl
  697.     <<"Update process cancelled."<<endl;
  698.   }
  699.  
  700.   cin.clear();
  701.   cin.ignore(1000, '\n');
  702.   cout << "Press enter to continue . . .";
  703.   getchar();
  704.   system("CLS");
  705.   main();
  706. }
  707.  
  708. //OPTION 3 : Delete Reservation Records
  709. void deleteRecord(){
  710.   int  bNo;
  711.   char confirm;
  712.   cout << "----------------=DELETE RECORD=-----------------" << endl;
  713.     cout<<"Enter Booking Number : ";
  714.     cin>>bNo;
  715.     if(RList.checker(bNo)){
  716.       RList.PrintBookingNoRecords(bNo);
  717.       cout<<"Confirm?(y/n) : ";
  718.       cin>>confirm;
  719.  
  720.       switch (confirm) {
  721.         case 'y':
  722.           RList.deleteNode(bNo);
  723.           cout<<"Deletion process complete."<<endl;
  724.           break;
  725.         default:
  726.           cout<<"Deletion process cancelled."<<endl;
  727.           main();
  728.       }
  729.     }else{
  730.       cout<<"No existing record with that booking number."<<endl;
  731.     }
  732.  
  733.   cin.clear();
  734.   cin.ignore(1000, '\n');
  735.   cout << "Press enter to continue . . .";
  736.   getchar();
  737.   system("CLS");
  738.   main();
  739. }
  740.  
  741. //OPTION 4 : View Reservation Records
  742. void viewRecord(){
  743.   char choice;
  744.   string name;
  745.   int bNo, year, month, day, date;
  746.   cout << "-----------------=VIEW RECORD=------------------" << endl;
  747.   cout << "Please enter your selection" << endl <<
  748.   "1. View All Reservations" << endl <<
  749.   "2. Search by Booking Number"<< endl <<
  750.   "3. Search by Name" << endl<<
  751.   "4. Search by Date"<< endl <<
  752.   "5. Back to Main Menu"<< endl;
  753.   cout << "Choice: ";
  754.   cin >> choice;
  755.   cin.clear();
  756.   cin.ignore(1, '\n');
  757.   system("CLS");
  758.  
  759.   switch (choice) {
  760.   //View All Reservations
  761.   case '1':
  762.     RList.PrintList();
  763.     break;
  764.  
  765.   case '2':
  766.     cout<<"Enter Booking Number : ";
  767.     cin>>bNo;
  768.     RList.PrintBookingNoRecords(bNo);
  769.     break;
  770.  
  771.   //Search by Name
  772.   case '3':
  773.     cout<<"Enter Name : ";
  774.     getline(cin, name);
  775.  
  776.     RList.PrintNameRecords(name);
  777.     break;
  778.  
  779.   case '4':
  780.     cout<<"Enter year (e.g : 2019) : ";
  781.     cin>>year;
  782.  
  783.     cout<<"Enter month (e.g : January = 1) : ";
  784.     cin>>month;
  785.  
  786.     cout<<"Enter day : ";
  787.     cin>>day;
  788.  
  789.     date = year*10000 + month*100 + day;
  790.  
  791.     RList.PrintDateRecords(date);
  792.     break;
  793.  
  794.   case '5':
  795.     main();
  796.     break;
  797.  
  798.   default:
  799.     cout << choice << " is not valid choice" << endl;
  800.     viewRecord();
  801.   }
  802.  
  803.   cout << "Press enter to continue . . .";
  804.   getchar();
  805.   system("CLS");
  806.   main();
  807. }
  808.  
  809. //OPTION 5 : Create Text File
  810. void createTextFile(){
  811.   RList.PrintListTextFile();
  812.   getchar();
  813.   cout << "-----------------------------------------------------" << endl;
  814.  
  815.   cout << "Press enter to continue . . .";
  816.   cin.clear();
  817.   cin.ignore(1000, '\n');
  818.   system("CLS");
  819.   main();
  820. }
  821.  
  822. //for checking whether the name is empty
  823. bool checkName(string name){
  824.   int counter = 0;
  825.   for(int i = 0; i<name.length() ; i++){
  826.     if(name.find_first_not_of(' ') != std::string::npos){
  827.       counter++;
  828.     }
  829.   }
  830.  
  831.   if(counter == 0){
  832.     cout<<"Invalid Input! Need a name!"<<endl;
  833.     return false;
  834.   }else{
  835.     return true;
  836.   }
  837. }
  838.  
  839. //for getting the current time
  840. time_t now = time(0);
  841. tm *ltm = localtime(&now);
  842.  
  843. int currentYear = 1900+ltm->tm_year;
  844. int currentMonth = 1 + ltm->tm_mon;
  845. int currentDay = ltm->tm_mday;
  846. int currentHour = ltm->tm_hour;
  847. int currentMinute = ltm->tm_min;
  848.  
  849. bool checkYear(int year){
  850.   if(year < currentYear){
  851.     cout<<"Can't go back in time!"<<endl;
  852.     return false;
  853.   }else{
  854.     return true;
  855.   }
  856. }
  857.  
  858. bool checkMonth(int month, int year){
  859.   if(month < currentMonth && year == currentYear){
  860.     cout<<"Can't go back in time!"<<endl;
  861.     return false;
  862.   }else if(month > 12){
  863.     cout<<"There are only 12 months in a year!"<<endl;
  864.     return false;
  865.   }else{
  866.     return true;
  867.   }
  868. }
  869.  
  870. bool checkDay(int day, int month, int year){
  871.   if(day < currentDay && month == currentMonth && year == currentYear){
  872.     cout<<"Can't go back in time!"<<endl;
  873.   //even months
  874.   }else if(day <= 0){
  875.     cout<<"Can't go back in time!"<<endl;
  876.   }else if(month%2 == 0){
  877.     // if the month is february
  878.     if(month == 2){
  879.       //february in common year that contain 28 days
  880.       if(year%4 != 0 && day>28){
  881.         cout << "Please key in between the day from 1 to 28"<< endl;
  882.       }
  883.       // february in leap year that contain 29 days
  884.       else if(year%4 == 0 && day>29){
  885.         cout << "Please key in between the day from 1 to 29"<< endl;
  886.       }
  887.       else{
  888.         return true;
  889.       }
  890.     }
  891.     // month that are even with 31 days
  892.     else if(month > 7 && day > 31){
  893.       cout << "Please key in between the day from 1 to 31"<< endl;
  894.     }
  895.     // month that are even  with 30 days
  896.     else if(month < 7 && day > 30){
  897.       cout << "Please key in between the day from 1 to 30"<< endl;
  898.     }
  899.     else{
  900.       return true;
  901.     }
  902.  
  903.   // month is odd
  904.   }else if(month%2 != 0){
  905.     // month that are odd with 30 days
  906.     if(month>8 && day > 30){
  907.       cout << "Please key in between the day from 1 to 30"<< endl;
  908.     // month that are odd with 31 days
  909.     }else if(month<8 && day > 31){
  910.       cout << "Please key in between the day from 1 to 31"<< endl;
  911.     }else{
  912.       return true;
  913.     }
  914.   }
  915.   else{
  916.     return true;
  917.   }
  918.   return false;
  919. }
  920.  
  921. bool checkTime(int time, int day, int month, int year){
  922.   int hour = time/100;
  923.   int minute = time - hour*100;
  924.  
  925.   if(hour > 24){
  926.     cout<<"Only 0 to 24 hours."<<endl;
  927.     return false;
  928.   }else if(hour < currentHour && day == currentDay && month == currentMonth && year == currentYear){
  929.     cout<<"Can't go back in time!"<<endl;
  930.     return false;
  931.   }else{
  932.     return true;
  933.   }
  934.  
  935.   if(minute > 59){
  936.     cout<<"Only 0 to 59 minutes."<<endl;
  937.   }else if(minute < currentMinute && hour == currentHour && day == currentDay && month == currentMonth && year == currentYear){
  938.     cout<<"Can't go back in time!"<<endl;
  939.   }else{
  940.     return true;
  941.   }
  942.   return false;
  943. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top