[prog] Re: C++
wolf
wolf at wolfrising.net
Tue Jan 20 18:57:54 EST 2004
here's the newest version - -I think it's getting closer but still
doesn't work quite correctly. here's the code, at the bottom of the
page I included the sample question I'm working since I changed
my strategy away from using switch
#include <iostream>
using namespace std;
int main()
{
int section;
int seats[10];
int FC =1; // first class
int EC = 6; // economy
int people;
{
cout << "Please enter 1 for First Class or enter 2 for Economy: " ;
cin >> section ;
if ( section == 1 ) {
if ( FC <= 10 && seats[ FC ] == 0 ) {
cout << "First Class Seat #" + FC << endl;
seats[ FC++ ] = 1;
people++;
}
else if ( FC > 10 && EC <= 5 ) {
cout << "First Class is full. Would Economy be okay?(1 for Yes :
2 for No): " << endl;
cin >> section;
}
else
cout << "Next flight leaves in 3 hours." << endl;
}
else if ( section == 2 ) {
if ( seats[ EC ] == 0 && EC <= 5 ) {
cout << "Economy Seat #" + EC << endl;
seats[ EC++ ] = 1;
people++;
}
else if ( EC > 5 && FC <= 10 ) {
cout << "Economy is full. Would First Class be okay?(1 for Yes :
2 for No): " << endl;
cin >> section;
}
else
cout << "Next flight leaves in 3 hours.";
}
else
cout << "Invalid input.";
}
{
if ( section == 1 ) {
cout << "Your seat assignment is " << EC << endl ;
seats[ EC++ ] = 1;
}
else { // section is 2
cout << "Your seat assignment is " << FC << endl ;
seats[ FC++ ] = 1;
}
++people;
}
{
cout << "Next flight leaves in 3 hours.";
}
}
A small airline has just purchased a computer for its new automated
reservations system. You have been asked to program the new system. You
are to write a program that assigns seats
on each fight of the airline's only plane which has a capacity of 10
people.
You program should display the following menu of alternatives - Please
type 1 for first class and Please type 2 for economy class. If the
person types 1 your program should assign
a seat in the first class section which are seats 1-5. If the person
types 2 your program
should assign a seat in the economy section seats 6-10. Your program
should print
a boarding pass indicating the person's seat number and whether it is
in first class or
economy.
use a single subscripted array to represent the seating chart of the
plane. Initialize all the elements of the array to 0 to indicate all
seats are empty. As each seat is assigned set the corresponding
elements of the array to 1 to indicate that the seat is no longer
available.
your program should never assign a seat that is already 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 ( or vice versa) if yes then make
the appropriate assignment if not
print the message "Next flight leaves in 3 hours"
More information about the Programming
mailing list