1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
// Store the data in a two-dimensional array of characters.
// Initially all the elements of the array contain the character -,
// to indicate that the seats are available.
// You already did this
int main()
{
char seats[7][10]={
{' ','1','2','3','4','5','6','7','8','9'},
{'A','-','-','-','-','-','-','-','-','-'},
{'B','-','-','-','-','-','-','-','-','-'},
{'C','-','-','-','-','-','-','-','-','-'},
{'D','-','-','-','-','-','-','-','-','-'},
{'E','-','-','-','-','-','-','-','-','-'},
{'F','-','-','-','-','-','-','-','-','-'}
};
// declare your variables:
char row;
int seat =0 , number = 0;
// set up a while loop to accept user entries, either like
cin >> row, seat, number; // or individually like
cin >> row;
cin>> seat;
cin>> number;
// If you accept a char as the row you'll have to convert it to int for use as an index in your array:
switch (row){
case 'a': // if row is type char, use single quotes, if type string, use double
case' A':
rowint = 1;
break;
case 'b':
case 'B':
rowint = 2;
break;
// etcetera through row 'F'
// you could also check for entry of 'Q' and act accordingly
// any out of range entries should restart the loop
//When a reservation , the program must determine if the requested seats are available.
// will the set of seats needed extend past the end of the row?
bool goodchoice = (seat + number <= 9 )
//user's choice is tentatively okay, but we need to check each seat individually:
If any of the requested seats is already reserved (or the requested seats fall outside the seat plan), reject the reservation
for (int i = seat; i < seat + number -1 && goodchoice; i++)
{ goodchoice = (seats[rowint][i] != 'R'); }
//
If they are available, it must reserve them.
if (goodchoice)
{ // replace the same seats as the previous for statement with 'R';}
//A reservation is made by assigning the character R to the elements in question.
else
{ The entire reservation must be rejected with an appropriate message.}
// The user must enter Q (for the row) to quit the program.
//since we're in a loop the above shouldn't be too difficult. . .
}
|