Advertisement
murad45

Project Implementation

Sep 1st, 2021
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 11.78 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. struct info
  5. {
  6.     char passportNumber[30];
  7.     char name[30];
  8.     char destination[30];
  9.     char email[30];
  10.     int phone;
  11. } x[100];
  12.  
  13. int n,i,j=0,a=0,sum=0,g,flag,num;
  14. void read();
  15. void reserve();
  16. void display();
  17. void search();
  18. void edit();
  19. void cancel();
  20. void show();
  21. int main()
  22. {
  23.     read();
  24.     int c,i,q;
  25.     printf("\n\n\t\t ********************************************************************");
  26.     printf("\n\t\t                   welcome to Murad's airline system                   ");
  27.     printf("\n\t\t   *******************************************************************");
  28.     int m,n;
  29.  
  30.     while(c!=6)
  31.     {
  32.         fflush(stdin);
  33.         printf("\n\n\n\t\t Please enter your option from below (1-4):");
  34.         printf("\n\n\t\t 1. Reservation");
  35.         printf("\n\n\t\t 2. DISPLAY RECORDS");
  36.         printf("\n\n\t\t 3. Search RECORDS");
  37.         printf("\n\n\t\t 4. Edit RECORDS");
  38.         printf("\n\n\t\t 5. Cancel");
  39.         printf("\n\n\t\t 6. EXIT");
  40.         printf("\n\n\t\t feel free to contact ");
  41.         printf("\n\n\t\t Enter your option :");
  42.         scanf("%d",&c);//choice for option
  43.         fflush(stdin);//making it clear
  44.         if(c==1)//reserve
  45.         {
  46.             system("cls");
  47.             reserve();
  48.         }
  49.         else if(c==2)//view
  50.         {
  51.             system("cls");
  52.             display();
  53.         }
  54.         else if(c==3)//search
  55.         {
  56.             system("cls");
  57.             search();
  58.         }
  59.         else if(c==4)//edit
  60.         {
  61.             system("cls");
  62.             edit();
  63.         }
  64.         else if(c==5)//cancel
  65.         {
  66.             system("cls");
  67.             cancel();
  68.         }
  69.         else if(c==6)
  70.         {
  71.             write();
  72.             return 0;
  73.         }
  74.         else
  75.         {
  76.             system("cls");
  77.             printf("\n\nInvalid input , try again by using valid inputs");
  78.         }
  79.         printf("\n\n");
  80.     }
  81. }
  82. void reserve()
  83. {
  84.     printf("\n\n");
  85.     printf("Already Reserved Seats =%d\n\n",num);//how many inputs
  86.     printf("How many Seats do you want to reserve=\n");
  87.     scanf("%d",&n);
  88.     sum=n+num;
  89.  
  90.     for(i=num,j=0; i<sum; i++)
  91.     {
  92.         printf("\n");
  93.         fflush(stdin);
  94.         printf("Enter Passport Number = ");
  95.         gets(x[i].passportNumber);
  96.         fflush(stdin);
  97.         printf("Enter Name = ");
  98.         gets(x[i].name);
  99.         fflush(stdin);
  100.         printf("Enter the Destination = ");
  101.         gets(x[i].destination);
  102.         fflush(stdin);
  103.         printf("Enter Email Address = ");
  104.         gets(x[i].email);
  105.         fflush(stdin);
  106.         printf("Enter phone number = ");
  107.         scanf("%d",&x[i].phone);
  108.         fflush(stdin);
  109.         printf("\n");
  110.         j++;
  111.         a++;
  112.         num++;
  113.         system("cls");
  114.     }
  115. }
  116.  
  117. void display()
  118. {
  119.     for(i=0; i<num; i++)
  120.     {
  121.         printf("\n");
  122.         printf("Seat Number= A-%d\n",i);
  123.         printf("Passport = ");
  124.         puts(x[i].passportNumber);
  125.         printf("Name = ");
  126.         puts(x[i].name);
  127.         printf("Destination = ");
  128.         puts(x[i].destination);
  129.         printf("Email Address = ");
  130.         puts(x[i].email);
  131.         printf("Phone number = 0%d\n",x[i].phone);
  132.         printf("\n\n");
  133.         fflush(stdin);
  134.     }
  135. }
  136. void edit()
  137. {
  138.     int q,p;
  139.     fflush(stdin);
  140.     printf("What do you want to edit ?\n");
  141.     printf("Enter your option\n");
  142.     printf("1.Passport Number\n2.Name\n3.Destination\n4.Email Address\n5.Phone no.\n");
  143.     printf("Option=");
  144.     scanf("%d",&q);//option
  145.     if(q<=5)
  146.     {
  147.         printf("Enter the seat no of that passenger= A(0 - %d)=",num-1);
  148.         scanf("%d",&p);//seat number
  149.         if(p<num)
  150.         {
  151.             if(q==1)
  152.             {
  153.                 fflush(stdin);
  154.                 printf("Enter the new Passport Number=");
  155.                 gets(x[p].passportNumber);
  156.  
  157.             }
  158.             else if(q==2)
  159.             {
  160.                 fflush(stdin);
  161.                 printf("Enter the new Name=");
  162.                 gets(x[p].name);
  163.             }
  164.             else if(q==3)
  165.             {
  166.                 fflush(stdin);
  167.                 printf("Enter the new Destination=");
  168.                 gets(x[p].destination);
  169.             }
  170.  
  171.             else if(q==4)
  172.             {
  173.                 fflush(stdin);
  174.                 printf("Enter the new Email Address=");
  175.                 gets(x[p].email);
  176.             }
  177.  
  178.             else if(q==5)
  179.             {
  180.                 fflush(stdin);
  181.                 printf("Enter the new Phone no =");
  182.                 scanf("%d",&x[p].phone);
  183.             }
  184.         }
  185.         else
  186.         {
  187.             printf("\n\nInvalid Seat \nTry Again !!\n\n");
  188.         }
  189.     }
  190.     else
  191.     {
  192.         printf("\n\nInvalid option\nTry Again!!\n\n");
  193.     }
  194. }
  195. void search()
  196. {
  197.     int s,h,f;
  198.     char u[100];
  199.     printf("By what do you want to search ?\n");
  200.     printf("1.Seat no.\n2.passport Number\n3.Name\n4.Destination.\n5.Phone no.\n6.Email address\n\nOption = ");
  201.     scanf("%d",&h);
  202.     if(h==1)
  203.     {
  204.         printf("Enter Seat number of the passanger= A-");
  205.         scanf("%d",&s);
  206.         if(s<num)
  207.         {
  208.             printf("\n");
  209.             printf("Seat Number= A-%d\n",s);
  210.             printf("Passport Number = ");
  211.             puts(x[s].passportNumber);
  212.             printf("Name = ");
  213.             puts(x[s].name);
  214.             printf("Destination = ");
  215.             puts(x[s].destination);
  216.             printf("Email Address = ");
  217.             puts(x[s].email);
  218.             printf("Phone number = 0%d",x[s].phone);
  219.             printf("\n\n");
  220.         }
  221.         else
  222.             printf("\n\nNot Found\n\n");
  223.     }
  224.     else if(h==2)//problem is here.........
  225.     {
  226.         int f=1;
  227.         fflush(stdin);
  228.         printf("Enter your passport Number=");
  229.         gets(u);
  230.         fflush(stdin);
  231.         for(g=0; g<num; g++)
  232.         {
  233.             if(strcmp(u,x[g].passportNumber)==0)
  234.             {
  235.                 printf("\n");
  236.                 printf("Seat Number= A-%d\n",g);
  237.                 printf("Passport Number = ");
  238.                 puts(x[g].passportNumber);
  239.                 printf("Name = ");
  240.                 puts(x[g].name);
  241.                 printf("Destination = ");
  242.                 puts(x[g].destination);
  243.                 printf("Email Address = ");
  244.                 puts(x[g].email);
  245.                 printf("Phone number = 0%d",x[g].phone);
  246.                 printf("\n\n");
  247.                 f=0;
  248.  
  249.             }
  250.         }
  251.         if(f==1)
  252.             printf("\nNot Found\n");
  253.  
  254.  
  255.  
  256.     }
  257.     else if(h==3)
  258.     {
  259.         int f=1;
  260.         fflush(stdin);
  261.         printf("Enter Name = ");
  262.         gets(u);
  263.         fflush(stdin);
  264.         for(g=0; g<num; g++)
  265.         {
  266.             if(strcmp(u,x[g].name)==0)
  267.             {
  268.                 printf("\n");
  269.                 printf("Seat Number= A-%d\n",g);
  270.                 printf("Passport Number = ");
  271.                 puts(x[g].passportNumber);
  272.                 printf("Name = ");
  273.                 puts(x[g].name);
  274.                 printf("Destination = ");
  275.                 puts(x[g].destination);
  276.                 printf("Email Address = ");
  277.                 puts(x[g].email);
  278.                 printf("Phone number = 0%d",x[g].phone);
  279.                 printf("\n\n");
  280.                 f=0;
  281.             }
  282.  
  283.  
  284.         }
  285.         if(f==1)
  286.             printf("\nNot Found\n");
  287.  
  288.  
  289.     }
  290.     else if(h==4)
  291.     {
  292.         int f=1;
  293.         fflush(stdin);
  294.         printf("Enter Destination = ");
  295.         gets(u);
  296.         fflush(stdin);
  297.         for(g=0; g<num; g++)
  298.         {
  299.             if(f==x[g].destination)
  300.             {
  301.                 printf("\n");
  302.                 printf("Seat Number= A-%d\n",g);
  303.                 printf("Passport Number = ");
  304.                 puts(x[g].passportNumber);
  305.                 printf("Name = ");
  306.                 puts(x[g].name);
  307.                 printf("Destination = ");
  308.                 puts(x[g].destination);
  309.                 printf("Email Address = ");
  310.                 puts(x[g].email);
  311.                 printf("Phone number = 0%d",x[g].phone);
  312.                 printf("\n\n");
  313.                 f=0;
  314.             }
  315.  
  316.         }
  317.         if(f==1)
  318.             printf("Not Found\n\n");
  319.  
  320.     }
  321.     else if(h==5)
  322.     {
  323.         int f=1;
  324.         printf("Enter Phone number = ");
  325.         scanf("%d",&f);
  326.         for(g=0; g<num; g++)
  327.         {
  328.             if(f==x[g].phone)
  329.             {
  330.                 printf("\n");
  331.                 printf("Seat Number= A-%d\n",g);
  332.                 printf("Passport Number = ");
  333.                 puts(x[g].passportNumber);
  334.                 printf("Name = ");
  335.                 puts(x[g].name);
  336.                 printf("Destination = ");
  337.                 puts(x[g].destination);
  338.                 printf("Email Address = ");
  339.                 puts(x[g].email);
  340.                 printf("Phone number = 0%d",x[g].phone);
  341.                 printf("\n\n");
  342.                 f=0;
  343.             }
  344.  
  345.         }
  346.         if(f==1)
  347.             printf("Not Found");
  348.     }
  349.     else if(h==6)
  350.     {
  351.         int f=1;
  352.         fflush(stdin);
  353.         printf("Enter Email Address = ");
  354.         gets(u);
  355.         fflush(stdin);
  356.         for(g=0; g<num; g++)
  357.         {
  358.             if(f==x[g].email)
  359.             {
  360.                 printf("\n");
  361.                 printf("Seat Number= A-%d\n",g);
  362.                 printf("Passport Number = ");
  363.                 puts(x[g].passportNumber);
  364.                 printf("Name = ");
  365.                 puts(x[g].name);
  366.                 printf("Destination = ");
  367.                 puts(x[g].destination);
  368.                 printf("Email Address = ");
  369.                 puts(x[g].email);
  370.                 printf("Phone number = 0%d",x[g].phone);
  371.                 printf("\n\n");
  372.                 f=0;
  373.             }
  374.  
  375.         }
  376.         if(f==1)
  377.             printf("Not Found\n\n");
  378.  
  379.     }
  380.     else
  381.         printf("\n\nInvalid input\n\n");
  382.  
  383.  
  384.  
  385.  
  386. }
  387. void cancel()
  388. {
  389.     int f,h;
  390.     printf("Enter the seat number of the passenger that you want to delete=");
  391.     scanf("%d",&f);
  392.     if(f<num)
  393.     {
  394.         printf("What do you want ?\n");
  395.         printf("1.Cancel the whole Reservation\n2.Remove Passport Number\n3.Remove Name\n4.Remove Destination\n5.Remove Email\n6.Remove phone number\nOption = ");
  396.         scanf("%d",&h);
  397.         if(h==1)
  398.         {
  399.             while(f<num)
  400.             {
  401.                 strcpy(x[f].passportNumber,x[f+1].passportNumber);
  402.                 strcpy(x[f].name,x[f+1].name);
  403.                 strcpy(x[f].destination,x[f+1].destination);
  404.                 strcpy(x[f].email,x[f+1].email);
  405.                 x[f].phone=x[f+1].phone;
  406.                 f++;
  407.             }
  408.             num--;
  409.         }
  410.         else if(h==2)
  411.         {
  412.             strcpy(x[f].passportNumber,"Cleared");
  413.  
  414.         }
  415.         else if(h==3)
  416.         {
  417.             strcpy(x[f].name,"Cleared");
  418.         }
  419.         else if(h==4)
  420.         {
  421.             strcpy(x[f].destination,"Cleared");
  422.         }
  423.         else if(h==5)
  424.         {
  425.             strcpy(x[f].email,"Cleared");
  426.         }
  427.         else if(h==6)
  428.         {
  429.             x[f].phone=0;
  430.         }
  431.  
  432.     }
  433.     else
  434.         printf("\n\nInvalid Seat number\n");
  435.  
  436. }
  437. void read()
  438. {
  439.     FILE *fp = fopen("Passanger.txt","r");
  440.     if(fp == NULL)
  441.     {
  442.         //create empty file, so that we can open it
  443.         //in the next execution of this program
  444.         fp = fopen("passanger.txt","w");
  445.         fclose(fp);
  446.         printf("File does not exist\n");
  447.         printf("Let me Create a file for you\n\n\n");
  448.         return 0;
  449.     }
  450.  
  451.     num = fread(x, sizeof(struct info),100, fp);
  452.     fclose(fp);
  453. }
  454. void write()
  455. {
  456.     FILE *fp = fopen("passanger.txt","w");
  457.     if(fp == NULL)
  458.     {
  459.         printf("Error 402");
  460.         exit(1);
  461.     }
  462.     fwrite(x, sizeof(struct info),num, fp);
  463.  
  464.     fclose(fp);
  465. }
  466.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement