C++ program help needed

unsunghero2314

Junior Member
Joined
Sep 4, 2009
Messages
3
Reaction score
0
hey all.

i'm currently working on an airline reservation program.
only managed to complete 2 parts. i'm lost with the remaining 2 parts (cancel & display seat arrangement).
anyone wanna give it a shot? will post the file here.

_____________________________________________________________
PART 1

(a) Display a menu system as follows :-
? If choice is A, Add a person to the flight or waiting list.(see part 2)
? If choice is B, Remove a passenger from the flight. (see part 4)
? If choice is C, Display Seating arrangment (see part 5)
? If choice is D, Display the waiting list
? If choice is E, Quit from the system.

(b) Create your own screen design or use this design as follows:

GREEN DOT AIRLINE ON LINE RESERVATION SYSTEM
(A) Reserve a seat
(B) Cancel a reservation
(C) Display Seating arrangement
(D) View Waiting List
(E) Quit
>> Enter Choice : XX

PART 2. Reserve a seat

When a customer want to reserve a seat, you should do following:

a) Request for passenger’s name
b) Ask passenger’s preference: smoking or non-smoking
c) Check if any seats of selected category (smoking/non-smoking) are available. If
yes, allocate a seat and printout a ticket.
d) If seats in selected area is not available, check if there is any seat in the other
section, if yes, ask whether customer wants to be in the other section. If yes,
allocate the seat, and printout a ticket. Otherwise, put him/her in the waiting list,
and display a message like “Sorry, the flight is full. You will be put in the waiting
list….”
e) Enter date of transaction.

PART 3. Cancel a reservation

When a customer wants to cancel a reservation, the program will do following.
a) Request for the passenger’s name
b) Search the seating chart for passenger’s name and delete it.
c) If the waiting list is empty, update the array so that the seat is available for the
other bookings
d) If the waiting list is not empty, get the first person in the waiting list who opted
for the same seating category, and allocate the seat to them. Print out the ticket.

PART 4. Display Seat arrangement

Create your own output screen design to show the seating arrangement.
Non smoking area:

=====================
Seat1 Seat2
Row 1: Mr. John Mrs John
Row 2 Mary Lim Jeffery Tan
Row 3 Gottman Bernald
Row 4 Thomas Dennis

Smoking area:
=====================
Seat1 Seat2
Row 1: Tina T Ashly
Row 2: Clinton Hoffman

_____________________________________________________________

MANY THANKS :))
let me know of any hints/ tips.

cheers guys.
Marco
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,301
PART 3. Cancel a reservation

When a customer wants to cancel a reservation, the program will do following.
a) Request for the passenger’s name
b) Search the seating chart for passenger’s name and delete it.
c) If the waiting list is empty, update the array so that the seat is available for the
other bookings
d) If the waiting list is not empty, get the first person in the waiting list who opted
for the same seating category, and allocate the seat to them. Print out the ticket.

Since you have already completed PART 2, that means you should already have a means of keeping track in an array of any previous reservations for any seat T. Also you ought to be having a means of storing which passenger is currently allocated to which seat.

THis part, all you need to do is search through your passenger list to see if there is such an existing passenger. If yes, proceed to the next step of checking of the awaiting list is empty or not. If empty, then remove the passenger P from your passenger list since the intention is to cancel the reservation. If the waiting list is not empty, then choose the first one, remove it from the waiting list and placed into the reserved seat that was allocated to passenger P previously.

Now there is a part not mentioned properly in the question, what if the passenger name given is in the waiting list, what should the program do ? Ignore it, or remove from the waiting list too ?

PART 4. Display Seat arrangement

Create your own output screen design to show the seating arrangement.
Non smoking area:

=====================
Seat1 Seat2
Row 1: Mr. John Mrs John
Row 2 Mary Lim Jeffery Tan
Row 3 Gottman Bernald
Row 4 Thomas Dennis

Smoking area:
=====================
Seat1 Seat2
Row 1: Tina T Ashly
Row 2: Clinton Hoffman

_____________________________________________________________

So what is so difficult about this part ? Iterate through your passengers list and print out the layout. You have to consider how are you storing the passenger list ? Is there any order to it ? Does element S in the passenger array represent certain row ? Think about it.
 

unsunghero2314

