Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <ctime>
- #include <stdlib.h> //for exit() function
- #include <fstream> //for creating text file
- using namespace std;
- int total = 0;
- int bookNum = 0;
- //linklist of reservations sorted by booking number
- linklist RBList;
- void addRecord();
- void updateRecord();
- void deleteRecord();
- void viewRecord();
- void createTextFile();
- bool checkName(string name);
- int checkNoOfDigits(int phoneNo);
- bool checkYear(int year);
- bool checkMonth(int month, int year);
- bool checkDay(int day, int month, int year);
- bool checkTime(int time, int day, int month, int year);
- int main() {
- char choice;
- cout << "===============RESTAURANT RESERVATION SYSTEM===============" << endl;
- cout << "Please enter your selection" << endl <<
- "1. Add Reservation Records" << endl <<
- "2. Update Reservation Records" << endl <<
- "3. Delete Reservation Records" << endl <<
- "4. View Reservation Records " << endl <<
- "5. Create text file" << endl <<
- "6. Exit" << endl;
- cout << "Choice: ";
- cin >> choice;
- cin.clear();
- cin.ignore(1, '\n');
- system("CLS");
- switch (choice) {
- //Add Records
- case '1':
- addRecord();
- break;
- //Update Records
- case '2':
- if (total == 0) {
- cout << "No reservation records available." << endl;
- main();
- }
- updateRecord();
- break;
- //Delete Records
- case '3':
- if (total == 0) {
- cout << "No reservation records available." << endl;
- main();
- }
- deleteRecord();
- break;
- //View Reservation Records
- case '4':
- if (total == 0) {
- cout << "No reservation records available." << endl;
- main();
- }
- viewRecord();
- break;
- //Create Text File
- case '5':
- if (total == 0) {
- cout << "No reservation records available." << endl;
- main();
- }
- createTextFile();
- break;
- case '6':
- exit(1);
- break;
- default:
- cout << choice << " is not valid choice" << endl;
- main();
- }
- return 0;
- }
- //OPTION 1 : Add Reservation Records
- void addRecord(){
- string name;
- int phoneNo, paxNo, day, month, year, time, date;
- int correct = 1;
- cout << "-----------------=ADD RECORD=-------------------" << endl;
- cout<<"Enter 0 to return to main menu."<<endl;
- do{
- cout<<"Enter name : ";
- getline(cin, name);
- }while(!checkName(name));
- if(name=="0"){
- cout << "Press enter to continue . . .";
- getchar();
- system("CLS");
- main();
- }
- cout<<endl<<"Enter phone number (e.g : 0123456789) : ";
- cin>>phoneNo;
- correct = 1;
- while (correct == 1){
- if (cin.fail() || phoneNo<0 || checkNoOfDigits(phoneNo)>11){
- cin.clear();
- cin.ignore();
- cout << "Invalid input! Enter positive numbers (maximum 11 digits)!" << endl<<endl;
- cout<< "Enter phone number (e.g : 0123456789) : ";
- cin >> phoneNo;
- }else{
- correct = 0;
- }
- }
- correct = 1;
- cout<<endl<<"Enter number of pax (maximum : 50) : ";
- cin>>paxNo;
- while (correct == 1){
- if (cin.fail() || paxNo<=0 || paxNo > 50){
- cin.clear();
- cin.ignore();
- cout << "Invalid input! Enter positive numbers (max : 50 , min : 1)!" << endl<<endl;
- cout<< "Enter number of pax (maximum : 50) : ";
- cin >> paxNo;
- }else{
- correct = 0;
- }
- }
- do{
- correct = 1;
- cout<<endl<<"Enter year (e.g : 2019): ";
- cin>>year;
- while (correct == 1){
- if (cin.fail() || year > 2021){
- cin.clear();
- cin.ignore();
- cout << "Invalid input! Enter numbers (maximum year is 2021)!" << endl<<endl;
- cout<< "Enter year (e.g : 2019) : ";
- cin >> year;
- //reset if a year before 2019 was entered then 2022 or later is entered
- }else{
- correct = 0;
- }
- }
- }while(!checkYear(year));
- do{
- correct = 1;
- cout<<endl<<"Enter month (e.g : January = 1) : ";
- cin>>month;
- while (correct == 1){
- if (cin.fail()){
- cin.clear();
- cin.ignore();
- cout << "Invalid input! Enter numbers!" << endl<<endl;
- cout<< "Enter month (e.g : January = 1) : ";
- cin >> month;
- }else{
- correct = 0;
- }
- }
- }while(!checkMonth(month, year));
- do{
- correct = 1;
- cout<<endl<<"Enter day : ";
- cin>>day;
- while (correct == 1){
- if (cin.fail()){
- cin.clear();
- cin.ignore();
- cout << "Invalid input! Enter numbers!" << endl<<endl;
- cout<< "Enter day : ";
- cin >> day;
- }else{
- correct = 0;
- }
- }
- }while(!checkDay(day, month, year));
- do{
- correct = 1;
- cout<<endl<<"Enter time in 24hr format (e.g : 3.30pm = 1530) : ";
- cin>>time;
- while (correct == 1){
- if (cin.fail()){
- cin.clear();
- cin.ignore();
- cout << "Invalid input! Enter positive numbers (maximum 4 digits)!" << endl<<endl;
- cout<< "Enter time in 24hr format (e.g : 3.30pm = 1530) : ";
- cin >> time;
- }else{
- correct = 0;
- }
- }
- }while(!checkTime(time, day, month, year));
- bookNum++;
- cout<<endl<<"Booking Number : "<<bookNum<<endl;
- date = year*10000 + month*100 + day;
- RBList.InsNewNodeByBookNo(bookNum, name, phoneNo, paxNo, day, month, year, time, date);
- total++;
- cin.clear();
- cin.ignore(1000, '\n');
- cout << "Press enter to continue . . .";
- getchar();
- system("CLS");
- main();
- }
- //OPTION 2 : Update Reservation Records
- void updateRecord(){
- string name;
- int bNo, phoneNo, paxNo, day, month, year, time, date;
- int correct = 1;
- cout << "----------------=UPDATE RECORD=-----------------" << endl;
- cout<<"Enter 0 to return to main menu."<<endl;
- cout << "Enter Booking Number : ";
- cin >> bNo;
- if(bNo == 0){
- cout << "Press enter to continue . . .";
- getchar();
- system("CLS");
- main();
- }
- if(RBList.checker(bNo)){
- RBList.deleteNode(bNo);
- cin.clear();
- cin.ignore(1000, '\n');
- cout<<endl;
- cout<<"Enter name : ";
- getline(cin, name);
- cout<<endl<<"Enter phone number (e.g : 0123456789) : ";
- cin>>phoneNo;
- correct = 1;
- while (correct == 1){
- if (cin.fail() || phoneNo<0 || checkNoOfDigits(phoneNo)>11){
- cin.clear();
- cin.ignore();
- cout << "Invalid input! Enter positive numbers (maximum 11 digits)!" << endl<<endl;
- cout<< "Enter phone number (e.g : 0123456789) : ";
- cin >> phoneNo;
- }else{
- correct = 0;
- }
- }
- correct = 1;
- cout<<endl<<"Enter number of pax (maximum : 50) : ";
- cin>>paxNo;
- while (correct == 1){
- if (cin.fail() || paxNo<=0 || paxNo > 50){
- cin.clear();
- cin.ignore();
- cout << "Invalid input! Enter positive numbers (max : 50 , min : 1)!" << endl<<endl;
- cout<< "Enter number of pax (maximum : 50) : ";
- cin >> paxNo;
- }else{
- correct = 0;
- }
- }
- do{
- correct = 1;
- cout<<endl<<"Enter year (e.g : 2019): ";
- cin>>year;
- while (correct == 1){
- if (cin.fail() || year > 2021){
- cin.clear();
- cin.ignore();
- cout << "Invalid input! Enter numbers (maximum year is 2021)!" << endl<<endl;
- cout<< "Enter year (e.g : 2019) : ";
- cin >> year;
- //reset if a year before 2019 was entered then 2022 or later is entered
- }else{
- correct = 0;
- }
- }
- }while(!checkYear(year));
- do{
- correct = 1;
- cout<<endl<<"Enter month (e.g : January = 1) : ";
- cin>>month;
- while (correct == 1){
- if (cin.fail()){
- cin.clear();
- cin.ignore();
- cout << "Invalid input! Enter numbers!" << endl<<endl;
- cout<< "Enter month (e.g : January = 1) : ";
- cin >> month;
- }else{
- correct = 0;
- }
- }
- }while(!checkMonth(month, year));
- do{
- correct = 1;
- cout<<endl<<"Enter day : ";
- cin>>day;
- while (correct == 1){
- if (cin.fail()){
- cin.clear();
- cin.ignore();
- cout << "Invalid input! Enter numbers!" << endl<<endl;
- cout<< "Enter day : ";
- cin >> day;
- }else{
- correct = 0;
- }
- }
- }while(!checkDay(day, month, year));
- do{
- correct = 1;
- cout<<endl<<"Enter time in 24hr format (e.g : 3.30pm = 1530) : ";
- cin>>time;
- while (correct == 1){
- if (cin.fail()){
- cin.clear();
- cin.ignore();
- cout << "Invalid input! Enter positive numbers (maximum 4 digits)!" << endl<<endl;
- cout<< "Enter time in 24hr format (e.g : 3.30pm = 1530) : ";
- cin >> time;
- }else{
- correct = 0;
- }
- }
- }while(!checkTime(time, day, month, year));
- //for finding the reservation by date
- date = year*10000 + month*100 + day;
- RBList.InsNewNodeByBookNo(bNo, name, phoneNo, paxNo, day, month, year, time, date);
- cout<<"Update process complete."<<endl;
- }else{
- cout<<"No existing record with that booking number."<<endl
- <<"Update process cancelled."<<endl;
- }
- cin.clear();
- cin.ignore(1000, '\n');
- cout << "Press enter to continue . . .";
- getchar();
- system("CLS");
- main();
- }
- //OPTION 3 : Delete Reservation Records
- void deleteRecord(){
- int bNo;
- char confirm;
- cout << "----------------=DELETE RECORD=-----------------" << endl;
- cout<<"Enter 0 to return to main menu."<<endl;
- cout<<"Enter Booking Number : ";
- cin>>bNo;
- if(bNo == 0){
- cout << "Press enter to continue . . .";
- getchar();
- system("CLS");
- main();
- }
- if(RBList.checker(bNo)){
- RBList.PrintBookingNoRecords(bNo);
- cout<<"Confirm?(y/n) : ";
- cin>>confirm;
- switch (confirm) {
- case 'y':
- RBList.deleteNode(bNo);
- total--;
- cout<<"Deletion process complete."<<endl;
- break;
- default:
- cout<<"Deletion process cancelled."<<endl;
- main();
- }
- }else{
- cout<<"No existing record with that booking number."<<endl;
- }
- cin.clear();
- cin.ignore(1000, '\n');
- cout << "Press enter to continue . . .";
- getchar();
- system("CLS");
- main();
- }
- //OPTION 4 : View Reservation Records
- void viewRecord(){
- char choice;
- string name;
- int bNo, year, month, day, date, correct;
- cout << "-----------------=VIEW RECORD=------------------" << endl;
- cout << "Please enter your selection" << endl <<
- "1. View All Reservations(Sorted by Booking Number)" << endl <<
- "2. Search by Name" << endl<<
- "3. Search by Date"<< endl <<
- "4. Back to Main Menu"<< endl;
- cout << "Choice: ";
- cin >> choice;
- cin.clear();
- cin.ignore(1, '\n');
- system("CLS");
- switch (choice) {
- //View All Reservations
- case '1':
- RBList.PrintList();
- break;
- //Search by Name
- case '2':
- do{
- cout<<"Enter name : ";
- getline(cin, name);
- }while(!checkName(name));
- RBList.PrintNameRecords(name);
- break;
- case '3':
- cout<<endl<<"Enter year (e.g : 2019): ";
- cin>>year;
- while (correct == 1){
- if (cin.fail() || year > 2021){
- cin.clear();
- cin.ignore();
- cout << "Invalid input! Enter numbers (maximum year is 2021)!" << endl<<endl;
- cout<< "Enter year (e.g : 2019) : ";
- cin >> year;
- }else{
- correct = 0;
- }
- }
- correct = 1;
- cout<<endl<<"Enter month (e.g : January = 1) : ";
- cin>>month;
- while (correct == 1){
- if (cin.fail()){
- cin.clear();
- cin.ignore();
- cout << "Invalid input! Enter numbers!" << endl<<endl;
- cout<< "Enter month (e.g : January = 1) : ";
- cin >> month;
- }else{
- correct = 0;
- }
- }
- cout<<endl<<"Enter day : ";
- cin>>day;
- while (correct == 1){
- if (cin.fail()){
- cin.clear();
- cin.ignore();
- cout << "Invalid input! Enter numbers!" << endl<<endl;
- cout<< "Enter day : ";
- cin >> day;
- }else{
- correct = 0;
- }
- }
- date = year*10000 + month*100 + day;
- RBList.PrintDateRecords(date);
- cin.clear();
- cin.ignore(1000, '\n');
- break;
- case '4':
- main();
- break;
- default:
- cout << choice << " is not valid choice" << endl;
- viewRecord();
- }
- cout << "Press enter to continue . . .";
- cin.clear();
- cin.ignore(1000, '\n');
- system("CLS");
- main();
- }
- //OPTION 5 : Create Text File
- void createTextFile(){
- char choice;
- cout << "------------------=Create Txt File=------------------" << endl;
- cout << "Please enter your selection" << endl <<
- "1. Create Sort By Booking Number." << endl <<
- "2. Back to Main Menu"<< endl;
- cout << "Choice: ";
- cin >> choice;
- switch (choice) {
- //View All Reservations
- case '1':
- RBList.PrintListTextFile();
- break;
- case '2':
- main();
- break;
- default:
- cout << choice << " is not valid choice" << endl;
- viewRecord();
- }
- getchar();
- cout << "-----------------------------------------------------" << endl;
- cout << "Press enter to continue . . .";
- cin.clear();
- cin.ignore(1000, '\n');
- system("CLS");
- main();
- }
- //for checking whether the name is empty
- bool checkName(string name){
- int counter = 0;
- bool found = true;
- if(name.find_first_not_of(" ") != std::string::npos){
- counter++;
- }
- if(name.find_first_not_of(" abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUV0") != std::string::npos){
- found = false;
- }else{
- found = true;
- }
- if(counter == 0 || !found){
- cout<<"Invalid Input! Need a name!"<<endl;
- return false;
- }else{
- return true;
- }
- }
- int checkNoOfDigits(int phoneNo){
- if (phoneNo == 0){
- return 0;
- }else{
- return 1 + checkNoOfDigits(phoneNo / 10);
- }
- }
- //for getting the current time
- time_t now = time(0);
- tm *ltm = localtime(&now);
- int currentYear = 1900+ltm->tm_year;
- int currentMonth = 1 + ltm->tm_mon;
- int currentDay = ltm->tm_mday;
- int currentHour = ltm->tm_hour;
- int currentMinute = ltm->tm_min;
- bool checkYear(int year){
- if(year < currentYear){
- cout<<"Can't go back in time!"<<endl;
- return false;
- }else{
- return true;
- }
- }
- bool checkMonth(int month, int year){
- if(month < currentMonth && year == currentYear){
- cout<<"Can't go back in time!"<<endl;
- return false;
- }else if(month > 12){
- cout<<"There are only 12 months in a year!"<<endl;
- return false;
- }else{
- return true;
- }
- }
- bool checkDay(int day, int month, int year){
- if(day < currentDay && month == currentMonth && year == currentYear){
- cout<<"Can't go back in time!"<<endl;
- //even months
- }else if(day <= 0){
- cout<<"Can't go back in time!"<<endl;
- }else if(month%2 == 0){
- // if the month is february
- if(month == 2){
- //february in common year that contain 28 days
- if(year%4 != 0 && day>28){
- cout << "Please key in between the day from 1 to 28"<< endl;
- }
- // february in leap year that contain 29 days
- else if(year%4 == 0 && day>29){
- cout << "Please key in between the day from 1 to 29"<< endl;
- }
- else{
- return true;
- }
- }
- // month that are even with 31 days
- else if(month > 7 && day > 31){
- cout << "Please key in between the day from 1 to 31"<< endl;
- }
- // month that are even with 30 days
- else if(month < 7 && day > 30){
- cout << "Please key in between the day from 1 to 30"<< endl;
- }
- else{
- return true;
- }
- // month is odd
- }else if(month%2 != 0){
- // month that are odd with 30 days
- if(month>8 && day > 30){
- cout << "Please key in between the day from 1 to 30"<< endl;
- // month that are odd with 31 days
- }else if(month<8 && day > 31){
- cout << "Please key in between the day from 1 to 31"<< endl;
- }else{
- return true;
- }
- }
- else{
- return true;
- }
- return false;
- }
- bool checkTime(int time, int day, int month, int year){
- int hour = time/100;
- int minute = time - hour*100;
- if(hour > 24){
- cout<<"Only 0 to 24 hours."<<endl;
- return false;
- }else if(hour < currentHour && day == currentDay && month == currentMonth && year == currentYear){
- cout<<"Can't go back in time!"<<endl;
- return false;
- }else if(minute > 59){
- cout<<"Only 0 to 59 minutes."<<endl;
- }else if(minute < currentMinute && hour == currentHour && day == currentDay && month == currentMonth && year == currentYear){
- cout<<"Can't go back in time!"<<endl;
- }else{
- return true;
- }
- return false;
- }
Add Comment
Please, Sign In to add comment