Computing.Net > Forums > Programming > C++ Program Help!

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

C++ Program Help!

Reply to Message Icon

Name: Alpha-v
Date: November 29, 2003 at 02:41:08 Pacific
OS: Window ME
CPU/Ram: Pentium III/64Ram
Comment:

(Airline Reservations System) A small airline has just purchased a computer for its new automated reservations system. You have been asked to program the new new system. You are to write a program to assign seats on each flight of the airline's only plane (capacity: 10 seats).

I have to write a program that display the following menu of alternatives-Please type 1 for "First Class" and Please type 2 for "Economy". If the person types 1, your program should assign a seat in the first class section (seat 1-5). If the person types 2, your program should assign a seat in the economy section (seat 6-10). Your program should print a boarding pass indicating the person's seat number and whether it is in the first class or economy section of the plane.

Use a single-subscripted array to represent the seating chart of the plane. Initialize all the elements of the array to 0 to indicate that all seats are empty. As each seat is assigned, set the corresponding elements of the array to 1 to inicate that the seat is no longer available.

Your program should, of course, never assign a seat that has already been assigned, When the first class section is full, your program should ask the person if it is acceptable to be placed in the economy section (and vice versa). If yes, then make the appropriate seat assignment. If no, then print the message "Next flight leaves in 3 hours."

In in the process of declaring and initializing variables and arrays. This is what I have to so far. Tell me if I'm on the right track.

#include <iostream>

using std::cin;
using std::cout;
using std::endl;


#include <iomanip>

using std::setw:

int main()
{

const int seats[10] = { 0 };
int options;
int firstClass = 1;
int economy = 2;
int passenger = 0

while ( passenger < 10 ) {

cout << " Please type 1 for "First Class" or type 2 for "Ecnonomy" ";
cin >> options;

if ( options == 1 >



Sponsored Link
Ads by Google

Response Number 1
Name: Ronin1
Date: November 29, 2003 at 13:14:34 Pacific
Reply:

Sort of. Don't declare seats as const since you will need to change it's data as seats are filled. I'd use a char for options since the program will go loopy if someone enters a letter for "options" with the way it is now.

Your menu is ok... I guess you meant cout << "Please type 1 for \"First Class\" or type 2 for \"Second Class\""; ?

I'd test specific elements of seats directly for seeing if it's filled or not. Just keep a basic index for first class, and add an offset to index for second class.

HTH


0

Response Number 2
Name: Alpha-v
Date: December 2, 2003 at 02:45:08 Pacific
Reply:

I updated my code below. Sofar I a) declared and initialzed my variables and array b) began my loop. So now I am requesting ticket preference and starting the If statement. If the user types 1 then assign to first class and if they type 2 then assign economy seat. I know I need some statements within those if statements to set the conditions and also a to set the elements of the array to 1 to indicate that a seat is no longer available. Please help! I been spending days trying to figure this part out.

#include <iostream>

#include <iomanip>

using std::cout;

using std::endl;

using std::cin;

int main()

{

int seats[10] = { 0 };

int firstClass = 1;

int economy = 6;

int passenger = 0;

int selection;

char answer;

for (int i = 1; i < 10; i++)

{

cout << endl;

cout << "Please type 1 for \"First Class\"" << endl;

cout << "Please type 2 for \"Economy\"" << endl;

cin >> selection;

if ( selection == 1 ) {

if (firstClass <= 5 {

cout << "Your first class seat is: " << firstClass << endl;

first++;
}

else if (firstClass >= 5) {

cout << "The first class section is full."
<< "Would you like to sit in the economy
<< "section (Y or N)?";
cin >> answer;

if (selection == 2)

{

cout << "Your economy seat is: " << economy << endl;

economy++

}


I drew out the job specifications, as how I want to do this program, but I am not sure how to get there. Here it is below:

Declare & initialize variables
Initialize array

Begin loop

Request ticket preference

Case First Class

If seat FC available

Assign First Class Seat

Else

If would like economy

If Economy Seat available

Assign Economy Seat

Else

Suggest next flight

End if

Else

Break

End if

End if

Case Economy

If seat available

Assign Economy Seat

Else

If would like First Class

If First Class Seat available

Assign First Class Seat

Else

Suggest next flight

End if

Else

Break

End if

End if

End Case

End Program



0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: C++ Program Help!

C programming help www.computing.net/answers/programming/c-programming-help-/6364.html

C Programing HELP www.computing.net/answers/programming/c-programing-help/13625.html

c program help www.computing.net/answers/programming/c-program-help/8129.html