Junior Member
Joined
Sep 4, 2009
Messages
3
Reaction score
0
the current codes.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
#include <string.h>
void displaywelcome();
void displayops();
void reserve();
void cancel();
void displayseat();
void waitlist();
void exit();

char customers[12][50]={"\0","\0","\0","\0","\0","\0","\0","\0","\0","\0","\0","\0"};
int smoking[2][2] = {-1,-1,-1,-1};
int non_smoking[4][2] = {-1,-1,-1,-1,-1,-1};
int main()
{
displaywelcome();
puts("\n");
displayops();
}

void displaywelcome()
{
puts("-----------------------Welcome to The System---------------------------");
puts("Version: 0.1");
puts("\n");
}

void displayops()
{
char option;

printf("GREEN DOT AIRLINE ON LINE RESERVATION SYSTEM\n");
printf("*********************************************\n");
printf("\n(A) \tReserved a seat\n");
printf("(B) \tCancel a reservation\n");
printf("(C) \tDisplay Seating arrangement\n");
printf("(D) \tView Waiting List\n");
printf("(E) \tQuit\n");
printf("\n>>Enter Choice : ");

scanf(" %c", &option);

option = toupper(option);
switch(option)
{
case'A': reserve();
break;
case 'B': cancel();
break;
case 'C': displayseat();
break;
case 'D': waitlist();
break;
case 'E': exit();
break;
default:
printf("Invalid selection.Try again\n\n");
return displayops();
}

}

void reserve()
{
int count=0, pref;
int flag;

for(count = 0;count < 12;count++)
{
if(strcmp(customers[count],"\0")==0)
break;
}

if (count <12)
{
printf("Please enter name:");
flushall();
gets(customers[count]);

printf("\nPress 1 for Smoking Seat\nPress 2 for Non-Smoking seat : ");
scanf("%d",&pref);

if(pref==1)
{
flag=0;
for(int row=0;row<2 && flag==0;row++)
{
for(int col=0;col<2 && flag==0;col++)
{
if(smoking[row][col]==-1)
{
printf("Here is your smoking seat\n");
flag=1;
}

}
}

if(flag==0)
{
printf("Sorry there is no more seat available\n"
"You will be put on the waiting list");
}

}
else if(pref==2)
{
flag=0;
for(int row=0;row<4 && flag==0;row++)
{
for(int col=0;col<2;col++)
{
if (non_smoking[row][col]==-1)
{
printf("Here is your Non-Smoking seat\n");
flag=1;
}
if(flag==0)
{
printf("Sorry there is no more seat available\n"
"You will be put on the waiting list");
}
}
}
}
else
{
printf("Invalid entry\n");
}

}
else
{
printf("Sorry there is no more seats available.");
}
return;
}
void cancel()
{

char cancelname[50];

printf("Please enter name to cancel reservation : \n");
gets (cancelname);
for(int row=0;row<4;row++)
{
for(int col=0;col<2;col++)
{
if(strcmp(non_smoking[row][col].

}
void displayseat()
{
printf("test");
}
void waitlist()
{
printf("test");
}
void exit()
{
system("exit");
}
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,301
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
#include <string.h>
void displaywelcome();
void displayops();
void reserve();
void cancel();
void displayseat();
void waitlist();
void exit();
....

Please use the CODE markup to encapsulate your codes. By the way, I find some missing information like where do you determine where is the smoking and non-smoking seats ? How many rows of seats should there be ?


I wouldn't go through all the codes, below are some of my findings

  • Other than the "customers" array, you should also keep a list of awaiting customers.
  • Instead of using the NULL character, which is normally NULL or 0 to indicate the end of the customer list, why don't you just keep a global counter ?
  • When you display to the customer that he/she is placed on the waiting list, where is the waiting list to keep track of the customer waiting for which seat ?
  • Why are you using literal 12 all over the code ? If I want you to change to 20 seats, how many times do you need to change the code ?
  • The way you are keeping track of smoking/non-smoking seats is weird. What is your layout for smoking and non-smoking region ?
  • Does the question mention how should the layout of the seats be ?
 
Important Forum Advisory Note
This forum is moderated by volunteer moderators who will react only to members' feedback on posts. Moderators are not employees or representatives of HWZ Forums. Forum members and moderators are responsible for their own posts. Please refer to our Community Guidelines and Standards and Terms and Conditions for more information.
Top