کدی که برای استفاده در اختیار شما قرار گرفته است در واقع سورس برنامه ای است که رزرو بلیط هواپیما را به شرح زیر انجام میدهد:
1-این برنامه برای 3 پرواز نوشته شده است که کاربر می تواند در هر کدام از 3 پرواز بلیط رزرو کند 2-هر هواپیما شامل 60 صندلی به صورت 6 ردیف و 10 ستون می باشد
3-برای رزرو بلیط از هر کاربر مشخصات زیر مورد نیاز می باشد:
*شماره پرواز
*نام
*نام خانوادگی
*کد ملی
*شماره تلفن==>اختیاری
4-رزرو صندلی به صورت اتوماتیک و اولین صندلی خالی می باشد
5-امکان جست و جوی هر مسافر بر اساس نام خانوادگی یا کد ملی وجود دارد
6-نقشه رزرو هر هواپیما قابل نمایش می باشد
7-امکان ذخیره اطلاعات در یک فایل دودویی و استفاده در موارد بعدی وجود دارد
8-امکان کنسل کردن بلیط بر اساس شماره صندلی وجود دارد
9-امکان نمایش کلیه مسافران به ترتیب حروف الفبا وجود دارد
3-برای رزرو بلیط از هر کاربر مشخصات زیر مورد نیاز می باشد:
*شماره پرواز
*نام
*نام خانوادگی
*کد ملی
*شماره تلفن==>اختیاری
4-رزرو صندلی به صورت اتوماتیک و اولین صندلی خالی می باشد
5-امکان جست و جوی هر مسافر بر اساس نام خانوادگی یا کد ملی وجود دارد
6-نقشه رزرو هر هواپیما قابل نمایش می باشد
7-امکان ذخیره اطلاعات در یک فایل دودویی و استفاده در موارد بعدی وجود دارد
8-امکان کنسل کردن بلیط بر اساس شماره صندلی وجود دارد
9-امکان نمایش کلیه مسافران به ترتیب حروف الفبا وجود دارد
این برنامه کاملا توسط مدیر گرامی این سایت نوشته شده و هرگونه کپی برداری ممنوع می باشد.
در صورت داشتن هر گونه مشکلی، سوال خود را با مدیر سایت در میان بگذارید.
//This program code download from www.chemical-eng.ir #include <stdio.h> #include <stdlib.h> #include <conio.h> #include <string.h> #include <ctype.h> #include <windows.h> #include <string.h>void gotoxy(int ,int ); void find(void); void display(int ,int, int,int); void map(void); void cancel(void); int menu(void) ; void init_list(void); void reserve(void) ; void load() ; void save (); void sort (void); int x,y,j,i,intflight; char flight[5]; char filename[10]; char searchname[15]; struct passenger { char name [20] ; char surname[20]; char national_id[20]; char phone[20]; int seat_num; } list1 [6][10],list2 [6][10],list3 [6][10]; int main() { system("cls"); init_list(); /*printf("Enter flight number<<1-10>>:"); gets(flight); strcpy(filename,flight); strcat(filename,".txt"); init_list(); */ FILE *fp ; fp = fopen("reserve.dat", "w+b"); if(!fp) { system("cls"); printf("\n cannot open file "); getch(); return ; } load(); /* char temp[1]; while (1){ gets(temp); if (strcmp(temp,"N")==0 || strcmp(temp,"n")==0) goto START; if (strcmp(temp,"Y")==0 || strcmp(temp,"y")==0) { fp2 = fopen(filename, "w+b"); break;} if (strcmp(temp,"Y")!=0 && strcmp(temp,"y")!=0 && strcmp(temp,"N")!=0 && strcmp(temp,"n")!=0 ) { system("cls"); printf("incorrect!try again: "); }//end of if getch() ; } } fclose(fp2); load(filename);*/ for(;;) { switch(menu()) { case 1: reserve(); break; case 2: cancel(); break ; case 3: find() ; break; case 4 : map() ; break ; case 5 : save(); break ; case 6 : load(); break ; case 7 : sort() ; break ; case 8 :{ save(); exit(0); } }//end of switch } //end of for } //************************************************************************ void init_list(void) { for(i=0;i<6;i++){ for (j = 0 ; j < 10 ; j++){ list1[i][j].name[0] = '\0'; list1[i][j].surname[0] = '\0'; list1[i][j].seat_num = -1 ; list1[i][j].national_id[0]='\0'; //list[i][j].flight_id = atoi(flight); list1[i][j].phone[0] = '\0'; list2[i][j].name[0] = '\0'; list2[i][j].surname[0] = '\0'; list2[i][j].seat_num = -1 ; list2[i][j].national_id[0]='\0'; //list[i][j].flight_id = atoi(flight); list2[i][j].phone[0] = '\0'; list3[i][j].name[0] = '\0'; list3[i][j].surname[0] = '\0'; list3[i][j].seat_num = -1 ; list3[i][j].national_id[0]='\0'; //list[i][j].flight_id = atoi(flight); list3[i][j].phone[0] = '\0'; }//end of for j }// end of for i } //************************************************************************* void reserve(void) { char numstr[10]; system("cls"); gotoxy(25,1); puts("<< PASSENGER INFORMATIONS >>"); gotoxy(1,2); puts ("-------------------------------------------------------------------------------") ; gotoxy(1,3); printf("Flight ID" ) ; gotoxy(13,3); printf("Name" ) ; gotoxy(22,3); printf("Surename" ) ; gotoxy(39,3); printf("National ID" ) ; gotoxy(56,3); printf("Phone Num" ) ; gotoxy(70,3); printf("Seat Num" ) ; //printf(" Name Surname Flight ID Phone number Seat number" ) ; gotoxy(1,4); puts ("-------------------------------------------------------------------------------") ; //puts (" ------- -------- --------- ----------- -----------") ; do{ gotoxy(1,5); gets(flight); intflight=atoi(flight); }while(intflight!=1 && intflight!=2 && intflight!=3); switch(intflight){ case 1: for(i=0;i<6;++i){ for(j=0;j<10;++j){ if (list1[i][j].seat_num==-1) break; }//end of for j if (list1[i][j].seat_num==-1) break; }// end of for i y=j; x=i; if(x==6 && y==10){ printf("No empty seat founded"); getch(); menu(); }// end of if else { gotoxy(13,5); gets(list1[x][y].name); for (;list1[x][y].name[0] == '\0';) { gotoxy(4,10); printf("Error: This field is mandatory"); gotoxy(13,5); gets(list1[x][y].name); }// end of for gotoxy(4,10); printf(" "); gotoxy(22,5); gets(list1[x][y].surname); for (;list1[x][y].surname[0] == '\0';) { gotoxy(4,10); printf("Error: This field is mandatory"); gotoxy(22,5); gets(list1[x][y].surname); }// end of for gotoxy(4,10); printf(" "); gotoxy(39,5); gets(list1[x][y].national_id); for (;list1[x][y].national_id[0] == '\0';) { gotoxy(4,10); printf("Error: This field is mandatory"); gotoxy(39,5); gets(list1[x][y].national_id); }// end of for gotoxy(4,10); printf(" "); gotoxy(56,5); gets(list1[x][y].phone); gotoxy(56,5); //gets(flight); //list[x][y].flight_id = atoi(flight); /*for (;list[x][y].phone[0] == '\0';) { gotoxy(4,10); printf("Error: This feild is mandatory"); gotoxy(45,6); gets(list[x][y].phone); } gotoxy(4,10); printf(" "); */ gotoxy(70,5); list1[x][y].seat_num=10*x+y+1; printf("%d",list1[x][y].seat_num); getch(); }// end of else break ; //*************end of case 1********************************************************* case 2: for(i=0;i<6;++i){ for(j=0;j<10;++j){ if (list2[i][j].seat_num==-1) break; }//end of for j if (list2[i][j].seat_num==-1) break; }// end of for i y=j; x=i; if(x==6 && y==10){ printf("No empty seat founded"); getch(); menu(); }// end of if else { gotoxy(13,5); gets(list2[x][y].name); for (;list2[x][y].name[0] == '\0';) { gotoxy(4,10); printf("Error: This field is mandatory"); gotoxy(13,5); gets(list2[x][y].name); }// end of for gotoxy(4,10); printf(" "); gotoxy(22,5); gets(list2[x][y].surname); for (;list2[x][y].surname[0] == '\0';) { gotoxy(4,10); printf("Error: This field is mandatory"); gotoxy(22,5); gets(list2[x][y].surname); }// end of for gotoxy(4,10); printf(" "); gotoxy(39,5); gets(list2[x][y].national_id); for (;list2[x][y].national_id[0] == '\0';) { gotoxy(4,10); printf("Error: This field is mandatory"); gotoxy(39,5); gets(list2[x][y].national_id); }// end of for gotoxy(4,10); printf(" "); gotoxy(56,5); gets(list2[x][y].phone); gotoxy(56,5); //gets(flight); //list[x][y].flight_id = atoi(flight); /*for (;list[x][y].phone[0] == '\0';) { gotoxy(4,10); printf("Error: This feild is mandatory"); gotoxy(45,6); gets(list[x][y].phone); } gotoxy(4,10); printf(" "); */ gotoxy(70,5); list2[x][y].seat_num=10*x+y+1; printf("%d",list2[x][y].seat_num); getch(); }// end of else break; //*****************************end od case 2***************************************** case 3: for(i=0;i<6;++i){ for(j=0;j<10;++j){ if (list3[i][j].seat_num==-1) break; }//end of for j if (list3[i][j].seat_num==-1) break; }// end of for i y=j; x=i; if(x==6 && y==10){ printf("No empty seat founded"); getch(); menu(); }// end of if else { gotoxy(13,5); gets(list3[x][y].name); for (;list3[x][y].name[0] == '\0';) { gotoxy(4,10); printf("Error: This field is mandatory"); gotoxy(13,5); gets(list3[x][y].name); }// end of for gotoxy(4,10); printf(" "); gotoxy(22,5); gets(list3[x][y].surname); for (;list3[x][y].surname[0] == '\0';) { gotoxy(4,10); printf("Error: This field is mandatory"); gotoxy(22,5); gets(list3[x][y].surname); }// end of for gotoxy(4,10); printf(" "); gotoxy(39,5); gets(list3[x][y].national_id); for (;list3[x][y].national_id[0] == '\0';) { gotoxy(4,10); printf("Error: This field is mandatory"); gotoxy(39,5); gets(list3[x][y].national_id); }// end of for gotoxy(4,10); printf(" "); gotoxy(56,5); gets(list3[x][y].phone); gotoxy(56,5); //gets(flight); //list[x][y].flight_id = atoi(flight); /*for (;list[x][y].phone[0] == '\0';) { gotoxy(4,10); printf("Error: This feild is mandatory"); gotoxy(45,6); gets(list[x][y].phone); } gotoxy(4,10); printf(" "); */ gotoxy(70,5); list3[x][y].seat_num=10*x+y+1; printf("%d",list3[x][y].seat_num); getch(); }// end of else break ; //************************end of case 3********************************************* } } //************************************************************************** void save() { FILE *fp ; register int i ; fp = fopen("reserve.dat", "w+b"); if(!fp) { printf("\nCan not open file. \nPress any key ..."); getch() ; return ; }// end of if for(i = 0 ; i < 6 ; i++) for(j=0;j<10;j++) //if(*list1[i][j].name) fwrite(&list1[i][j], sizeof(struct passenger), 1, fp) ; for(i = 0 ; i < 6 ; i++) for(j=0;j<10;j++) //if(*list1[i][j].name) fwrite(&list2[i][j], sizeof(struct passenger), 1, fp) ; for(i = 0 ; i < 6 ; i++) for(j=0;j<10;j++) //if(*list1[i][j].name) fwrite(&list3[i][j], sizeof(struct passenger), 1, fp) ; system("cls"); printf("Data saved.\nPress any key..."); fclose(fp); getch() ; system("cls"); } //************************************************************************** void load() { int k; FILE *fp ; register int i ; fp = fopen("reserve.dat", "r+b"); if(!fp) { printf("\ncan not open file. \npress a key ..."); getch() ; return ; }; for(i = 0 ; i < 6 ; i++) for(j=0;j<10;j++){ fread(&list1[i][j], sizeof(struct passenger), 1, fp) ; }// end of for j fseek(fp, 60*(sizeof(struct passenger)), SEEK_SET); for(i = 0 ; i < 6 ; i++) for(j=0;j<10;j++){ fread(&list2[i][j], sizeof(struct passenger), 1, fp) ; }// end of for j fseek(fp, 2*60*( sizeof(struct passenger)), SEEK_SET); for(i = 0 ; i < 6 ; i++) for(j=0;j<10;j++){ fread(&list3[i][j], sizeof(struct passenger), 1, fp) ; if(feof(fp)){ system("cls"); printf("data loaded.\nPress a key..."); getch() ; fclose(fp); return ; }//end of if }// end of for j } //************************************************************************* int menu(void) { int select ; char s[10]; do { system("cls"); printf("1) Reserve Ticket \n"); printf("2) Cancel Reservtion \n"); printf("3) Search passenger\n"); printf("4) Show reservtion map\n"); printf("5) Save in file\n"); printf("6) Load data\n"); printf("7) Show passenger name by sort\n"); printf("8) Quit\n"); printf("Enter your select:\n"); gets(s); select=atoi(s); }while(select<1||select>8);//end of while return (select); } //************************************************************************* void gotoxy(int x, int y) { static HANDLE hStdout = NULL; COORD coord; coord.X = x; coord.Y = y; if(!hStdout) { hStdout = GetStdHandle(STD_OUTPUT_HANDLE); }// end of if SetConsoleCursorPosition(hStdout,coord); } //************************************************************************** void find() { int z=0,flight; char s1[15]; char select; system("cls"); printf("1)Search by Surname\n2)Search by National ID\n"); select=getche(); system("cls"); if(select=='1'){ puts("Enter passanger Surname"); gets(s1); system("cls"); for(i=0;i<6;i++){ for (j=0;j<10;j++){ if(strcmp(list1[i][j].surname,s1)==0){ display(i,j,z,1); z++; }// end of if }// end of for j }// end of for i for(i=0;i<6;i++){ for (j=0;j<10;j++){ if(strcmp(list2[i][j].surname,s1)==0){ display(i,j,z,2); z++; }// end of if }// end of for j }// end of for i for(i=0;i<6;i++){ for (j=0;j<10;j++){ if(strcmp(list3[i][j].surname,s1)==0){ display(i,j,z,3); z++; }// end of if }// end of for j }// end of for i if (z == 0) printf("passenger Not found."); getch(); };// end of if 1 ********************************************** if(select=='2'){ puts("Enter passanger national ID"); gets(s1); system("cls"); for(i=0;i<6;i++){ for (j=0;j<10;j++){ if(strcmp(list1[i][j].national_id,s1)==0){ display(i,j,z,1); z++; }// end of if }// end of for j }// end of for i for(i=0;i<6;i++){ for (j=0;j<10;j++){ if(strcmp(list2[i][j].national_id,s1)==0){ display(i,j,z,2); z++; }// end of if }// end of for j }// end of for i for(i=0;i<6;i++){ for (j=0;j<10;j++){ if(strcmp(list3[i][j].national_id,s1)==0){ display(i,j,z,3); z++; }// end of if }// end of for j }// end of for i if (z == 0) printf("passenger Not found."); getch(); };// end of if 2 ***************** } //************************************* void display(int i,int j, int z,int flight) { char numstr[10]; if (z == 0){ system("cls"); gotoxy(25,1); puts("<< PASSENGER INFORMATIONS >>"); gotoxy(1,2); puts ("-------------------------------------------------------------------------------") ; gotoxy(1,3); printf("Flight ID" ) ; gotoxy(13,3); printf("Name" ) ; gotoxy(22,3); printf("Surename" ) ; gotoxy(39,3); printf("National ID" ) ; gotoxy(56,3); printf("Phone Num" ) ; gotoxy(70,3); printf("Seat Num" ) ; gotoxy(1,4); puts ("-------------------------------------------------------------------------------") ; }// end of if switch(flight){ case 1: gotoxy(1,5+z); printf("%d",flight); gotoxy(13,5+z); puts(list1[i][j].name); gotoxy(22,5+z); puts(list1[i][j].surname); gotoxy(39,5+z); puts(list1[i][j].national_id); gotoxy(56,5+z); puts(list1[i][j].phone) ; gotoxy(70,5+z); printf("%d",list1[i][j].seat_num); printf("\n"); break; //end of case 1*************** case 2: gotoxy(1,5+z); printf("%d",flight); gotoxy(13,5+z); puts(list2[i][j].name); gotoxy(22,5+z); puts(list2[i][j].surname); gotoxy(39,5+z); puts(list2[i][j].national_id); gotoxy(56,5+z); puts(list2[i][j].phone) ; gotoxy(70,5+z); printf("%d",list2[i][j].seat_num); printf("\n"); break; //end of case 2*************** case 3 : gotoxy(1,5+z); printf("%d",flight); gotoxy(13,5+z); puts(list3[i][j].name); gotoxy(22,5+z); puts(list3[i][j].surname); gotoxy(39,5+z); puts(list3[i][j].national_id); gotoxy(56,5+z); puts(list3[i][j].phone) ; gotoxy(70,5+z); printf("%d",list3[i][j].seat_num); printf("\n"); break; //end of case 3*************** };//end of switch******************************** } //************************************************************************** void map(void) { int flight; system("cls"); printf("Enter Flight Id:"); scanf("%d",&flight); int count =0; system("cls"); gotoxy(3,1); printf("****************************************************"); gotoxy(15,2); printf("RESERVATION MAP FLIGHT !%d!",flight); gotoxy(3,3); printf("****************************************************"); switch(flight){ case 1: for(i=0;i<6;i++){ for(j=0;j<10;j++){ gotoxy((j+1)*5,(i+3)*2); if(list1[i][j].seat_num == -1){ printf("F"); count++; }// end of if else printf("*"); }//end of for j }// end of for i gotoxy(0,20); printf("The number of reserved seats are: %d\nThe number of free seats are: %d\n",60-count,count); getch(); break; // end of switch 1************** case 2: for(i=0;i<6;i++){ for(j=0;j<10;j++){ gotoxy((j+1)*5,(i+3)*2); if(list2[i][j].seat_num == -1){ printf("F"); count++; }// end of if else printf("*"); }//end of for j }// end of for i gotoxy(0,20); printf("The number of reserved seats are: %d\nThe number of free seats are: %d\n",60-count,count); getch(); break; // end of case 2******************* case 3: for(i=0;i<6;i++){ for(j=0;j<10;j++){ gotoxy((j+1)*5,(i+3)*2); if(list3[i][j].seat_num == -1){ printf("F"); count++; }// end of if else printf("*"); }//end of for j }// end of for i gotoxy(0,20); printf("The number of reserved seats are: %d\nThe number of free seats are: %d\n",60-count,count); getch(); break; // end of case 3****************** }// end of switch************************************** } //************************************************************************** void cancel(void) { char ans; system("cls"); int z1=-1,z2=-1,flight; char s[15],temp[5]; puts("Enter seat number & flight ID: "); gets(s); gets(temp); flight=atoi(temp); int tem = atoi(s); switch(flight){ case 1: for(i=0;i<6;i++){ for (j=0;j<10;j++){ if(list1[i][j].seat_num == tem){ z1=i; z2=j; }// end of if }// end of for j }//end of for i if(z1!=-1 && z2!=-1) { display(z1,z2,0,flight); printf("\nAre you sure want to cancel?\n(if yes enter \'y\' or \'Y\' else press any key)\n"); ans=getche(); if(ans=='y' || ans=='Y') { list1[z1][z2].seat_num = -1; strcpy(list1[z1][z2].name," "); strcpy(list1[z1][z1].surname," "); list1[z1][z1].surname[0]='\0'; strcpy(list1[z1][z2].national_id," "); strcpy(list1[z1][z2].phone," "); printf("\nYour reserved seat is canceled"); }//end of in if }//end of out if else printf("passenger Not found"); getch(); break ; // end of case 1************** case 2: for(i=0;i<6;i++){ for (j=0;j<10;j++){ if(list2[i][j].seat_num == tem){ z1=i; z2=j; }// end of if }// end of for j }//end of for i if(z1!=-1 && z2!=-1) { display(z1,z2,0,flight); printf("\nAre you sure want to cancel?\n(if yes enter \'y\' or \'Y\' else press any key)\n"); ans=getche(); if(ans=='y' || ans=='Y') { list2[z1][z2].seat_num = -1; strcpy(list2[z1][z2].name," "); strcpy(list2[z1][z2].surname," "); list2[z1][z2].surname[0]='\0'; strcpy(list2[z1][z2].national_id," "); strcpy(list2[z1][z2].phone," "); printf("\nYour reserved seat is canceled"); }//end of in if }//end of out if else printf("passenger Not found"); getch(); break ; // end of case2************** case 3: for(i=0;i<6;i++){ for (j=0;j<10;j++){ if(list3[i][j].seat_num == tem){ z1=i; z2=j; }// end of if }// end of for j }//end of for i if(z1!=-1 && z2!=-1) { display(z1,z2,0,flight); printf("\nAre you sure want to cancel?\n(if yes enter \'y\' or \'Y\' else press any key)\n"); ans=getche(); if(ans=='y' || ans=='Y') { list3[z1][z2].seat_num = -1; strcpy(list3[z1][z2].name," "); strcpy(list3[z1][z2].surname," "); list3[z1][z2].surname[0]='\0'; strcpy(list3[z1][z2].national_id," "); strcpy(list3[z1][z2].phone," "); printf("\nYour reserved seat is canceled"); }//end of in if }//end of out if else printf("passenger Not found"); getch(); break ; // end of case 3************** }; } //************************************************************************** void sort(void) { int i,j, slot=0,flight; char temp[60][15]; char temp1[15]; system("cls"); printf("Enter Flight number"); scanf("%d",&flight); system("cls"); gotoxy(1,1); printf("*********************************"); gotoxy(1,2); printf("SORTED NAME OF PASSENGER FLIGHT %d",flight); gotoxy(1,3); printf("*********************************\n"); switch(flight){ case 1: for(i=0;i<6;i++) { for(j=0;j<10;j++) { strcpy(temp[slot],list1[i][j].surname); slot++; }//end of for j }//end of for i for(i=59;i>0;i--) for(j=0;j<i;j++) if(strcmp(temp[j],temp[j+1])>0) { strcpy(temp1,temp[j]); strcpy(temp[j],temp[j+1]); strcpy(temp[j+1],temp1); }//end of if for(i=0;i<60;i++) { if(temp[i][0]!='\0') { printf(" "); puts(temp[i]); }//end of if }//end of for getch(); break; // end of case 1*************** case 2: for(i=0;i<6;i++) { for(j=0;j<10;j++) { strcpy(temp[slot],list2[i][j].surname); slot++; }//end of for j }//end of for i for(i=59;i>0;i--) for(j=0;j<i;j++) if(strcmp(temp[j],temp[j+1])>0) { strcpy(temp1,temp[j]); strcpy(temp[j],temp[j+1]); strcpy(temp[j+1],temp1); }//end of if for(i=0;i<60;i++) { if(temp[i][0]!='\0') { printf(" "); puts(temp[i]); }//end of if }//end of for getch(); break; // end of case 2*************** case 3: for(i=0;i<6;i++) { for(j=0;j<10;j++) { strcpy(temp[slot],list3[i][j].surname); slot++; }//end of for j }//end of for i for(i=59;i>0;i--) for(j=0;j<i;j++) if(strcmp(temp[j],temp[j+1])>0) { strcpy(temp1,temp[j]); strcpy(temp[j],temp[j+1]); strcpy(temp[j+1],temp1); }//end of if for(i=0;i<60;i++) { if(temp[i][0]!='\0') { printf(" "); puts(temp[i]); }//end of if }//end of for getch(); break; // end of case 3*************** }; } //*************************************************************************