Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 12-09-2004, 09:06 PM   #1
Member (4 bit)
 
Join Date: Dec 2004
Posts: 8
C++ program help

for this program i have to design an airline reservation program. i need to use a single array to reserve the seats. there are 10 seats available. 0-4 are first class, and 5-9 are economy. if one seat gets reserved the program should place a 1 on the seat (array) number...then it prints a voucher telling the seat number and if thier in first class or economy. the program shouldnt allow a reservation for a seat thats taken, it should print seat it taken. and when all the seats are filled up.....program should print next flight is in three hours.....im having trouble with this...heres what i did so far....can anyone help?
this is what i have so far.....

#include

int seats[ 9 ];

int main()
{

int choice;
int count;

std::cout << "Welcome to the airline reservations system.\n";
std::cout << "Please type 1 for First Class or type 2 for Economy.\n";
std::cin >> choice;

if ( choice == 1 )
{
seats[ 0 ] = 1;
std::cout << "Your are seat Number:\n" ;
std::cout << "Your seat is in FIRST CLASS, have a nice flight.\n";
}

if ( choice == 2 )
{
seats[ 5 ] = 1;
std::cout << "You are seat number:\n" ;
std::cout << "Your seat is in the ECONOMY SECTION, have a nice flight.\n";
}

return 0;
}
tominator is offline   Reply With Quote
Old 12-14-2004, 07:31 AM   #2
Member (7 bit)
 
shaticus's Avatar
 
Join Date: May 2004
Posts: 103
Your going to need a some sort of loop for it(while,for). what loop depends on if you have any style guidelines for the program. You will also have to check if the seat is taken before putting anyone in it(if statement).

#include

int seats[ 9 ];

int main()
{

int choice;
int count;
int i = 0;
std::cout << "Welcome to the airline reservations system.\n";
while(seats[i] > 0 && seats[i] < 9) // checks to make sure there is an open seat
if(seats[i] == 9) // if all seats are full display this message else continue execution.
std::cout <<"Next flight leaves in three hours.\n";
else
{
std::cout << "Please type 1 for First Class or type 2 for Economy.\n";
std::cin >> choice;

if ( choice == 1 )
{
i = 0;
while(seats[i] > 0 && i < 5)
i++;
if(seats[i] == 5)
std::cout << " Sorry, All first class seats are full.\n";
else
{
seats[ i ] = 1;
std::cout << "Your are seat Number:\n" ;
std::cout << "Your seat is in FIRST CLASS, have a nice flight.\n";
}
}

if ( choice == 2 )
{
i =5;
while(seats[i] > 0 && i < 9)
i++;
if(seats[i] == 9)
std::cout << " Sorry, All economy class seats are full.\n";
else
{
seats[ i ] = 1;
std::cout << "You are seat number:\n" ;
std::cout << "Your seat is in the ECONOMY SECTION, have a nice flight.\n";
}
}
}
return 0;
}

Last edited by shaticus; 12-14-2004 at 07:39 AM.
shaticus is offline   Reply With Quote
Old 12-14-2004, 07:34 AM   #3
Member (7 bit)
 
shaticus's Avatar
 
Join Date: May 2004
Posts: 103
One last thing, i would break up this program into a few different functions.
One function for reserving first class seat & one for second class seats.
Then main would be responsible for reading the choice, and you could go in to a switch statement or just add function calls and call your program good.

Adding the functions should make debugging any problems you have a little easier as you will be able to tell what function the problem is in.
shaticus is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:13 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2