[prog] Re: C++
wolf
wolf at wolfrising.net
Tue Jan 20 11:31:31 EST 2004
sorry about that, fixed the initializing of the array...
here's the question from the book to help explain what I'm trying to
figure out : )
new code follows after : )
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"
and now the code : )
#include <iostream>
#include <cctype>
using namespace std;
int main()
{
int seat [10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int first_class = 0;
int economy = 5;
char Choice;
int i = 0;
char option;
cout << "Please enter 1 for First Class or enter 2 for Economy: ";
cin >> Choice;
cout << endl;
if (Choice == 1)
switch (Choice)
{
case '1':
cout << "Your choice is 1.";
break;
case '2':
cout << "Your choice is 2.";
break;
// default:
}
for ( i = 0; i < 5; i++)
{
cout << "Your assigned seat is: \t" << i << endl;
first_class++;
if (seat [4] == 1)
cout << endl;
cout << "This section is full. Would you like to be assigned to";
cout << " the economy section? (Y or N)" << endl;
cout << endl;
}
for (i = 5; i < 9; i ++)
{
cout << endl;
cout <<" Your assigned seat is: " << i << endl;
economy++;
if (seat [9] == 1)
cout << endl;
cout << "This section is full. Would you like to be assigned to ";
cout << "the economy section? Y or N: " ;
cin >> option;
if (option == 1)
switch (option)
{
case 'Y':
case 'y':
cout << "Your choice is Y. ";
break;
case 'N':
case 'n':
cout << "Your choice is N. ";
break;
//default:
}
}
cout << "Next flight leaves in 3 hours." << endl;
return 0;
}
On Jan 20, 2004, at 10:31 AM, Sue Stones wrote:
> On Wed, 21 Jan 2004 02:08 am, wolf wrote:
>> It's not doing quite what it's supposed to but here's the modified
>> version based on everyone's
>> suggestions so far : ) It's most definitely better than it was before
>
> What is it doing, and what is it suposed to?
>
>> : ) Thanks!
>>
>> #include <iostream>
>>
>> #include <cctype>
>>
>> using namespace std;
>>
>> int main()
>>
>> {
>>
>> int seat [10];
>
> Note you are not now initialising this array at all, it could contain
> anything, including all 1's
>
> sue
> _______________________________________________
> Programming mailing list
> Programming at linuxchix.org
> http://mailman.linuxchix.org/mailman/listinfo/programming
>
More information about the Programming
mailing list