Guest User

Untitled

a guest
Jan 19th, 2018
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 21.47 KB | None | 0 0
  1. #include<iostream.h>
  2. #include<conio.h>
  3. #include<stdio.h>
  4. #include<string.h>
  5. #include<ctype.h>
  6. #include<process.h>
  7. #include<fstream.h>
  8.  
  9. ifstream fin;
  10. ofstream fout;
  11.  
  12. class bus{
  13.     long int mon;
  14.     long int tue;
  15.     long int wed;
  16.     long int thus;
  17.     long int fri;
  18.     long int sat;
  19.     // we dont work on sunday.
  20.     public:
  21.     void insert_table();
  22.     int dayo(char x[])
  23.     {
  24.         if(!strcmpi(x,"mon") )
  25.         {   return mon;}
  26.        
  27.         else if (!strcmpi(x,"tue") )
  28.         {   return tue;}
  29.        
  30.         else if (!strcmpi(x,"wed") )
  31.             {   return wed;}
  32.        
  33.         else if (!strcmpi(x,"thus") )
  34.             {   return thus;}
  35.        
  36.         else if (!strcmpi(x,"fri") )
  37.             {   return fri;}
  38.        
  39.         else if (!strcmpi(x,"sat") )
  40.             {   return sat;}   
  41.        
  42.        
  43.     }  
  44. }obj[20];
  45.  
  46. void bus::insert_table(){
  47.     cout<<"Enter time for: m/t/w/th/f/sa/s ";
  48.     cin>>mon>>tue>>wed>>thus>>fri>>sat;
  49. }
  50.  
  51. class passenger: public bus{
  52.     private:
  53.     char from,to,day[4];                               // cities are ABCDE therefore only char not a string.
  54.     int date,month,seatno;
  55.     public:
  56.     void insert_table()
  57.     {
  58.         cout<<"From location (A/B/C/D/E) : ";
  59.         cin>>from;
  60.         cout<<"To location (A/B/C/D/E) : ";
  61.         cin>>to;
  62.         cout<<"Date of travel : ";
  63.         cin>>date;
  64.         cout << "Month of travel : ";
  65.         cin >> month;
  66.         cout<<"Day of travel (mon/tue/wed/thus/fri/sat) : ";
  67.         gets(day);
  68.        
  69.     }
  70.  
  71.     void book_ticket();
  72.     int encrypt();
  73. }po;
  74.  
  75. int passenger::encrypt(){  
  76.     int x;
  77.     if(po.from=='A'&&po.to=='B')
  78.         x=0;
  79.     else if(po.from=='A'&&po.to=='C')
  80.          (x=1);
  81.     else if(po.from=='A'&&po.to=='D')
  82.      (x=2);
  83.     else if(po.from=='A'&&po.to=='E')
  84.     (x=3);
  85.     else if(po.from=='B'&&po.to=='A')
  86.      (x=4);
  87.     else if(po.from=='B'&&po.to=='C')
  88.      (x=5);
  89.     else if(po.from=='B'&&po.to=='D')
  90.      (x=6);
  91.     else if(po.from=='B'&&po.to=='E')
  92.      (x=7);
  93.     else if(po.from=='C'&&po.to=='A')
  94.          (x=8);
  95.     else if(po.from=='C'&&po.to=='B')
  96.          (x=9);
  97.     else if(po.from=='C'&&po.to=='D')
  98.          (x=10);
  99.     else if(po.from=='C'&&po.to=='E')
  100.          (x=11);
  101.     else if(po.from=='D'&&po.to=='A')
  102.      (x=12);
  103.     else if(po.from=='D'&&po.to=='B')
  104.          (x=13);
  105.     else if(po.from=='D'&&po.to=='C')
  106.      (x=14);
  107.     else if(po.from=='D'&&po.to=='E')
  108.      (x=15);
  109.     else if(po.from=='E'&&po.to=='A')
  110. (x=16);
  111.     else if(po.from=='E'&&po.to=='B')
  112.  (x=17);
  113.     else if(po.from=='E'&&po.to=='C')
  114.          (x=18);
  115.     else if(po.from=='E'&&po.to=='D')
  116.      (x=19);
  117.  
  118. return x;
  119. }
  120.  
  121. void passenger::book_ticket(){
  122.     char xom[3];
  123.     ifstream fin;
  124. fin.open("schedule.dat",ios::binary);
  125.     char ch='y',ch1;int obj_no;
  126.      
  127.      while(ch=='y')
  128.      {
  129.          po.insert_table();
  130.          obj_no=po.encrypt();
  131.      fin.read((char*)&obj[obj_no] , sizeof(obj[obj_no]));
  132.     strcpy(xom,(po.day));
  133.     if(obj[obj_no].dayo(xom)==0 )
  134.          cout<<"No buses available, transaction failed.\n";
  135.  
  136.      
  137.      
  138.      else
  139.      {cout<<"Bus departure timing : "<<obj[obj_no].dayo( po.day)<<endl;
  140.      cout<<"Press 'y' to book another ticket : ";
  141.       cin>>ch1;
  142.           if(ch1=='y')
  143.         cout<<"Ticket booked successfully!!\n";
  144.      
  145.      }
  146.      
  147.      cout<<"Press 'y' to book another ticket : ";
  148.      cin>>ch;
  149.      clrscr();
  150.      }
  151. }
  152.  
  153. int strcomp(char c[], char s[]){
  154.     int size = strlen(c) + 1;
  155.     for(int i = 0; i < size; i++){
  156.         if(c[i] != s[i]){
  157.             return -1;
  158.         }
  159.     }
  160.    
  161.     return 0;
  162. }
  163.  
  164. class Money{
  165.   public:
  166.   long int cardno, phone, acct;
  167.   char bank[30],name[30], emailId[30], password[20];
  168.   float amt,withdraw;
  169.  
  170.   Money()
  171.   { cardno=phone=acct=0;
  172.     amt=withdraw=0.0;
  173.     strcpy(bank,strcpy(name,strcpy(emailId,strcpy(password, "NOT INITIALISED"))));   
  174.   }
  175.   void Newacct();
  176.   void pay(float);
  177.   void add(float);
  178.   void transfer(float);
  179.    
  180. }M;
  181.  
  182. void Money:: pay(float bill){
  183. if(bill>amt)
  184.     { cout<<"Bill exceeds your current balance!!!";
  185.        getch();
  186.       exit(-1);
  187.     }                                                           //Bill payment...call wherever you are making payments
  188.   amt=-bill;
  189.   cout<<"****Transaction complete****";
  190.    
  191. }
  192.  
  193.  void Money:: transfer(float cash){  
  194.  int flag=0;
  195.      long mobno;
  196.      cout<<"Enter the mobile no: ";
  197.      cin>>mobno;                                                //Transfering money to a particular phone no.
  198.      fin.open("FILE.dat", ios::in| ios::binary);
  199.      while(!fin.eof())
  200.      { fin.read((char*)&M, sizeof(M));
  201.        if(mobno==M.phone)
  202.          { amt-= cash;
  203.            flag=1;
  204.          }
  205.      }
  206.      fin.close();
  207.      if(flag == 1)
  208.      { cout<<"Money Transfer complete";
  209.      }
  210.      else
  211.      { cout<<"\nPhone no. didn't match the saved data.";
  212.      }
  213.      
  214. }
  215.  
  216. void Money:: add(float cash){
  217. char mode[15];
  218.     cout<<"Enter your mode of payment: \tCredit card\tDebit card\tNet banking\n";
  219.     gets(mode);
  220.     if(!strcmpi(mode,"Debit card"))
  221.     {  cout<<"Enter your debit card no.: ";
  222.        cin>>cardno;
  223.        amt+=cash;    
  224.     }                                                       //Adding money to the wallet
  225.     if(!strcmpi(mode,"Net banking"))
  226.     {   cout<<"Enter the bank: ";
  227.         gets(bank);
  228.         cout<<"Account no: ";
  229.         cin>>acct;
  230.         amt+=cash;   
  231.     }
  232.     if(!strcmpi(mode,"Credit card"))
  233.     {   cout<<"Enter your Credit card no.: ";
  234.         cin>>cardno;
  235.         amt+=cash;
  236.     }
  237.   }
  238.  
  239. class mobile{
  240.   long int mobno ;
  241.   char Opratr[15];
  242.   float amount;
  243.   public:
  244.   void Getinfo()                        /*For both postpaid & prepaid */
  245.   { cout<<"Enter the mobile no.: ";
  246.     cin>>mobno;
  247.     cout<<"Enter the operator: ";
  248.     gets(Opratr);
  249.     cout<<"Enter the amount: ";
  250.     cin>>amount;
  251.     M.pay(amount);
  252.      
  253.   }
  254. };
  255.  
  256. class Electric{
  257.   char state[15], board[25], city[15];
  258.   long int consumer_no;
  259.   float bill;
  260.   public:
  261.   void Enter()
  262.   { cout<<"Enter the following details: ";
  263.     cout<<"\nState: ";
  264.     gets(state);
  265.     cout<<"\nCity: ";
  266.     gets(city);
  267.     cout<<"Electricity Board: ";
  268.     gets(board);
  269.     cout<<"consumer no: ";
  270.     cin>>consumer_no;
  271.     cout<<"Bill: ";
  272.     cin>>bill;
  273.     M.pay(bill);
  274.   }
  275. };
  276.  
  277. void Money::Newacct(){
  278.     char code[20],ch;
  279.     redo:
  280.     cout<<"Enter the following details: ";
  281.     cout <<"Enter phone number : ";
  282.     cin >> phone;
  283.     cout << "Enter account number : ";
  284.     cin >> acct;
  285.     cout << "Enter card number : ";
  286.     cin >> cardno;
  287.     cout<<"Name: ";
  288.     gets(name);
  289.     cout<<"\nEmail Id: ";
  290.     gets(emailId);
  291.     cout<<"\nPassword: ";
  292.     gets(password);
  293.     cout<<"\nConfirm password: ";
  294.     gets(code);
  295.    
  296.     if(strcomp(code,password))
  297.     { cout<<"Incorrect";
  298.       goto redo;
  299.     }
  300.    
  301.   }
  302.  
  303. void menu(){
  304.   float deposit;
  305.   char ch = 'y',opt;
  306.   fout.open("FILE.dat", ios::app|ios::binary);
  307.  
  308.   do
  309.   {
  310.       cout<<"\n\n\t\tBill Payment                 - a\n";
  311.       cout<<"\t\tDeposit                      - b\n";
  312.       cout<<"\t\tTransfer money               - c\n";
  313.       cout<<"\t\tCreate new account           - d\n";
  314.       cout<<"\n\t\tEnter your choice: ";
  315.       cin>>opt;
  316.       clrscr();
  317.       switch(opt)
  318.       { case 'a': { cout<<"Enter the amount: ";
  319.                     cin>>deposit;
  320.                     M.pay(deposit);
  321.                     fout.write((char*)&M,sizeof(M));
  322.                    
  323.                   }
  324.         case 'b': { cout<<"Enter the amount: ";
  325.                     cin>>deposit;
  326.                     M.add(deposit);
  327.                     fout.write((char*)&M,sizeof(M));
  328.                     break;
  329.                   }
  330.         case 'c': { cout<<"Enter the amt to be transferred: ";
  331.                     cin>>deposit;
  332.                     M.transfer(deposit);
  333.                     fout.write((char*)&M,sizeof(M));
  334.                     break;
  335.                   }
  336.         case 'd': { M.Newacct();
  337.                     fout.write((char*)&M,sizeof(M));
  338.                     break;
  339.                   }
  340.         default: { cout<<"Invalid choice..!!";
  341.                  }
  342.          
  343.       }  
  344.     cout<<"\nGo back to menu: ";
  345.     cin>>ch;
  346.     clrscr();
  347.   }while(ch=='y'||ch=='Y');
  348.  
  349.   fout.close();
  350. }
  351.  
  352. class hotel{
  353.     int room_no;
  354.     char name[30];
  355.     char address[50];
  356.     char phone[10];
  357.    
  358.     public:
  359.     void main_menu();    //to dispay the main menu
  360.     void add();        //to book a room
  361.     void display();    //to display the customer record
  362.     void rooms();    //to display alloted rooms
  363.     void edit();    //to edit the customer record
  364.     int check(int);    //to check room status
  365.     void modify(int);    //to modify the record
  366.     void delete_rec(int);    //to delete the record
  367. }h;
  368.  
  369. void hotel::main_menu(){
  370.     int choice;
  371.    
  372.     while(choice!=5)
  373.     {
  374.         clrscr();
  375.         cout<<"\n\t\t\t\t*************";
  376.         cout<<"\n\t\t\t\t* MAIN MENU *";
  377.         cout<<"\n\t\t\t\t*************";
  378.         cout<<"\n\n\n\t\t\t1.Book A Room";
  379.         cout<<"\n\t\t\t2.Customer Record";
  380.         cout<<"\n\t\t\t3.Rooms Allotted";
  381.         cout<<"\n\t\t\t4.Edit Record";
  382.         cout<<"\n\t\t\t5.Exit";
  383.         cout<<"\n\n\t\t\tEnter Your Choice: ";
  384.         cin>>choice;
  385.        
  386.         switch(choice)
  387.         {
  388.             case 1: add();
  389.                     break;
  390.             case 2: display();
  391.                     break;
  392.             case 3: rooms();
  393.                     break;
  394.             case 4: edit();
  395.                     break;
  396.             case 5: break;
  397.             default:
  398.                     {
  399.                         cout<<"\n\n\t\t\tWrong choice!!!";
  400.                         cout<<"\n\t\t\tPress any key to continue!!";
  401.                         getch();
  402.                     }
  403.         }
  404.     }
  405. }
  406.  
  407. void hotel::add(){
  408.     clrscr();
  409.     int r,flag;
  410.     ofstream fout("Record.dat",ios::app);
  411.    
  412.     cout<<"\n Enter Customer Detalis";
  413.     cout<<"\n **********************";
  414.     cout<<"\n\n Room no: ";
  415.     cin>>r;
  416.     flag=check(r);
  417.    
  418.     if(flag)
  419.         cout<<"\n Sorry..!!!Room is already booked";
  420.     else
  421.     {
  422.         room_no=r;
  423.         cout<<" Name: ";
  424.         gets(name);
  425.         cout<<" Address: ";
  426.         gets(address);
  427.         cout<<" Phone No: ";
  428.         gets(phone);
  429.         fout.write((char*)this,sizeof(hotel));
  430.         cout<<"\n Room is booked!!!";
  431.     }
  432.    
  433.     cout<<"\n Press any key to continue!!";
  434.     getch();
  435.     fout.close();
  436. }
  437.  
  438. void hotel::display(){
  439.     clrscr();
  440.     ifstream fin("Record.dat",ios::in);
  441.     int r,flag;
  442.     cout<<"\n Enter room no: ";
  443.     cin>>r;
  444.    
  445.     while(!fin.eof())
  446.     {
  447.         fin.read((char*)this,sizeof(hotel));
  448.         if(room_no==r)
  449.         {
  450.             clrscr();
  451.             cout<<"\n Cusromer Details";
  452.             cout<<"\n ****************";
  453.             cout<<"\n\n Room no: "<<room_no;
  454.             cout<<"\n Name: "<<name;
  455.             cout<<"\n Address: "<<address;
  456.             cout<<"\n Phone no: "<<phone;
  457.             flag=1;
  458.             break;
  459.         }
  460.     }
  461.    
  462.     if(flag==0)
  463.         cout<<"\n Sorry Room no. not found or vacant!!";
  464.        
  465.     cout<<"\n\n Press any key to continue!!";
  466.     getch();
  467.     fin.close();
  468. }
  469.  
  470. void hotel::rooms(){
  471.     clrscr();
  472.     ifstream fin("Record.dat",ios::in);
  473.     cout<<"\n\t\t\tList Of Rooms Allotted";
  474.     cout<<"\n\t\t\t*********************";
  475.     cout<<"\n\n Room No.\tName\t\tAddress\t\tPhone No.\n";
  476.    
  477.     while(!fin.eof())
  478.     {
  479.         fin.read((char*)this,sizeof(hotel));
  480.         cout<<"\n\n "<<room_no<<"\t\t"<<name;
  481.         cout<<"\t\t"<<address<<"\t\t"<<phone;
  482.     }
  483.    
  484.     cout<<"\n\n\n\t\t\tPress any key to continue!!";
  485.     getch();
  486.     fin.close();
  487. }
  488.  
  489. void hotel::edit(){
  490.     clrscr();
  491.     int choice,r;
  492.    
  493.     cout<<"\n EDIT MENU";
  494.     cout<<"\n *********";
  495.     cout<<"\n\n 1.Modify Customer Record";
  496.     cout<<"\n 2.Delete Customer Record";
  497.    
  498.     cout<<"\n Enter your choice: ";
  499.     cin>>choice;
  500.    
  501.     clrscr();
  502.     cout<<"\n Enter room no: ";
  503.     cin>>r;
  504.    
  505.     switch(choice)
  506.    
  507.     {
  508.         case 1: modify(r);
  509.        
  510.                 break;
  511.                
  512.         case 2: delete_rec(r);
  513.        
  514.                 break;
  515.                
  516.         default: cout<<"\n Wrong Choice!!";
  517.        
  518.     }
  519.    
  520.     cout<<"\n Press any key to continue!!!";
  521.     getch();
  522. }
  523.  
  524. int hotel::check(int r){
  525.     int flag=0;
  526.     ifstream fin("Record.dat",ios::in);
  527.     while(!fin.eof())
  528.     {
  529.         fin.read((char*)this,sizeof(hotel));
  530.         if(room_no==r)
  531.         {
  532.             flag=1;
  533.                 break;
  534.         }
  535.     }
  536.    
  537.     fin.close();
  538.     return(flag);
  539. }
  540.  
  541. void hotel::modify(int r){
  542.     long pos,flag=0;
  543.     fstream file("Record.dat",ios::in|ios::out|ios::binary);
  544.    
  545.     while(!file.eof())
  546.        
  547.     {
  548.         pos=file.tellg();
  549.         file.read((char*)this,sizeof(hotel));
  550.         if(room_no==r)
  551.         {
  552.             cout<<"\n Enter New Details";
  553.             cout<<"\n *****************";
  554.             cout<<"\n Name: ";
  555.             gets(name);
  556.             cout<<" Address: ";
  557.             gets(address);
  558.             cout<<" Phone no: ";
  559.             gets(phone);
  560.            
  561.             file.seekg(pos);
  562.             file.write((char*)this,sizeof(hotel));
  563.             cout<<"\n Record is modified!!";
  564.             flag=1;
  565.             break;
  566.         }
  567.     }
  568.    
  569.     if(flag==0)
  570.         cout<<"\n Sorry Room no. not found or vacant!!";
  571.        
  572.     file.close();
  573. }
  574.  
  575. void hotel::delete_rec(int r){
  576.     int flag=0;
  577.     char ch;
  578.     ifstream fin("Record.dat",ios::in);
  579.     ofstream fout("temp.dat",ios::out);
  580.    
  581.     while(!fin.eof())
  582.     {
  583.         fin.read((char*)this,sizeof(hotel));
  584.         if(room_no==r)
  585.         {
  586.             cout<<"\n Name: "<<name;
  587.             cout<<"\n Address: "<<address;
  588.             cout<<"\n Pone No: "<<phone;
  589.             cout<<"\n\n Do you want to delete this record(y/n): ";
  590.             cin>>ch;
  591.            
  592.             if(ch=='n')
  593.             fout.write((char*)this,sizeof(hotel));
  594.            
  595.             flag=1;
  596.         }
  597.         else
  598.             fout.write((char*)this,sizeof(hotel));
  599.     }
  600.    
  601.     fin.close();
  602.     fout.close();
  603.    
  604.     if(flag==0)
  605.         cout<<"\n Sorry room no. not found or vacant!!";
  606.     else
  607.     {
  608.         remove("Record.dat");
  609.         rename("temp.dat","Record.dat");
  610.     }
  611. }
  612.  
  613. class Menu {
  614.     public:
  615.         int numItems;
  616.         char name[50];
  617.         int selectedItem;
  618.         int space;
  619.         int x;
  620.         int y;
  621.         int width;
  622.         int height;
  623.         void printBorder() const ;
  624.        
  625.         Menu(int _numItems, char _name[50], int _selectedItem, int _space, int _x, int _y, int _width, int _height){
  626.             numItems = _numItems;
  627.             strcpy(name, _name);
  628.             selectedItem = _selectedItem;
  629.             space = _space;
  630.             x = _x;
  631.             y = _y;
  632.             width = _width;
  633.             height = _height;
  634.         }
  635.        
  636.         Menu(){}
  637.         void highlightNext();
  638.         void highlightPrev();
  639. };
  640.  
  641. void Menu::highlightNext(){
  642.     selectedItem = (selectedItem >= numItems) ?  1 : selectedItem + 1;
  643.  
  644. }
  645.  
  646. void Menu::highlightPrev(){
  647.     selectedItem = (selectedItem <= 1) ?  numItems : selectedItem - 1;
  648. }
  649.  
  650. void spaces(int n){
  651.     for(int i = 0; i < n; i++){
  652.         cout << " ";
  653.     }
  654. }
  655.  
  656. int strcomp(char c[], char s[], int size){
  657.     for(int i = 0; i < size; i++){
  658.         if(c[i] != s[i]){
  659.             return -1;
  660.         }
  661.     }
  662.    
  663.     return 0;
  664. }
  665.  
  666. /*struct Node{
  667.     char element[30];
  668.     Node* next;
  669.     Node(){next = NULL; strcpy(element, " ");}
  670. };
  671.  
  672. class Stack{
  673.     private:
  674.         int length;
  675.         Node* top;
  676.     public:
  677.         Stack(){top = new Node; length = 0;}
  678.         char[30] getElement(int n);
  679.         void push(char c[30]);
  680.         void pop();
  681. };
  682.  
  683. void Stack::push(char c[30]){
  684.     Node* newnode = new Node;
  685.     strcpy(newnode->element, c);
  686.     newnode->next = top;
  687.     length++;
  688. }
  689. */
  690.  
  691. /*void Menu::printBorder() const {
  692.     textcolor(8);
  693.    
  694.     for(int i = x; i <= x + width; i++){
  695.         gotoxy(i, y);
  696.         cprintf("#");
  697.         gotoxy(i,y + height);
  698.         cprintf("#");
  699.     }
  700.    
  701.    
  702.     for(int j = y; j <= y + height; j++){
  703.         gotoxy(x, j);
  704.         cprintf("#");
  705.         gotoxy(width + x, j);
  706.         cprintf("#");
  707.     }
  708. }*/
  709.  
  710. class MainMenu : public Menu {
  711.     private:   
  712.         char mainItems[5][30];
  713.         void initMainItems(char c[5][30], int size);
  714.     public:
  715.         MainMenu() : Menu(0, " ", 0, 0, 0, 0, 0, 0) {}
  716.         MainMenu(char c[5][30] ,int size) : Menu(size, "Main", 1, 1, 20, 3, 40, 20){initMainItems(c, size);}
  717.    
  718.         void printMainMenu() const;
  719.         void interact();
  720. };
  721.  
  722. void MainMenu::initMainItems(char c[5][30], int size){
  723.     for(int i = 0; i < size; i++){
  724.         strcpy(mainItems[i], c[i]);
  725.     }
  726.  
  727. }
  728.  
  729. void MainMenu::printMainMenu() const {
  730.     for(int i = 0;i < numItems; i++){
  731.         gotoxy(x + 15, 2*(i + space) + y + 3 );
  732.        
  733.         if( (i + 1) == selectedItem){
  734.             textcolor(0xA);
  735.         }else{
  736.             textcolor(7);
  737.         }
  738.         cprintf(mainItems[i]);
  739.     }
  740.    
  741. }
  742.  
  743. class Credentials {
  744.     public:
  745.         char username[8];
  746.         char password[8];
  747. };
  748.  
  749. class SignUpMenu : public Menu {
  750.     private :
  751.         Credentials curCredential;
  752.         int usernameFlag;
  753.         int passwordFlag;
  754.     public :
  755.         SignUpMenu() : Menu(5, "SignUpMenu", 1, 2, 20, 3, 40, 20), usernameFlag(0), passwordFlag(0) {}
  756.        
  757.         void printSignUpMenu() const;
  758.         void interact();
  759. };
  760.  
  761. class  MENUS {
  762.     public :
  763.         static const int SIGNUP;
  764.         static const int  MAIN;
  765.         static int CURRENT;
  766.         static int MENUCHANGE;
  767.         static void printCurMenu(MainMenu& m, SignUpMenu &s);
  768.         static void highlightNext(MainMenu& m, SignUpMenu &s);
  769.         static void highlightPrev(MainMenu& m, SignUpMenu &s);
  770.         static void interact(MainMenu& m, SignUpMenu &s);
  771. };
  772.  
  773. const int MENUS::SIGNUP = 0;
  774. const int MENUS::MAIN = 1;
  775. int MENUS::CURRENT = 0;
  776. int MENUS::MENUCHANGE = 0;
  777.  
  778. void MainMenu::interact(){
  779.     if(selectedItem == 1){
  780.         h.main_menu();
  781.         getch();
  782.     }else if(selectedItem == 2){
  783.         clrscr();
  784.         menu();
  785.     }else if(selectedItem == 3){
  786.         clrscr();
  787.         po.book_ticket();
  788.     }else if(selectedItem == 4){
  789.         exit(-1);
  790.     }
  791. }
  792.  
  793. void SignUpMenu::interact(){
  794.     int offset = 5;
  795.    
  796.     if(selectedItem == 1){
  797.         if(usernameFlag) for(int i = 0; i < 8; i++) {
  798.             curCredential.username[i] = ' ';
  799.             gotoxy(x + 12 + 11 + i, space + y + offset );
  800.             cout << curCredential.username[i];
  801.         }
  802.        
  803.         int numChar = 0;
  804.         while(numChar < 8 && numChar >= 0){
  805.             char c = getch();
  806.             if(!isalnum(c)){
  807.                 if(c == 13) break;
  808.                 numChar--;
  809.                 continue;
  810.             }  
  811.            
  812.             curCredential.username[numChar] = c;
  813.             gotoxy(x + 12 + 11 + numChar, space + y + offset );
  814.             cout << curCredential.username[numChar];
  815.             numChar++;
  816.         }
  817.        
  818.         usernameFlag = 1;
  819.     }else if (selectedItem == 2){
  820.         if(passwordFlag) for(int i = 0; i < 8; i++) {
  821.             curCredential.password[i] = ' ';
  822.             gotoxy(x + 12 + 11 + i, 2 + space + y + offset );
  823.             cout << curCredential.password[i];
  824.         }
  825.        
  826.         int numChar = 0;
  827.         while(numChar < 8 && numChar >= 0){
  828.             char c = getch();
  829.             if(!isalnum(c)){
  830.                 if(c == 13) break;
  831.                 numChar--;
  832.                 continue;
  833.             }  
  834.             curCredential.password[numChar] = c;
  835.             gotoxy(x + 12 + 11 + numChar,2 + space + y + offset );
  836.             cout << "*";
  837.             numChar++;
  838.         }
  839.    
  840.         passwordFlag = 1;
  841.     }else if (selectedItem == 3){
  842.         exit(0);
  843.     }else if(selectedItem == 4){
  844.         Credentials c;
  845.         int flag = 0;
  846.         ifstream fin("Database.dat", ios::binary | ios::in);
  847.  
  848.         if(fin == NULL){
  849.             gotoxy(x + 12, space + y + offset + 9 );
  850.             cout << "Database not found.";
  851.             getch();
  852.             exit(0);
  853.         }
  854.        
  855.         while( fin.read((char*)& c, sizeof(c)) ){
  856.             if( (!strcomp(c.username, curCredential.username, 8)) ){
  857.                 gotoxy(x + 12, space + y + offset + 9 );
  858.                 cout << "Invalid username.";
  859.                 getch();
  860.                 gotoxy(x + 12 , space + y + offset + 9 );
  861.                 spaces(25);
  862.                 flag = 1;
  863.             }
  864.         }
  865.        
  866.         fin.close();
  867.  
  868.         if(!flag){
  869.             ofstream fout("Database.dat", ios::binary | ios::app);
  870.             if(fout != NULL){
  871.                 fout.write((char*)& curCredential, sizeof(curCredential));
  872.                 gotoxy(x + 12, space + y + offset + 9 );
  873.                 cout << "Account created.";
  874.                 getch();
  875.                 gotoxy(x + 12, space + y + offset + 9 );
  876.                 spaces(16);
  877.             }
  878.             fout.close();
  879.         }
  880.        
  881.     }else if(selectedItem == 5){
  882.         Credentials c;
  883.         int flag = 0;
  884.         ifstream fin("Database.dat", ios::binary | ios::in);
  885.  
  886.         if(fin == NULL){
  887.             gotoxy(x + 12, space + y + offset + 9 );
  888.             cout << "Database not found.";
  889.             getch();
  890.             exit(0);
  891.         }
  892.        
  893.         while( fin.read((char*)& c, sizeof(c)) ){
  894.             if( (!strcomp(c.username, curCredential.username, 8)) &&
  895.                 (!strcomp(c.password, curCredential.password, 8)) ){
  896.                 gotoxy(x + 12, space + y + offset + 9 );
  897.                 MENUS::CURRENT = MENUS::MAIN;
  898.                 MENUS::MENUCHANGE = 1;
  899.                 flag = 1;
  900.             }
  901.         }
  902.        
  903.         if(!flag){
  904.             gotoxy(x + 12, space + y + offset + 9 );
  905.             cout << "Account not found.";
  906.             getch();
  907.             gotoxy(x + 12 , space + y + offset + 9 );
  908.             spaces(25);
  909.         }
  910.    
  911.     }
  912. }
  913.  
  914. void SignUpMenu::printSignUpMenu() const {
  915.     int offset = 5;
  916.    
  917.     if(selectedItem == 1){textcolor(0xA);}else{textcolor(7);}
  918.     gotoxy(x + 12, space + y + offset );
  919.     cprintf("Username : ");
  920.    
  921.     if(selectedItem == 2){textcolor(0xA);}else{textcolor(7);}  
  922.     gotoxy(x + 12, 2 + space + y + offset );
  923.     cprintf("Password : ");
  924.    
  925.     if(selectedItem == 3){textcolor(0xA);}else{textcolor(7);}
  926.     gotoxy(x + 8, 7 + space + y + offset );
  927.     cprintf("Exit");
  928.    
  929.     if(selectedItem == 4){textcolor(0xA);}else{textcolor(7);}
  930.     gotoxy(x + 16, 7 + space + y + offset );
  931.     cprintf("Sign Up");
  932.  
  933.     if(selectedItem == 5){textcolor(0xA);}else{textcolor(7);}
  934.     gotoxy(x + 27, 7 + space + y + offset );
  935.     cprintf("Login");
  936.  
  937. }
  938.  
  939. void MENUS::printCurMenu(MainMenu& m, SignUpMenu &s) {
  940.     if(MENUS::MENUCHANGE) clrscr();
  941.    
  942.     switch(MENUS::CURRENT){
  943.         case MENUS::SIGNUP:
  944.             s.printSignUpMenu();
  945.             break;
  946.         case MENUS::MAIN:
  947.             m.printMainMenu();
  948.             break;
  949.     }
  950. }
  951.  
  952. void MENUS::highlightNext(MainMenu& m, SignUpMenu &s) {
  953.     switch(MENUS::CURRENT){
  954.         case MENUS::SIGNUP:
  955.             s.highlightNext();
  956.             break;
  957.         case MENUS::MAIN:
  958.             m.highlightNext();
  959.             break;
  960.     }
  961. }
  962.  
  963. void MENUS::highlightPrev(MainMenu& m, SignUpMenu &s) {
  964.     switch(MENUS::CURRENT){
  965.         case MENUS::SIGNUP:
  966.             s.highlightPrev();
  967.             break;
  968.         case MENUS::MAIN:
  969.             m.highlightPrev();
  970.             break;
  971.     }
  972.  
  973. }
  974.  
  975. void MENUS::interact(MainMenu& m, SignUpMenu &s) {
  976.     switch(MENUS::CURRENT){
  977.         case MENUS::SIGNUP:
  978.             s.interact();
  979.             break;
  980.         case MENUS::MAIN:
  981.             m.interact();
  982.             break;
  983.     }
  984. }
  985.  
  986. void mainProgram(){
  987.     char mainMenuItems[4][30] = {"Hotel booking", "Money transactions", "Bus booking", "Exit"};
  988.    
  989.     MainMenu m(mainMenuItems, 4);
  990.     //mainM.printMainMenu();
  991.     SignUpMenu s;
  992.     MENUS::printCurMenu(m, s);
  993.    
  994.     int flag = 1;
  995.     while(flag == 1){
  996.         switch(getch()){
  997.             case 'w':
  998.                 MENUS::highlightPrev(m, s);
  999.                 break;
  1000.             case 's':
  1001.                 MENUS::highlightNext(m, s);
  1002.                 break;
  1003.             case 13:
  1004.                 MENUS::interact(m, s);
  1005.                 break;
  1006.         }
  1007.         MENUS::printCurMenu(m, s);
  1008.     }
  1009. }
  1010.  
  1011. void main(){
  1012.     mainProgram();
  1013.     getch();
  1014. }
Add Comment
Please, Sign In to add comment