#include<stdio.h>
#include<stdlib.h>
#define MAX 30
int menu(){
int choice;
printf("1. Add a new reservation\n");
printf("2. Show details of a reservation (given reservation number)\n");
printf("3. Make Payment (given the reservation number and payment amount)\n");
printf("4. Confirm a Reservation (given the reservation number)\n");
printf("5. Quit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
return(choice);
}
int GetReservationNumber(){
int PNR;
do{
printf("Enter reservation number: ");
scanf("%d", &PNR);
if(PNR < 0)
printf("Wrong number\n");
}while(PNR < 0);
return(PNR);
}
void DisplayInfo(char first[][15], char last[][15], int seats[], char destination[][15], float amount[], int confirmed[], int PNR){
printf("\nNAME : %s %s\n", first[PNR], last[PNR]);
printf("# SEATS : %d\n", seats[PNR]);
printf("DESTINATION: %s\n", destination[PNR]);
printf("AMOUNT : %.3f SAR\n", amount[PNR]);
if(confirmed[PNR] == 1)
printf("STATUS : CONFIRMED\n\n");
else
printf("STATUS : UNCONFIRMED\n\n");
}
void AddNew(char first[][15], char last[][15], int seats[], char destination[][15], int n){
printf("Enter first name: ");
scanf("%s", first[n]);
printf("Enter last name: ");
scanf("%s", last[n]);
do{
printf("Enter number of seats: ");
scanf("%d", &seats[n]);
if(seats[n] <= 0)
printf("Wrong number\n");
}while(seats[n] <= 0);
printf("Enter destination: ");
scanf("%s", destination[n]);
}
void GetAmount(float amount[], int PNR){
do{
printf("Enter the amount in SAR: ");
scanf("%f", &amount[PNR]);
if(amount[PNR] <= 0)
printf("Wrong amount\n");
else
printf("Thank you\n\n");
}while(amount[PNR] <= 0);
}
main(){
int seats[MAX], confirmed[MAX], n, reserved[MAX], i, PNR, choice;
float amount[MAX];
char first[MAX][15], last[MAX][15], destination[MAX][15];
FILE *inp, *outp;
inp = fopen("E:reservat.txt", "r");
if(inp == NULL){
printf("Cannot open the file ");
exit(1);
}
for(i = 0; i < MAX; i++)
reserved[i] = 0;
n = 0;
for(int status = fscanf(inp, "%s", first[n]);
status != EOF;
status = fscanf(inp, "%s", first[n])){
fscanf(inp, "%s%d%s%f%d", last[n], &seats[n], destination[n], &amount[n], &confirmed[n]);
reserved[n] = 1;
n++;
}
fclose(inp);
do{
choice = menu();
switch(choice){
case 1: if(n < MAX){
AddNew(first, last, seats, destination, n);
reserved[n] = 1;
printf("Thank You, your reservation number is %d (Unconfirmed)\n\n", n);
n++;
}else
printf("The arrays are full\n\n");
break;
case 2: PNR = GetReservationNumber();
if(reserved[PNR] == 1)
DisplayInfo(first, last, seats, destination, amount, confirmed, PNR);
else
printf("Not Found\n\n");
break;
case 3: PNR = GetReservationNumber();
if(reserved[PNR] == 1)
GetAmount(amount, PNR);
else
printf("Not Found\n\n");
break;
case 4: PNR = GetReservationNumber();
if(reserved[PNR] == 1){
confirmed[PNR] = 1;
printf("The reservation is confirmed\n\n");
}else
printf("Not Found\n\n");
break;
case 5: outp = fopen("a:reservation.txt", "w");
for(i = 0; i < n; i++)
fprintf(outp, "%s %s %d %s %.3f %d\n", first[i], last[i], seats[i], destination[i], amount[i], confirmed[i]);
fclose(outp);
printf("Thank You..");
break;
default: printf("Wrong Choice\n\n");
}
}while(choice != 5);
priya123 0 Newbie Poster
WolfPack 491 Posting Virtuoso Team Colleague
priya123 0 Newbie Poster
priya123 0 Newbie Poster
WolfPack 491 Posting Virtuoso Team Colleague
WolfPack 491 Posting Virtuoso Team Colleague
priya123 0 Newbie Poster
priya123 0 Newbie Poster
WolfPack 491 Posting Virtuoso Team Colleague
priya123 0 Newbie Poster
WolfPack 491 Posting Virtuoso Team Colleague
priya123 0 Newbie Poster
Salem 5,199 Posting Sage
priya123 0 Newbie Poster
priya123 0 Newbie Poster
Salem 5,199 Posting Sage
Salem 5,199 Posting Sage
priya123 0 Newbie Poster
priya123 0 Newbie Poster
Dave Sinkula 2,398 long time no c Team Colleague
himanjim 0 Junior Poster in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.