Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- /* run this program using the console pauser or add your own getch, system("pause") or input loop */
- struct Tripdate {
- int tripday;
- int tripmonth;
- int tripyear;
- };
- struct Bustime {
- int hours;
- int minute;
- };
- struct Passenger {
- char custname[50];
- char custsurname[50];
- char custpassword;
- char custusername[50];
- int seat;
- char username[20];
- char password[20];
- int busId;
- };
- struct Bus {
- int id;
- int busplate;
- char bustripname[50];
- int ticketprice;
- struct Tripdate date;
- struct Bustime time;
- struct Passenger customer[5];
- };
- struct Ticket {
- struct Passenger customer[20];
- struct Bus info[5];
- struct Bustime time;
- struct Tripdate date;
- };
- struct Employe {
- char usern[20];
- char passw[20];
- };
- //decleration of functions
- struct Passenger customer[20];
- struct Ticket t[20];
- int read_EMP_usernameandpassword(struct Employe e[], char u[], char p[]);
- int read_PESS_usernameandpassword(struct Passenger customer[], char us[], char pa[]);
- void read_passenger(struct Bus info[], struct Passenger customer[]);
- void print_passenger(struct Bus info[]);
- int busCount = 0;
- int passengerCount = 0;
- int main() {
- FILE *fp4;
- FILE *fp6;
- FILE *fp8;
- int choice;
- int k, m, i;
- int checker = 0;
- char u[20];
- char p[20];
- char us[20];
- char pa[20];
- struct Bus info[5];
- struct Passenger customer[20];
- struct Employe worker[5];
- struct Ticket t[20];
- printf("********** BUS TICKET RESERVATION SERVICE **********");
- printf("1-LOGIN AS ADMINISTRATOR \n2-LOGIN AS PASSENGER\n");
- scanf("%d", &choice);
- switch (choice) {
- while (checker != 1) {
- case 1:
- printf("\nUsername : \n");
- scanf("%s", &u);
- printf("Password : \n");
- scanf("%s", &p);
- if (read_EMP_usernameandpassword(worker, u, p)) {
- 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");
- scanf("%d", &k);
- switch (k) {
- case 1:
- read_passenger(info, customer);
- print_passenger(info);
- break;
- case 2:
- break;
- case 3:
- break;
- case 4:
- break;
- }
- checker = 1;
- break;
- }
- else {
- printf("You enter wrong username or password!!!Please try again.");
- }
- }
- case 2:
- printf("Username : \n");
- scanf("%s", &us);
- printf("Password : \n");
- scanf("%s", &pa);
- if (read_PESS_usernameandpassword(customer, us, pa)) {
- 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");
- scanf("%d", &m);
- switch (m) {
- case 1:
- break;
- case 2:
- break;
- case 3:
- break;
- case 4:
- break;
- case 5:
- break;
- }
- break;
- }
- }
- return 0;
- }
- int read_EMP_usernameandpassword(struct Employe e[], char u[], char p[]) {
- FILE *fp = fopen("EMP_usernameandpassword.txt", "r");
- int check = 0;
- int size = 0;
- while (!feof(fp)) {
- fscanf(fp, "%s %s", e[size].usern, e[size].passw);
- if (strcmp(e[size].usern, u) == 0 && strcmp(e[size].passw, p) == 0) {
- check = 1;
- break;
- }
- size++;
- }
- fclose(fp);
- return check;
- }
- int read_PESS_usernameandpassword(struct Passenger customer[], char us[], char pa[]) {
- FILE *fp = fopen("PASS_usernameandpassword.txt", "r");
- int check = 0;
- int i = 0;
- while (!feof(fp)) {
- fscanf(fp, "%s %s", customer[i].username, customer[i].password);
- if (strcmp(customer[i].username, us) == 0 && strcmp(customer[i].password, pa) == 0) {
- check = 1;
- break;
- i++;
- }
- }
- fclose(fp);
- return check;
- }
- void read_passenger(struct Bus info[], struct Passenger customer[]) {
- FILE *fp1 = fopen("Name_Surname_Seat.txt", "r");
- FILE *fp2 = fopen("Line_Date_Time.txt", "r");
- busCount = 0;
- while (!feof(fp2)) {
- fscanf(fp2, "%d %s %d %d %d %d %d", &info[busCount].id, info[busCount].bustripname, &info[busCount].date.tripday,
- &info[busCount].date.tripmonth, &info[busCount].date.tripyear, &info[busCount].time.hours, &info[busCount].time.minute);
- busCount++;
- }
- fclose(fp2);
- passengerCount = 0;
- while (!feof(fp1)) {
- fscanf(fp1, "%s %s %d %d", customer[passengerCount].custname, customer[passengerCount].custsurname, &customer[passengerCount].busId,
- &customer[passengerCount].seat);
- passengerCount++;
- }
- fclose(fp1);
- int k = 0;
- for (k = 0; k < busCount; k++) {
- int l = 0, m = 0;
- for (m = 0; m < passengerCount; m++) {
- if (customer[m].busId == info[k].id) {
- info[k].customer[l] = customer[m];
- l++;
- }
- }
- }
- }
- void print_passenger(struct Bus info[]) {
- int i=0;
- printf("*****INFORMATION OF ALL PASSENGER*****\n");
- for (i = 0; i < 5; i++) {
- printf("NAME : %s \nSURNAME : %s \nSEAT : %d ", info[i].customer[i].custname, info[i].customer[i].custsurname,
- info[i].customer[i].seat);
- printf("\nTRIP NAME : %s\nTRIP DATE : %d.%d.%d\nTRIP TIME : %d:%d\n\n", info[i].bustripname,
- info[i].date.tripday, info[i].date.tripmonth, info[i].date.tripyear, info[i].time.hours,
- info[i].time.minute);
- i++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement