All pastes #273343 Raw Edit

Anonymous

public cpp v1 · immutable
·published 2006-12-09 20:39 UTC
rendered paste body
#include <iostream>#include <iomanip>#include <string>#include <cctype>#include <cstring>using namespace std;const char empty = '*';const char filled = 'X';void populate(char seats[][6]);void outputSeating(char seats[][6]);void getTicket(char seats[][6]);int main(){    // array declaration	char seats[13][6];	// Populate array	populate(seats);	// Display initial (empty) seating	outputSeating(seats);	// Get user input for seating / ticket assignment	getTicket(seats);	return 0;}/* Populates seat array with empty seats for initial output */void populate(char seats[][6]){	// populate array with empty seats	for (int r = 0; r < 13; r++)		for (int c = 0; c < 6; c++)			seats[r][c] = empty;}/* Shows seating chart to the user with updated seating information */void outputSeating(char seats[][6]){	// Output array	cout << endl;	for (int r = 0; r < 13; r++)	{		if (r == 0)		{			for (int c = 0; c < 6; c++)			{				if (c == 0)					cout << "Isle \t";				// Make room for Stewardess to serve drinks				if (c == 3)					cout << "\t " << static_cast<char>(c+65) << " ";				else					cout << " " << static_cast<char>(c+65) << " ";			}			cout << endl;		}		// Show user row #1 -- seats[0][c]		cout << "Row " << r+1 << "\t";				for (int c = 0; c < 6; c++)		{			// Make room for Stewardess to serve drinks			if (c == 2)				cout << " " << seats[r][c] << "\t";			else				cout << " " << seats[r][c] << " ";		}				cout << endl;	}}/*	Processes customers ticket based on seating type, whether or not they're a smoker, and	allows them to select which seat they'd like to sit in, so long as it's not already taken */void getTicket(char seats[][6]){	bool done = false;                	do	{	        	// Local variable declaration -- No meaning outside of this function                char seatType = ' ', isle = ' ', smoker = ' ';                int row = 0;                char quit = ' ';                		// determine ticket type                do {                        cout << "\nAre you a [F]irst class or [e]conomy passenger? [F/E]: ";			cin >> seatType;		} while ((toupper(seatType) != 'E') && (toupper(seatType) != 'F'));					switch (toupper(seatType))		{			// Economy class ticket			case 'E':				cout << "Would you to be seated in the smoking section? [Y/N]: ";				cin >> smoker;				// Customer wants to sit in smoking section				if (toupper(smoker) == 'Y')				{					cout << "Smoking seats for economy class tickets are rows 8 through 13.\n";					cout << "\nWhere would you like to sit?";					do {                                                cin.clear();                                                cin.ignore(100, '\n');                                		cout << "\nEnter row number: " ;                                		cin >> row;					} while((row <= 0) || (row > 13));	                                do {                                                cin.clear();                                                cin.ignore(100, '\n');                     	                        cout << "\nEnter isle letter: ";                        	                cin >> isle;					} while(isle == ' ');					// Ensure seat is empty					if (seats[row -1][static_cast<int>(toupper(isle) - 65)] == empty)					{						// Ensure seat request within valid range based on ticket type						if (row < 8 || row > 13)						{							cout << "Invalid seat selection!\n";							cout << "Smoking seats for economy class tickets are rows 8 through 13!\n";							break;						}						// Process seat request, label as filled for future customers						else							for (int r = 7; r < 14; r++)								for (int c = 0; c < 6; c++)									seats[row - 1][static_cast<int>(toupper(isle) - 65)] = filled;					}				}				// Customer wants to sit in NON-smoking section				else				{					cout << "Non-smoking seating for economy class tickets are rows 3 through 7.\n";					cout << "\nWhere would you like to sit?";					do {						cin.clear();                                		cin.ignore(100, '\n');	                                  	cout << "\nEnter row number: " ;						cin >> row;					} while((row <= 0) || (row > 13));                        	        do {                                                cin.clear();                                                cin.ignore(100, '\n');                                     	        cout << "\nEnter isle letter: ";	                                        cin >> isle;        	                        } while(isle == ' ');					// Ensure seat is empty					if (seats[row -1][static_cast<int>(toupper(isle) - 65)] == empty)					{						// Ensure seat range is avlid						if (row < 3 || row > 7)						{							cout << "Invalid seat selection!\n";							cout << "Non smoking seats for economy class tickets are rows 3 through 7!\n";							break;						}						// Process seat request, label as filled for future customers						else							for (int r = 2; r < 7; r++)								for (int c = 0; c < 6; c++)									seats[row - 1][static_cast<int>(toupper(isle) - 65)] = filled;					}					// Seat must be filled, inform user to make a different selection					else					{						cout << "Seat is currently filled! Please refere to the seating chart!\n";						break;					}				}				break;			// First class ticket			case 'F':				cout << "\nWhere would you like to sit?";                                do {                                        cin.clear();                                        cin.ignore(100, '\n');                                  	cout << "\nEnter row number: " ;					cin >> row;				} while((row <= 0) || (row > 13));                                do {                                        cin.clear();                                        cin.ignore(100, '\n');                                             cout << "\nEnter isle letter: ";                                        cin >> isle;                                } while(isle == ' ');                                				if (seats[row - 1][static_cast<int>(toupper(isle) - 65)] == empty)				{					// Ensure seat request within valid range based on ticket type					if (row > 2)					{						cout << "First class seats are the first two rows!\n";						break;					}					// Process seat request, label as filled for future customers					else						for (int r = 0; r < 2; r++)							for (int c = 0; c < 6; c++)								seats[row - 1][static_cast<int>(toupper(isle) - 65)] = filled;									}				// Seat must be filled, inform user to make a different selection				else				{					cout << "Seat is currently filled! Please refer to the seating chart!\n";					break;				}				break;			// Invalid ticket type			default:				cout << "No such ticket type as \" " << seatType << " \"!\n";				break;		}		// Output updated seating chart now that customer has made a selection		outputSeating(seats);				// Determine whether customer would like to quit the program		do {                        cin.clear();                        cin.ignore(100, '\n');                        cout << "\nWould you like to quit? [Y/N]: ";                        cin >> quit;                } while ((toupper(quit) != 'Y') && (toupper(quit) != 'N'));		if (toupper(quit) == 'Y')			done = true;                cin.clear();                cin.ignore(100, '\n'); // Chop off any leftover input                        	} while (!done);}