Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- struct info
- {
- char passportNumber[30];
- char name[30];
- char destination[30];
- char email[30];
- int phone;
- } x[100];
- int n,i,j=0,a=0,sum=0,g,flag,num;
- void read();
- void reserve();
- void display();
- void search();
- void edit();
- void cancel();
- void show();
- int main()
- {
- read();
- int c,i,q;
- printf("\n\n\t\t ********************************************************************");
- printf("\n\t\t welcome to Murad's airline system ");
- printf("\n\t\t *******************************************************************");
- int m,n;
- while(c!=6)
- {
- fflush(stdin);
- printf("\n\n\n\t\t Please enter your option from below (1-4):");
- printf("\n\n\t\t 1. Reservation");
- printf("\n\n\t\t 2. DISPLAY RECORDS");
- printf("\n\n\t\t 3. Search RECORDS");
- printf("\n\n\t\t 4. Edit RECORDS");
- printf("\n\n\t\t 5. Cancel");
- printf("\n\n\t\t 6. EXIT");
- printf("\n\n\t\t feel free to contact ");
- printf("\n\n\t\t Enter your option :");
- scanf("%d",&c);//choice for option
- fflush(stdin);//making it clear
- if(c==1)//reserve
- {
- system("cls");
- reserve();
- }
- else if(c==2)//view
- {
- system("cls");
- display();
- }
- else if(c==3)//search
- {
- system("cls");
- search();
- }
- else if(c==4)//edit
- {
- system("cls");
- edit();
- }
- else if(c==5)//cancel
- {
- system("cls");
- cancel();
- }
- else if(c==6)
- {
- write();
- return 0;
- }
- else
- {
- system("cls");
- printf("\n\nInvalid input , try again by using valid inputs");
- }
- printf("\n\n");
- }
- }
- void reserve()
- {
- printf("\n\n");
- printf("Already Reserved Seats =%d\n\n",num);//how many inputs
- printf("How many Seats do you want to reserve=\n");
- scanf("%d",&n);
- sum=n+num;
- for(i=num,j=0; i<sum; i++)
- {
- printf("\n");
- fflush(stdin);
- printf("Enter Passport Number = ");
- gets(x[i].passportNumber);
- fflush(stdin);
- printf("Enter Name = ");
- gets(x[i].name);
- fflush(stdin);
- printf("Enter the Destination = ");
- gets(x[i].destination);
- fflush(stdin);
- printf("Enter Email Address = ");
- gets(x[i].email);
- fflush(stdin);
- printf("Enter phone number = ");
- scanf("%d",&x[i].phone);
- fflush(stdin);
- printf("\n");
- j++;
- a++;
- num++;
- system("cls");
- }
- }
- void display()
- {
- for(i=0; i<num; i++)
- {
- printf("\n");
- printf("Seat Number= A-%d\n",i);
- printf("Passport = ");
- puts(x[i].passportNumber);
- printf("Name = ");
- puts(x[i].name);
- printf("Destination = ");
- puts(x[i].destination);
- printf("Email Address = ");
- puts(x[i].email);
- printf("Phone number = 0%d\n",x[i].phone);
- printf("\n\n");
- fflush(stdin);
- }
- }
- void edit()
- {
- int q,p;
- fflush(stdin);
- printf("What do you want to edit ?\n");
- printf("Enter your option\n");
- printf("1.Passport Number\n2.Name\n3.Destination\n4.Email Address\n5.Phone no.\n");
- printf("Option=");
- scanf("%d",&q);//option
- if(q<=5)
- {
- printf("Enter the seat no of that passenger= A(0 - %d)=",num-1);
- scanf("%d",&p);//seat number
- if(p<num)
- {
- if(q==1)
- {
- fflush(stdin);
- printf("Enter the new Passport Number=");
- gets(x[p].passportNumber);
- }
- else if(q==2)
- {
- fflush(stdin);
- printf("Enter the new Name=");
- gets(x[p].name);
- }
- else if(q==3)
- {
- fflush(stdin);
- printf("Enter the new Destination=");
- gets(x[p].destination);
- }
- else if(q==4)
- {
- fflush(stdin);
- printf("Enter the new Email Address=");
- gets(x[p].email);
- }
- else if(q==5)
- {
- fflush(stdin);
- printf("Enter the new Phone no =");
- scanf("%d",&x[p].phone);
- }
- }
- else
- {
- printf("\n\nInvalid Seat \nTry Again !!\n\n");
- }
- }
- else
- {
- printf("\n\nInvalid option\nTry Again!!\n\n");
- }
- }
- void search()
- {
- int s,h,f;
- char u[100];
- printf("By what do you want to search ?\n");
- printf("1.Seat no.\n2.passport Number\n3.Name\n4.Destination.\n5.Phone no.\n6.Email address\n\nOption = ");
- scanf("%d",&h);
- if(h==1)
- {
- printf("Enter Seat number of the passanger= A-");
- scanf("%d",&s);
- if(s<num)
- {
- printf("\n");
- printf("Seat Number= A-%d\n",s);
- printf("Passport Number = ");
- puts(x[s].passportNumber);
- printf("Name = ");
- puts(x[s].name);
- printf("Destination = ");
- puts(x[s].destination);
- printf("Email Address = ");
- puts(x[s].email);
- printf("Phone number = 0%d",x[s].phone);
- printf("\n\n");
- }
- else
- printf("\n\nNot Found\n\n");
- }
- else if(h==2)//problem is here.........
- {
- int f=1;
- fflush(stdin);
- printf("Enter your passport Number=");
- gets(u);
- fflush(stdin);
- for(g=0; g<num; g++)
- {
- if(strcmp(u,x[g].passportNumber)==0)
- {
- printf("\n");
- printf("Seat Number= A-%d\n",g);
- printf("Passport Number = ");
- puts(x[g].passportNumber);
- printf("Name = ");
- puts(x[g].name);
- printf("Destination = ");
- puts(x[g].destination);
- printf("Email Address = ");
- puts(x[g].email);
- printf("Phone number = 0%d",x[g].phone);
- printf("\n\n");
- f=0;
- }
- }
- if(f==1)
- printf("\nNot Found\n");
- }
- else if(h==3)
- {
- int f=1;
- fflush(stdin);
- printf("Enter Name = ");
- gets(u);
- fflush(stdin);
- for(g=0; g<num; g++)
- {
- if(strcmp(u,x[g].name)==0)
- {
- printf("\n");
- printf("Seat Number= A-%d\n",g);
- printf("Passport Number = ");
- puts(x[g].passportNumber);
- printf("Name = ");
- puts(x[g].name);
- printf("Destination = ");
- puts(x[g].destination);
- printf("Email Address = ");
- puts(x[g].email);
- printf("Phone number = 0%d",x[g].phone);
- printf("\n\n");
- f=0;
- }
- }
- if(f==1)
- printf("\nNot Found\n");
- }
- else if(h==4)
- {
- int f=1;
- fflush(stdin);
- printf("Enter Destination = ");
- gets(u);
- fflush(stdin);
- for(g=0; g<num; g++)
- {
- if(f==x[g].destination)
- {
- printf("\n");
- printf("Seat Number= A-%d\n",g);
- printf("Passport Number = ");
- puts(x[g].passportNumber);
- printf("Name = ");
- puts(x[g].name);
- printf("Destination = ");
- puts(x[g].destination);
- printf("Email Address = ");
- puts(x[g].email);
- printf("Phone number = 0%d",x[g].phone);
- printf("\n\n");
- f=0;
- }
- }
- if(f==1)
- printf("Not Found\n\n");
- }
- else if(h==5)
- {
- int f=1;
- printf("Enter Phone number = ");
- scanf("%d",&f);
- for(g=0; g<num; g++)
- {
- if(f==x[g].phone)
- {
- printf("\n");
- printf("Seat Number= A-%d\n",g);
- printf("Passport Number = ");
- puts(x[g].passportNumber);
- printf("Name = ");
- puts(x[g].name);
- printf("Destination = ");
- puts(x[g].destination);
- printf("Email Address = ");
- puts(x[g].email);
- printf("Phone number = 0%d",x[g].phone);
- printf("\n\n");
- f=0;
- }
- }
- if(f==1)
- printf("Not Found");
- }
- else if(h==6)
- {
- int f=1;
- fflush(stdin);
- printf("Enter Email Address = ");
- gets(u);
- fflush(stdin);
- for(g=0; g<num; g++)
- {
- if(f==x[g].email)
- {
- printf("\n");
- printf("Seat Number= A-%d\n",g);
- printf("Passport Number = ");
- puts(x[g].passportNumber);
- printf("Name = ");
- puts(x[g].name);
- printf("Destination = ");
- puts(x[g].destination);
- printf("Email Address = ");
- puts(x[g].email);
- printf("Phone number = 0%d",x[g].phone);
- printf("\n\n");
- f=0;
- }
- }
- if(f==1)
- printf("Not Found\n\n");
- }
- else
- printf("\n\nInvalid input\n\n");
- }
- void cancel()
- {
- int f,h;
- printf("Enter the seat number of the passenger that you want to delete=");
- scanf("%d",&f);
- if(f<num)
- {
- printf("What do you want ?\n");
- printf("1.Cancel the whole Reservation\n2.Remove Passport Number\n3.Remove Name\n4.Remove Destination\n5.Remove Email\n6.Remove phone number\nOption = ");
- scanf("%d",&h);
- if(h==1)
- {
- while(f<num)
- {
- strcpy(x[f].passportNumber,x[f+1].passportNumber);
- strcpy(x[f].name,x[f+1].name);
- strcpy(x[f].destination,x[f+1].destination);
- strcpy(x[f].email,x[f+1].email);
- x[f].phone=x[f+1].phone;
- f++;
- }
- num--;
- }
- else if(h==2)
- {
- strcpy(x[f].passportNumber,"Cleared");
- }
- else if(h==3)
- {
- strcpy(x[f].name,"Cleared");
- }
- else if(h==4)
- {
- strcpy(x[f].destination,"Cleared");
- }
- else if(h==5)
- {
- strcpy(x[f].email,"Cleared");
- }
- else if(h==6)
- {
- x[f].phone=0;
- }
- }
- else
- printf("\n\nInvalid Seat number\n");
- }
- void read()
- {
- FILE *fp = fopen("Passanger.txt","r");
- if(fp == NULL)
- {
- //create empty file, so that we can open it
- //in the next execution of this program
- fp = fopen("passanger.txt","w");
- fclose(fp);
- printf("File does not exist\n");
- printf("Let me Create a file for you\n\n\n");
- return 0;
- }
- num = fread(x, sizeof(struct info),100, fp);
- fclose(fp);
- }
- void write()
- {
- FILE *fp = fopen("passanger.txt","w");
- if(fp == NULL)
- {
- printf("Error 402");
- exit(1);
- }
- fwrite(x, sizeof(struct info),num, fp);
- fclose(fp);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement