Advertisement
tiffprag

Update Function

Oct 25th, 2019
482
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.07 KB | None | 0 0
  1. //OPTION 2 : Update Reservation Records
  2. void updateRecord(){
  3.   string name;
  4.   int bNo, phoneNo, paxNo, day, month, year, time, date;
  5.   int correct = 1;
  6.   cout << "----------------=UPDATE RECORD=-----------------" << endl;
  7.   cout<<"Enter 0 to return to main menu."<<endl;
  8.   cout << "Enter Booking Number : ";
  9.   cin >> bNo;
  10.   if(bNo == 0){
  11.     cout << "Press enter to continue . . .";
  12.     getchar();
  13.     system("CLS");
  14.     main();
  15.   }
  16.  
  17.   if(RBList.checker(bNo)){
  18.     RBList.PrintBookingNoRecords(bNo);
  19.     RBList.deleteNode(bNo);
  20.     cin.clear();
  21.     cin.ignore(1000, '\n');
  22.  
  23.     do{
  24.       cout<<"Enter name : ";
  25.       getline(cin, name);
  26.     }while(!checkName(name));
  27.  
  28.     if(name=="0"){
  29.       cout << "Press enter to continue . . .";
  30.       getchar();
  31.       system("CLS");
  32.       main();
  33.     }
  34.  
  35.     cout<<endl<<"Enter phone number (e.g : 0123456789) : ";
  36.     cin>>phoneNo;
  37.  
  38.     correct = 1;
  39.     while (correct == 1){
  40.       if (cin.fail() || phoneNo<0 || checkNoOfDigits(phoneNo)>10){
  41.         cin.clear();
  42.         cin.ignore();
  43.         cout << "Invalid input! Enter positive numbers (maximum 11 digits)!" << endl<<endl;
  44.         cout<< "Enter phone number (e.g : 0123456789) : ";
  45.         cin >> phoneNo;
  46.       }else{
  47.         correct = 0;
  48.       }
  49.     }
  50.  
  51.     correct = 1;
  52.     cout<<endl<<"Enter number of pax (maximum : 50) : ";
  53.     cin>>paxNo;
  54.  
  55.     while (correct == 1){
  56.       if (cin.fail() || paxNo<=0 || paxNo > 50){
  57.         cin.clear();
  58.         cin.ignore();
  59.         cout << "Invalid input! Enter positive numbers (max : 50 , min : 1)!" << endl<<endl;
  60.         cout<< "Enter number of pax (maximum : 50) : ";
  61.         cin >> paxNo;
  62.       }else{
  63.         correct = 0;
  64.       }
  65.     }
  66.  
  67.     do{
  68.       correct = 1;
  69.       cout<<endl<<"Enter year (e.g : 2019): ";
  70.       cin>>year;
  71.       while (correct == 1){
  72.         if (cin.fail() || year > 2021){
  73.           cin.clear();
  74.           cin.ignore();
  75.           cout << "Invalid input! Enter numbers (maximum year is 2021)!" << endl<<endl;
  76.           cout<< "Enter year (e.g : 2019) : ";
  77.           cin >> year;
  78.           //reset if a year before 2019 was entered then 2022 or later is entered
  79.         }else{
  80.           correct = 0;
  81.         }
  82.       }
  83.     }while(!checkYear(year));
  84.  
  85.     do{
  86.       correct = 1;
  87.       cout<<endl<<"Enter month (e.g : January = 1) : ";
  88.       cin>>month;
  89.       while (correct == 1){
  90.         if (cin.fail()){
  91.           cin.clear();
  92.           cin.ignore();
  93.           cout << "Invalid input! Enter numbers!" << endl<<endl;
  94.           cout<< "Enter month (e.g : January = 1) : ";
  95.           cin >> month;
  96.         }else{
  97.           correct = 0;
  98.         }
  99.       }
  100.     }while(!checkMonth(month, year));
  101.  
  102.     do{
  103.       correct = 1;
  104.       cout<<endl<<"Enter day : ";
  105.       cin>>day;
  106.       while (correct == 1){
  107.         if (cin.fail()){
  108.           cin.clear();
  109.           cin.ignore();
  110.           cout << "Invalid input! Enter numbers!" << endl<<endl;
  111.           cout<< "Enter day : ";
  112.           cin >> day;
  113.         }else{
  114.           correct = 0;
  115.         }
  116.       }
  117.     }while(!checkDay(day, month, year));
  118.  
  119.     do{
  120.       correct = 1;
  121.       cout<<endl<<"Enter time in 24hr format (e.g : 3.30pm = 1530) : ";
  122.       cin>>time;
  123.       while (correct == 1){
  124.         if (cin.fail()){
  125.           cin.clear();
  126.           cin.ignore();
  127.           cout << "Invalid input! Enter positive numbers (maximum 4 digits)!" << endl<<endl;
  128.           cout<< "Enter time in 24hr format (e.g : 3.30pm = 1530) : ";
  129.           cin >> time;
  130.         }else{
  131.           correct = 0;
  132.         }
  133.       }
  134.     }while(!checkTime(time, day, month, year));
  135.  
  136.     //for finding the reservation by date
  137.     date = year*10000 + month*100 + day;
  138.  
  139.     RBList.InsNewNodeByBookNo(bNo, name, phoneNo, paxNo, day, month, year, time, date);
  140.     cout<<"Update process complete."<<endl;
  141.   }else{
  142.     cout<<"No existing record with that booking number."<<endl
  143.     <<"Update process cancelled."<<endl;
  144.   }
  145.  
  146.   cin.clear();
  147.   cin.ignore(1000, '\n');
  148.   cout << "Press enter to continue . . .";
  149.   getchar();
  150.   system("CLS");
  151.   main();
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement