Advertisement
Guest User

Untitled

a guest
Jan 11th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.38 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  6.  
  7. struct Tripdate {
  8.     int tripday;
  9.     int tripmonth;
  10.     int tripyear;
  11. };
  12. struct Bustime {
  13.     int hours;
  14.     int minute;
  15. };
  16. struct Passenger {
  17.     char custname[50];
  18.     char custsurname[50];
  19.     char custpassword;
  20.     char custusername[50];
  21.     int seat;
  22.     char username[20];
  23.     char password[20];
  24.     int busId;
  25. };
  26. struct Bus {
  27.     int id;
  28.     int busplate;
  29.     char bustripname[50];
  30.     int ticketprice;
  31.     struct Tripdate date;
  32.     struct Bustime time;
  33.     struct Passenger customer[5];
  34. };
  35.  
  36. struct Ticket {
  37.     struct Passenger customer[20];
  38.     struct Bus info[5];
  39.     struct Bustime time;
  40.     struct Tripdate date;
  41. };
  42. struct Employe {
  43.     char usern[20];
  44.     char passw[20];
  45. };
  46. //decleration of functions
  47. struct Passenger customer[20];
  48. struct Ticket t[20];
  49.  
  50. int read_EMP_usernameandpassword(struct Employe e[], char u[], char p[]);
  51.  
  52. int read_PESS_usernameandpassword(struct Passenger customer[], char us[], char pa[]);
  53.  
  54. void read_passenger(struct Bus info[], struct Passenger customer[]);
  55.  
  56. void print_passenger(struct Bus info[]);
  57.  
  58. int busCount = 0;
  59. int passengerCount = 0;
  60.  
  61. int main() {
  62.  
  63.     FILE *fp4;
  64.     FILE *fp6;
  65.     FILE *fp8;
  66.     int choice;
  67.     int k, m, i;
  68.     int checker = 0;
  69.     char u[20];
  70.     char p[20];
  71.     char us[20];
  72.     char pa[20];
  73.     struct Bus info[5];
  74.     struct Passenger customer[20];
  75.     struct Employe worker[5];
  76.     struct Ticket t[20];
  77.  
  78.     printf("********** BUS TICKET RESERVATION SERVICE **********");
  79.  
  80.  
  81.     printf("1-LOGIN AS ADMINISTRATOR \n2-LOGIN AS PASSENGER\n");
  82.     scanf("%d", &choice);
  83.  
  84.     switch (choice) {
  85.         while (checker != 1) {
  86.             case 1:
  87.                 printf("\nUsername : \n");
  88.             scanf("%s", &u);
  89.             printf("Password : \n");
  90.             scanf("%s", &p);
  91.  
  92.             if (read_EMP_usernameandpassword(worker, u, p)) {
  93.                 printf("1. Display all information of all passengers\n2. Display all passengers which took tickets for a specific bus trip\n3. Cancel a ticket\n4. Print the ticket for a passenger\n0-Return the MENU\n");
  94.                 scanf("%d", &k);
  95.                 switch (k) {
  96.                     case 1:
  97.  
  98.                         read_passenger(info, customer);
  99.  
  100.                         print_passenger(info);
  101.                         break;
  102.                     case 2:
  103.  
  104.                         break;
  105.                     case 3:
  106.                         break;
  107.                     case 4:
  108.                         break;
  109.  
  110.                 }
  111.                 checker = 1;
  112.                 break;
  113.             }
  114.             else {
  115.                 printf("You enter wrong username or password!!!Please try again.");
  116.             }
  117.         }
  118.  
  119.         case 2:
  120.  
  121.             printf("Username : \n");
  122.             scanf("%s", &us);
  123.             printf("Password : \n");
  124.             scanf("%s", &pa);
  125.  
  126.             if (read_PESS_usernameandpassword(customer, us, pa)) {
  127.                 printf("1. Buy a ticket for a trip\n2. Display your online ticket\n3. Change ticket information(For ex trip or seat or bus)\n4. Display available and unavailable seats for a specific bus trip\n5. Search a ticket\n0-Return the MENU\n");
  128.                 scanf("%d", &m);
  129.                 switch (m) {
  130.                     case 1:
  131.                         break;
  132.                     case 2:
  133.                         break;
  134.                     case 3:
  135.                         break;
  136.                     case 4:
  137.                         break;
  138.                     case 5:
  139.                         break;
  140.  
  141.                 }
  142.                 break;
  143.             }
  144.     }
  145.  
  146.  
  147.     return 0;
  148. }
  149.  
  150. int read_EMP_usernameandpassword(struct Employe e[], char u[], char p[]) {
  151.     FILE *fp = fopen("EMP_usernameandpassword.txt", "r");
  152.  
  153.     int check = 0;
  154.     int size = 0;
  155.     while (!feof(fp)) {
  156.         fscanf(fp, "%s %s", e[size].usern, e[size].passw);
  157.         if (strcmp(e[size].usern, u) == 0 && strcmp(e[size].passw, p) == 0) {
  158.             check = 1;
  159.             break;
  160.         }
  161.         size++;
  162.     }
  163.     fclose(fp);
  164.     return check;
  165. }
  166.  
  167. int read_PESS_usernameandpassword(struct Passenger customer[], char us[], char pa[]) {
  168.     FILE *fp = fopen("PASS_usernameandpassword.txt", "r");
  169.     int check = 0;
  170.     int i = 0;
  171.     while (!feof(fp)) {
  172.         fscanf(fp, "%s %s", customer[i].username, customer[i].password);
  173.         if (strcmp(customer[i].username, us) == 0 && strcmp(customer[i].password, pa) == 0) {
  174.             check = 1;
  175.             break;
  176.             i++;
  177.         }
  178.     }
  179.     fclose(fp);
  180.     return check;
  181. }
  182.  
  183. void read_passenger(struct Bus info[], struct Passenger customer[]) {
  184.     FILE *fp1 = fopen("Name_Surname_Seat.txt", "r");
  185.     FILE *fp2 = fopen("Line_Date_Time.txt", "r");
  186.  
  187.     busCount = 0;
  188.     while (!feof(fp2)) {
  189.         fscanf(fp2, "%d %s %d %d %d %d %d", &info[busCount].id, info[busCount].bustripname, &info[busCount].date.tripday,
  190.                &info[busCount].date.tripmonth, &info[busCount].date.tripyear, &info[busCount].time.hours, &info[busCount].time.minute);
  191.         busCount++;
  192.     }
  193.     fclose(fp2);
  194.  
  195.     passengerCount = 0;
  196.     while (!feof(fp1)) {
  197.         fscanf(fp1, "%s %s %d %d", customer[passengerCount].custname, customer[passengerCount].custsurname, &customer[passengerCount].busId,
  198.                &customer[passengerCount].seat);
  199.         passengerCount++;
  200.     }
  201.     fclose(fp1);
  202.  
  203.     int k = 0;
  204.     for (k = 0; k < busCount; k++) {
  205.         int l = 0, m = 0;
  206.         for (m = 0; m < passengerCount; m++) {
  207.             if (customer[m].busId == info[k].id) {
  208.                 info[k].customer[l] = customer[m];
  209.                 l++;
  210.             }
  211.         }
  212.     }
  213. }
  214.  
  215. void print_passenger(struct Bus info[]) {
  216.     int i=0;
  217.     printf("*****INFORMATION OF ALL PASSENGER*****\n");
  218.     for (i = 0; i < 5; i++) {
  219.         printf("NAME : %s \nSURNAME : %s \nSEAT : %d ", info[i].customer[i].custname, info[i].customer[i].custsurname,
  220.                info[i].customer[i].seat);
  221.         printf("\nTRIP NAME : %s\nTRIP DATE : %d.%d.%d\nTRIP TIME : %d:%d\n\n", info[i].bustripname,
  222.                info[i].date.tripday, info[i].date.tripmonth, info[i].date.tripyear, info[i].time.hours,
  223.                info[i].time.minute);
  224.         i++;
  225.     }
  226. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement