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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
#include <stdio.h>
#include <string.h>
#include<iomanip>
#include <iostream>
#include <cstdlib>
using namespace std;
void getData(string &namez, char& ticketType, int& row, int& column);
struct flight_date
{
int day;
int month;
int year;
};
struct flight_time
{
int hour;
int minute;
};
struct flight_information {
char flight_num[4];
struct flight_date date;
struct flight_time time;
char gate[2];
} flight_info;
void
getData(string &namez, char& ticketType, int& row, int& column)
{
cout << "The airplane has 13 rows, with six seats in each row. " << endl;
cout << "Enter ticket type,\n"
<< "F for first class, \n"
<< "E for economy class:" << endl;
cin >> ticketType;
ticketType = static_cast<char>(toupper(ticketType));
switch(ticketType)
{
case 'F':
cout << "Row 1 and 4 are first class,\n" ;
break;
case 'E':
cout << "row 8 through 13 are economy class." << endl;
break;
}
cout << "Enter the row number you want to sit: " << endl ;
cin >> row;
cout << "Enter the seat number (from A to E). " << endl;
cin >> column;
cout<< "enter passenger name:"<<endl;
cin >> namez;
//getline(cin, namez); // could also work
column = static_cast<char>(toupper(column));
}
void printForm(const string &namez, int form[][5], int row, char column)
{
int i, j;
cout << "* indicates that the seat is available; " << endl;
cout << setw(14) << "A" << setw(8) << "B" << setw(8) << "C"
<< setw(8) << "D" << setw(8) << "E"<< endl;
for(i = 0; i < 13; i++)
{
cout << left << setw(3) << "Row " << setw(2)<< i+1 ;
for(j = 0; j < 5; j++)
{
if(i == row - 1 && j == static_cast<int>(column)-65)
cout << right << setw(8) <<namez;
else
cout << right << setw(8) << "*";
}
cout << endl;
}}
int main ()
{
int option;
do
{
// option = 0;
string namez;
int roww;
int seat[13][5] = {0};
int i,j,choice,num_of_seat,empty_seat=0,row,col;
char name[20],column;
char opselect,ticketType;
cout<<"\t\tFJ513 Seat Reservation"<<endl;
cout<<endl;
cout<<"\t1.Display Aircraft Seating Plan"<<endl;
cout<<"\t2.Reserve a Seat"<<endl;
cout<<"\t3.Retrieve Seat Information"<<endl;
cout<<"\t4.Quit"<<endl;
cout<<endl;
cout<<"enter your choice"<<endl;
cout << __FILE__ << __LINE__ << " Reading option, option was = " << option << endl;
cin >> hex >> option;
cout << __FILE__ << __LINE__ << " OPTION = " << option << endl;
// cout << __FILE__ << __LINE__ << " OPTION = " << option << endl;
switch (option)
{
case 1:
printf("\tA\tB\tC\tD\tE\n");
for (row=0; row<13; row++)
{
printf("\nRow %d", row+1);
for (col=0; col<5; col++)
{
printf("\tx", seat[row][col]);
}
}
// system ("pause");
break;
case 2:
getData(namez, ticketType, row,col);
break;
case 3:
printForm(namez, seat, row,col);
break;
default:
cout << __FILE__ << __LINE__ << " OPTION = " << option << endl;
cout<<"invalid choice"<< endl;
exit(-1);
/*
if(option != 4)
{
cout<<"invalid choice"<< endl;
}
*/ //Not needed
}
} while(option != 4);
// system ("pause");
return 0;
}
|