All pastes #757008 Raw Edit

seats.cpp

public cpp v1 · immutable
#757008 ·published 2007-10-31 22:08 UTC
rendered paste body
#include <iostream>using namespace std;#define SEATS_PER_SECTION 5#define NUMBER_OF_SECTIONS 3int checkSeats( const int*, const int );int main(){        int seats[NUMBER_OF_SECTIONS][SEATS_PER_SECTION], numSelection, seatUsed;        char *sections[] = {                "First",                "Economy",                "Baggage"        };        char selection;        // Initialize array        memset( seats, '\0', sizeof( seats ) );        do {                cout << "Which class of seating would you like (enter a number 1 through " << NUMBER_OF_SECTIONS << ")?" << endl;                cin >> numSelection;        } while( numSelection < 1 || numSelection > NUMBER_OF_SECTIONS );        // Convert to 0 based offset        do {                seatUsed = checkSeats( seats[ numSelection - 1 ], SEATS_PER_SECTION );                if( seatUsed ){                        cout << "You have been placed in " << sections[ numSelection - 1 ] << " Class seat number " << seatUsed << "." << endl;                        cout << "Thanks for flying!" << endl;                        break;                } else {                        if( numSelection < NUMBER_OF_SECTIONS ){                                do {                                        cout << "All " << sections[ numSelection - 1 ] << " Class seats are taken!  Would you like a seat in " << sections[ numSelection ] << " Class? (y/n)?";                                        cin >> selection;                                } while( selection != 'y' && selection != 'n' );                                if( selection == 'y' ){                                        numSelection++;                                } else {                                        break;                                }                        } else {                                cout << "It appears that there are no more seats available." << endl;                                break;                        }                }        } while( numSelection < NUMBER_OF_SECTIONS );}int checkSeats( const int* section, const int section_seat_count  ){        int i, seatFound = 0;        for( i = 0; i < section_seat_count; i++ ){                if( section[i] == 0 ){                        seatFound = ( i + 1 );                        break;                }        }        return( seatFound );}