Advertisement
tiffprag

Asgn 2(7)

Nov 19th, 2019
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 19.23 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. #include <iomanip>    //Reservation Class
  4.  
  5. //Functions Class
  6. #include <fstream>
  7. #include <sstream>
  8. #include <string>
  9.  
  10. #include <stdlib.h> //for exit() function
  11. #define MAX 5       //Array Size/number of reservations allowed
  12. using namespace std;
  13.  
  14. int found = 0;    //check whether there is any imported text files
  15. string fileDirectory; //the .txt file directory
  16.  
  17. class Reservation{
  18. private:
  19.   int bookingNo;
  20.   string name;
  21.   int phoneNo;
  22.   int paxNo;
  23.   int time;
  24.   int date;
  25.  
  26. public:
  27.   Reservation(){
  28.     bookingNo = 1;
  29.     name = "Tan Phit Huan";
  30.     phoneNo = 0123456777;
  31.     paxNo = 1;
  32.     time = 1500;
  33.     date = 20190101;
  34.   }
  35.   Reservation(int bNo, string na, int phNo, int pxNo, int t, int da){
  36.     bookingNo = bNo;
  37.     name = na;
  38.     phoneNo = phNo;
  39.     paxNo = pxNo;
  40.     time = t;
  41.     date = da;
  42.   }
  43.   void setBookingNo(int bNo){
  44.     bookingNo = bNo;
  45.   }
  46.   int getBookingNo(){
  47.     return bookingNo;
  48.   }
  49.   void setName(string na){
  50.     name = na;
  51.   }
  52.   string getName(){
  53.     return name;
  54.   }
  55.   void setPhoneNo(int phNo){
  56.     phoneNo = phNo;
  57.   }
  58.   int getPhoneNo(){
  59.     return phoneNo;
  60.   }
  61.   void setPaxNo(int pxNo){
  62.     paxNo = pxNo;
  63.   }
  64.   int getPaxNo(){
  65.     return paxNo;
  66.   }
  67.   void setTime(int t){
  68.     time = t;
  69.   }
  70.   int getTime(){
  71.     return time;
  72.   }
  73.   void setDate(long da){
  74.     date = da;
  75.   }
  76.   int getDate(){
  77.     return date;
  78.   }
  79.   void display(){
  80.     int monthNYear = date/100;
  81.  
  82.     int year = date/10000;
  83.     int month = monthNYear-(year*100);
  84.     int day = date - (monthNYear*100);
  85.  
  86.     cout<<"| "<<setfill(' ')<<bookingNo<<"   "
  87.     <<left<<setw(30)<<name
  88.     <<right<<setw(10)<<setfill('0')<<phoneNo
  89.     <<setw(12)<<setfill(' ')<<paxNo<<setw(6)<<setfill(' ')<<" "
  90.     <<setw(2)<<setfill('0')<< day <<"/"<<setw(2)<<setfill('0')<< month <<"/"<<setw(4)<<setfill('0')<< year<<setw(7)<<setfill(' ')<<" "
  91.     <<setw(4)<<setfill('0')<< time <<" |"<<endl;
  92.   }
  93. };
  94.  
  95. class Functions{
  96. public:
  97.   //DISPLAY TABLE COLUMN NAMES
  98.   void displayColumnNames(){
  99.     cout<<setfill('_')<<setw(87)<<"_"<<endl
  100.     <<setfill(' ')<<setw(5)<<"| No. "
  101.     <<left<<setw(30)<<"Name"
  102.     <<setw(5)<<"Phone No."
  103.     <<right<<setw(16)<<"Pax No."
  104.     <<setw(10)<<"Date"
  105.     <<setw(16)<<"Time |"<<endl
  106.     <<"|"<<right<<setfill('=')<<setw(86)<<"|"<<endl;
  107.   }
  108.  
  109.   //TRIM FUNCTION
  110.   string trim(const string& str){
  111.       size_t first = str.find_first_not_of(' ');
  112.       if (string::npos == first)
  113.       {
  114.           return str;
  115.       }
  116.       size_t last = str.find_last_not_of(' ');
  117.       return str.substr(first, (last - first + 1));
  118.   }
  119.  
  120.   //READ TEXT FILE FUNCTION
  121.   void readTextFile(string fileDirectory, Reservation records[]){
  122.     ifstream myFile(fileDirectory);
  123.     if(!myFile.is_open()){
  124.       cout<<endl<<"ERROR! File failed to open."<<endl;
  125.       return;
  126.     }
  127.  
  128.     found = 1;
  129.  
  130.     try{
  131.     int i=0;  //index number
  132.     string tempString,line;
  133.  
  134.     //Reservation Information
  135.     int bkNo, phoneNo, paxNo, day, month, year, date, time;
  136.     string name;
  137.  
  138.     while(getline(myFile, line)){   //reads a line
  139.       // cout<<i<<endl;
  140.       // if(i >= MAX){
  141.       //   cout<<endl<<"Maximum of "<<MAX<<" reservations can be stored."<<endl
  142.       //   <<"Some data will be lost."<<endl;
  143.       //   break;
  144.       // }
  145.       stringstream ss(line);        //using stringstream to manipulate the line
  146.       getline(ss, tempString, ' ');  //store the string in
  147.       if(tempString != "|=====================================================================================|"){
  148.         getline(ss, tempString, ' ');
  149.         if(tempString != "No."){
  150.  
  151.           bkNo=stoi(tempString);    //convert tempString to integer
  152.  
  153.           getline(ss, tempString, '|');
  154.  
  155.           //gets substring from character in position 2 onwards, 30 characters(where name column occupies)
  156.           //Then trim to get rid of empty spaces
  157.           name = (trim(tempString.substr(2,30)));
  158.  
  159.           phoneNo = stoi(tempString.substr(32,10));
  160.  
  161.           //need to trim because there can be 1 or 2 digits
  162.           paxNo = stoi(trim(tempString.substr(52,2)));
  163.  
  164.           day = stoi(tempString.substr(60,2));
  165.  
  166.           month = stoi(tempString.substr(63,2));
  167.  
  168.           year = stoi(tempString.substr(66,4));
  169.  
  170.           time = stoi(tempString.substr(77,4));
  171.  
  172.           date = year*10000 + month*100 + day;
  173.  
  174.           //Overriding the default/previous records with the new records
  175.           records[i].setBookingNo(bkNo);
  176.           records[i].setName(name);
  177.           records[i].setPhoneNo(phoneNo);
  178.           records[i].setPaxNo(paxNo);
  179.           records[i].setDate(date);
  180.           records[i].setTime(time);
  181.  
  182.           i++;
  183.         }
  184.       }
  185.  
  186.     }
  187.     }catch(...){
  188.       cout<<endl<<"ERROR! Import process cancelled."<<endl
  189.       <<"Please check whether it is the correct text file or directory."<<endl;
  190.       found = 0;
  191.     }
  192.  
  193.     cout<<endl<<"Import Successful."<<endl;
  194.     myFile.close();
  195.   }
  196.  
  197.   //BUBBLE SORT FUNCTIONS
  198.   //Sort by Name
  199.   void bubbleSortName(Reservation records[]){
  200.     int i,j;
  201.     Reservation current;
  202.     for(i=0; i<MAX;i++){  
  203.       for (j=0; j<MAX-1; j++){  
  204.         if(records[j].getName()>records[j+1].getName()){              
  205.           current = records[j];              
  206.           records[j] = records[j+1];              
  207.           records[j+1] = current;          
  208.         }        
  209.       }          
  210.     }
  211.   }
  212.  
  213.   //Sort by Date
  214.   void bubbleSortDate(Reservation records[]){
  215.       int i,j;
  216.       Reservation current;
  217.       for(i=0; i<MAX;i++){  
  218.         for (j=0; j<MAX-1; j++){  
  219.           if(records[j].getDate()>records[j+1].getDate()){              
  220.             current = records[j];              
  221.             records[j] = records[j+1];              
  222.             records[j+1] = current;          
  223.           }        
  224.         }          
  225.       }
  226.   }
  227.  
  228.   //Sort by Phone Number
  229.   void bubbleSortPhoneNo(Reservation records[]){
  230.       int i,j;
  231.       Reservation current;
  232.       for(i=0; i<MAX;i++){  
  233.         for (j=0; j<MAX-1; j++){  
  234.           if(records[j].getPhoneNo()>records[j+1].getPhoneNo()){              
  235.             current = records[j];              
  236.             records[j] = records[j+1];              
  237.             records[j+1] = current;          
  238.           }        
  239.         }          
  240.       }
  241.   }
  242.  
  243.   //BINARY SEARCH FUNCTIONS
  244.   //Search Phone No Record
  245.   int binarySearchPhoneNo(Reservation records[], int key, int low, int high){    
  246.     int middle; //the middle index number of the array    
  247.     bubbleSortPhoneNo(records);
  248.     while (low <= high ){      
  249.       middle = (low+high)/2;
  250.       if(key==records[middle].getPhoneNo()){
  251.         return middle;
  252.  
  253.       }else if(key<records[middle].getPhoneNo()){
  254.         high = middle-1; //reset high index to left side
  255.  
  256.       }else{
  257.         low = middle+1; //reset low index to right side
  258.  
  259.       }
  260.     }
  261.  
  262.     return -1;   //key not found
  263.   }
  264.  
  265.   //Search Name Record
  266.   int binarySearchName(Reservation records[], string key, int low, int high){    
  267.     int middle; //the middle index number of the array    
  268.     bubbleSortPhoneNo(records);
  269.     while (low <= high ){      
  270.       middle = (low+high)/2;
  271.       if(key==records[middle].getName()){
  272.         return middle;
  273.  
  274.       }else if(key<records[middle].getName()){
  275.         high = middle-1; //reset high index to left side
  276.  
  277.       }else{
  278.         low = middle+1; //reset low index to right side
  279.  
  280.       }
  281.     }
  282.  
  283.     return -1;   //key not found
  284.   }
  285.  
  286.   //RECURSION FUNCTIONS
  287.   //Given date, Display all with same date
  288.   void givenDate (Reservation A[], int date, int high){
  289.     if (date == A[high].getDate() ){
  290.       A[high].display();
  291.       return givenDate(A, date, high-1);
  292.     }
  293.     else if (high < 0){
  294.       return;
  295.     }
  296.     else {
  297.       return givenDate(A, date, high-1);
  298.     }
  299.   }
  300.  
  301.  
  302.   //PART 6 FUNCTION
  303.   //Give number of pax, Display all with at least given number of pax
  304.   void givenPaxNo (Reservation A[], int pax, int high){
  305.    
  306.     if (pax <= A[high].getPaxNo() ){
  307.       A[high].display();
  308.       return givenPaxNo(A, pax, high-1);
  309.     }
  310.     if(pax>A[high].getPaxNo()){
  311.       return;
  312.     }
  313.     else if (high < 0){
  314.       return;
  315.     }
  316.     else {
  317.       return givenPaxNo(A, pax, high-1);
  318.     }
  319.   }
  320.  
  321.   //ERROR CHECKING FUNCTIONS
  322.   //for checking whether the name is empty
  323.   bool checkName(string name){
  324.     int counter = 0;
  325.     bool found = true;
  326.     //if found any characters other than space
  327.     if(name.find_first_not_of(" ") != string::npos){
  328.       counter++;
  329.     }
  330.  
  331.     //if found any characters other than the alphabets and a space
  332.     if(name.find_first_not_of(" abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUV") != string::npos){
  333.       found = true;
  334.     }else{
  335.       found = false;
  336.     }
  337.  
  338.     //if no input or if got any non alphabetic character
  339.     if(counter == 0 || found){
  340.       cout<<"Invalid Input! Need a name!"<<endl;
  341.       return false;
  342.     }else{
  343.       return true;
  344.     }
  345.   }
  346.  
  347.   //Check whether that day exists
  348.   bool checkDay(int day, int month, int year){
  349.     //even months
  350.     if(day <= 0){
  351.       cout<<"Invalid Input! Enter positive numbers!"<<endl;
  352.     }else if(month%2 == 0){
  353.       // if the month is february
  354.       if(month == 2){
  355.         //february in common year that contain 28 days
  356.         if(year%4 != 0 && day>28){
  357.           cout << "Please key in between the day from 1 to 28"<< endl;
  358.         }
  359.         // february in leap year that contain 29 days
  360.         else if(year%4 == 0 && day>29){
  361.           cout << "Please key in between the day from 1 to 29"<< endl;
  362.         }
  363.         else{
  364.           return true;
  365.         }
  366.       }
  367.       // month that are even with 31 days
  368.       else if(month > 7 && day > 31){
  369.         cout << "Please key in between the day from 1 to 31"<< endl;
  370.       }
  371.       // month that are even  with 30 days
  372.       else if(month < 7 && day > 30){
  373.         cout << "Please key in between the day from 1 to 30"<< endl;
  374.       }
  375.       else{
  376.         return true;
  377.       }
  378.  
  379.     // month is odd
  380.     }else if(month%2 != 0){
  381.       // month that are odd with 30 days
  382.       if(month>8 && day > 30){
  383.         cout << "Please key in between the day from 1 to 30"<< endl;
  384.       // month that are odd with 31 days
  385.       }else if(month<8 && day > 31){
  386.         cout << "Please key in between the day from 1 to 31"<< endl;
  387.       }else{
  388.         return true;
  389.       }
  390.     }
  391.     else{
  392.       return true;
  393.     }
  394.     return false;
  395.   }
  396. };
  397.  
  398. //Global Variables
  399. Functions stuff;
  400. Reservation records[MAX];
  401.  
  402. //Option 1: Display All sorted by...
  403. void displayAll();
  404. //Option 2: Search & Display...
  405. void searchNDisplay();
  406. //Option 3: Given...display all
  407. void givenDisplayAll();
  408.  
  409. int main(){
  410.   //DEFAULT RESERVATIONS
  411.   if(found == 0){
  412.     for(int i = 0; i<MAX; i++){
  413.       records[i].setBookingNo(i+1);
  414.     }
  415.  
  416.     records[0].setName("Tan Phit Huan");
  417.     records[1].setName("Khong Ziv Hale");
  418.     records[2].setName("Rex Luah");
  419.     records[3].setName("Lee Yeu Gor");
  420.     records[4].setName("Tiffany Pragasam");
  421.  
  422.     for(int i = 0; i<MAX; i++){
  423.       records[i].setPhoneNo(123456777+i);
  424.     }
  425.  
  426.     records[0].setPaxNo(2);
  427.     records[1].setPaxNo(5);
  428.     records[2].setPaxNo(7);
  429.     records[3].setPaxNo(4);
  430.     records[4].setPaxNo(10);
  431.  
  432.     records[0].setDate(20191212);
  433.     records[1].setDate(20191111);
  434.     records[2].setDate(20191111);
  435.     records[3].setDate(20191212);
  436.     records[4].setDate(20191211);
  437.  
  438.     for(int i = 0; i<MAX; i++){
  439.       records[i].setTime(1200+(i*100));
  440.     }
  441.   }
  442.  
  443.   char choice;
  444.   cout << "===============RESTAURANT RESERVATION SYSTEM II===============" << endl<<endl;
  445.   if(found == 0){
  446.     cout<<"< Currently using default reservation records >"<<endl<<endl;
  447.   }else{
  448.     cout<<"< Current Reservation Records : "<<fileDirectory<<" >"<<endl<<endl;
  449.   }
  450.  
  451.   cout<< "Please enter your selection" << endl <<
  452.     "1. Import Text File Data" << endl <<
  453.     "2. Display All Sorted by..." << endl <<
  454.     "3. Search & Display..." << endl <<
  455.     "4. Given...display all..." << endl <<
  456.     "5. Exit" << endl;
  457.  
  458.   cout << "Choice: ";
  459.   cin >> choice;
  460.   cin.clear();
  461.   cin.ignore(1, '\n');
  462.   system("CLS");
  463.  
  464.   switch (choice) {
  465.   //Display All Sorted by...
  466.   case '1':
  467.     cout<<"Enter 0 to return to main menu."<<endl<<endl;
  468.  
  469.     cout<<"NOTE : - Only the .txt file created from the 'Restaurant Reservation System I' can be used."<<endl
  470.     <<"       - Only "<<MAX<<" reservations are allowed."<<endl<<endl;
  471.  
  472.     cout<<"Please enter file directory of .txt file (e.g : /Users/TiffanyP/Desktop/Reservations.txt) : "<<endl;
  473.     cin>>fileDirectory;
  474.  
  475.     if(fileDirectory != "0"){
  476.       stuff.readTextFile(fileDirectory, records);
  477.     }
  478.  
  479.     getchar();
  480.     cout <<endl<< "Press enter to continue . . .";
  481.     cin.clear();
  482.     cin.ignore(1000, '\n');
  483.     system("CLS");
  484.     main();
  485.  
  486.   //Display All Sorted by...
  487.   case '2':
  488.     displayAll();
  489.  
  490.   //Search...
  491.   case '3':
  492.     searchNDisplay();
  493.  
  494.   //Given...display all
  495.   case '4':
  496.     givenDisplayAll();
  497.  
  498.   case '5':
  499.     exit(1);
  500.  
  501.   default:
  502.     cout << choice << " is not valid choice" << endl;
  503.     main();
  504.   }
  505.  
  506.   return 0;
  507. }
  508.  
  509. //Option 1 : Display All sorted by...
  510. void displayAll(){
  511.   char choice;
  512.   cout << "-----------------=DISPLAY ALL=------------------" << endl;
  513.   cout << "Display all sorted by..." << endl <<
  514.   "1. Name" << endl <<
  515.   "2. Date" << endl<<
  516.   "3. Back to Main Menu"<< endl;
  517.   cout << "Choice: ";
  518.   cin >> choice;
  519.   cin.clear();
  520.   cin.ignore(1, '\n');
  521.   system("CLS");
  522.  
  523.   switch (choice) {
  524.  
  525.   //Display all sorted by name (PART 1)
  526.   case '1':
  527.     stuff.bubbleSortName(records);
  528.     stuff.displayColumnNames();
  529.  
  530.     for(int i = 0; i<MAX; i++){
  531.       records[i].display();
  532.     }
  533.     cout<<setfill('-')<<setw(87)<<"-"<<endl;
  534.  
  535.     break;
  536.  
  537.   //Display all sorted by date (PART 2)
  538.   case '2':
  539.     stuff.bubbleSortDate(records);
  540.     stuff.displayColumnNames();
  541.    
  542.     for(int i = 0; i<MAX; i++){
  543.       records[i].display();
  544.     }
  545.     cout<<setfill('-')<<setw(87)<<"-"<<endl;
  546.  
  547.     break;
  548.  
  549.   case '3':
  550.     main();
  551.  
  552.   default:
  553.     cout << choice << " is not valid choice" << endl<<endl;
  554.     displayAll();
  555.   }
  556.  
  557.   cout <<endl<< "Press enter to continue . . .";
  558.   cin.clear();
  559.   cin.ignore(1000, '\n');
  560.   system("CLS");
  561.   main();
  562. }
  563.  
  564. //Option 2 : Search...
  565. void searchNDisplay(){
  566.   char choice;
  567.   int foundIndex, phoneNo, correct;
  568.   string name;
  569.   cout << "-----------------=SEARCH & DISPLAY=------------------" << endl;
  570.   cout << "Search..." << endl <<
  571.   "1. Phone Number" << endl <<
  572.   "2. Name" << endl<<
  573.   "3. Back to Main Menu"<< endl;
  574.   cout << "Choice: ";
  575.   cin >> choice;
  576.   cin.clear();
  577.   cin.ignore(1, '\n');
  578.   system("CLS");
  579.  
  580.   switch (choice) {
  581.  
  582.   //Search by Phone Number (PART 3)
  583.   case '1':
  584.     cout<<endl<<"Enter phone number (e.g : 0123456789) : ";
  585.     cin>>phoneNo;
  586.  
  587.     correct = 1;
  588.     while (correct == 1){
  589.       if (cin.fail() || phoneNo<0){
  590.         cin.clear();
  591.         cin.ignore();
  592.         cout << "Invalid input! Enter positive numbers!" << endl<<endl;
  593.         cout<< "Enter phone number (e.g : 0123456789) : ";
  594.         cin >> phoneNo;
  595.       }else{
  596.         correct = 0;
  597.       }
  598.     }
  599.  
  600.     foundIndex = stuff.binarySearchPhoneNo(records, phoneNo, 0, MAX-1);
  601.     //If not found
  602.     if(foundIndex==-1){
  603.       cout<<"No such record with that phone number."<<endl;
  604.     }else{
  605.       //If found
  606.       stuff.displayColumnNames();
  607.       records[foundIndex].display();
  608.     }
  609.     cout<<setfill('-')<<setw(87)<<"-"<<endl;
  610.  
  611.     getchar();
  612.     cout <<endl<< "Press enter to continue . . .";
  613.     cin.clear();
  614.     cin.ignore(1000, '\n');
  615.     system("CLS");
  616.     main();
  617.  
  618.   //Search by Name (PART 4)
  619.   case '2':
  620.     do{
  621.       cout<<"Enter name : ";
  622.       getline(cin, name);
  623.     }while(!stuff.checkName(name));
  624.  
  625.     foundIndex = stuff.binarySearchName(records, name, 0, MAX-1);
  626.     //If not found
  627.     if(foundIndex==-1){
  628.       cout<<"No such record with that name."<<endl;
  629.     }else{
  630.       //If found
  631.       stuff.displayColumnNames();
  632.       records[foundIndex].display();
  633.     }
  634.     cout<<setfill('-')<<setw(87)<<"-"<<endl;
  635.  
  636.     cout <<endl<< "Press enter to continue . . .";
  637.     cin.clear();
  638.     cin.ignore(1000, '\n');
  639.     system("CLS");
  640.     main();
  641.  
  642.   case '3':
  643.     main();
  644.  
  645.   default:
  646.     cout << choice << " is not valid choice" << endl<<endl;
  647.     searchNDisplay();
  648.   }
  649. }
  650.  
  651. //Option 3 : Given...display all
  652. void givenDisplayAll(){
  653.   char choice;
  654.   int year, month, day, date, paxNo, correct;
  655.   cout << "-----------------=GIVEN DISPLAY ALL=------------------" << endl;
  656.   cout << "Given...display all records with..." << endl <<
  657.   "1. Date, the same date" << endl <<
  658.   "2. Number of Pax, at least the given number of pax" << endl<<
  659.   "3. Back to Main Menu"<< endl;
  660.   cout << "Choice: ";
  661.   cin >> choice;
  662.   cin.clear();
  663.   cin.ignore(1, '\n');
  664.   system("CLS");
  665.  
  666.   switch (choice) {
  667.  
  668.   //Display by Date (PART 5)
  669.   case '1':
  670.     correct = 1;
  671.     cout<<endl<<"Enter year (e.g : 2019): ";
  672.     cin>>year;
  673.     while (correct == 1){
  674.       if (cin.fail() || year<0){
  675.         cin.clear();
  676.         cin.ignore();
  677.         cout << "Invalid input! Enter positive numbers!" << endl<<endl;
  678.         cout<< "Enter year (e.g : 2019) : ";
  679.         cin >> year;
  680.         //reset if a year before 2019 was entered then 2022 or later is entered
  681.       }else{
  682.         correct = 0;
  683.       }
  684.     }
  685.  
  686.     correct = 1;
  687.     cout<<endl<<"Enter month (e.g : January = 1) : ";
  688.     cin>>month;
  689.     while (correct == 1){
  690.       if (cin.fail() || month<1 || month>12){
  691.         cin.clear();
  692.         cin.ignore();
  693.         cout << "Invalid input! Only numbers from 1 to 12!" << endl<<endl;
  694.         cout<< "Enter month (e.g : January = 1) : ";
  695.         cin >> month;
  696.       }else{
  697.         correct = 0;
  698.       }
  699.     }
  700.  
  701.     do{
  702.       correct = 1;
  703.       cout<<endl<<"Enter day : ";
  704.       cin>>day;
  705.       while (correct == 1){
  706.         if (cin.fail()){
  707.           cin.clear();
  708.           cin.ignore();
  709.           cout << "Invalid input! Enter numbers!" << endl<<endl;
  710.           cout<< "Enter day : ";
  711.           cin >> day;
  712.         }else{
  713.           correct = 0;
  714.         }
  715.       }
  716.     }while(!stuff.checkDay(day, month, year));
  717.  
  718.     date = year*10000 + month*100 + day;
  719.     stuff.displayColumnNames();
  720.     //Call recursion function here
  721.     stuff.givenDate(records, date, MAX-1);
  722.     cout<<setfill('-')<<setw(87)<<"-"<<endl;
  723.     break;
  724.  
  725.   //Display by Pax Number (PART 6)
  726.   case '2':
  727.     correct = 1;
  728.     cout<<endl<<"Enter number of pax : ";
  729.     cin>>paxNo;
  730.  
  731.     while (correct == 1){
  732.       if (cin.fail() || paxNo<=0){
  733.         cin.clear();
  734.         cin.ignore();
  735.         cout << "Invalid input! Enter positive numbers (mininimum : 1)!" << endl<<endl;
  736.         cout<< "Enter number of pax : ";
  737.         cin >> paxNo;
  738.       }else{
  739.         correct = 0;
  740.       }
  741.     }
  742.  
  743.     stuff.displayColumnNames();
  744.     //Call recursion function here
  745.     stuff.givenPaxNo(records, paxNo, MAX-1);
  746.     cout<<setfill('-')<<setw(87)<<"-"<<endl;
  747.     break;
  748.  
  749.   case '3':
  750.     main();
  751.  
  752.   default:
  753.     cout << choice << " is not valid choice" << endl;
  754.     displayAll();
  755.   }
  756.  
  757.   getchar();
  758.   cout <<endl<< "Press enter to continue . . .";
  759.   cin.clear();
  760.   cin.ignore(1000, '\n');
  761.   system("CLS");
  762.   main();
  763. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement