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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
|
#include <iostream>
using namespace std;
//Function Declarations
void seating (int,int,char seat[13][13]);
int main ()
{
int k,l,z=0,x=0;
char y=0,ttype,sent=y,seat[13][13];
//Initialize the array; All empty seats.
for (int i=12;i>=0;--i)
{
for (int j=5;j>=0;--j)
{
seat[i][j]='*';
}
}
//Get Ticket Type
cout<<"Welcome.\n";
error0:
cout<<"Please enter your ticket type \n[F for First Class ; B for Business Class; E for Economy Class] \n[F/B/E] : ";
cin >> ttype;
cout <<"\nYou have ";
switch (ttype)
{
case 'F' :
case 'f' :
{
cout<<"first class ticket.";
k=0;
l=1;
break;
}
case 'B' :
case 'b' :
{
cout<<"business class ticket.";
k=2;
l=6;
break;
}
case 'E' :
case 'e' :
{
cout<<"economy class ticket.";
k=7;
l=12;
break;
}
default:
{
system ("cls");
cout<<"\nYou have entered an invalid ticket type. Please try again.\n";
goto error0;
}
}
//Display seats available
error1:
cout << "\n'*' are seats available to you.";
seating (k,l,seat);
//Get desired seat (row)
cout<< "Enter your desired seat: [eg 1A] : ";
cin >>x;
x-=1;
if (cin.fail()||x<k||x>l)
{
cin.clear(); //clear error flag created by cin.fail... not too sure how it works.. found online
cin.ignore();
//cin.fail leaves the input in memory and the bad input will be used again unless cin.ignore is used, came with cin.clear
error2:
system ("cls");
cout<<"The seat you have chosen is invalid or unavailable. Please choose another.";
goto error1;
}
//Get desired seat (column)
cin>>y;
switch (y)
{
case 'A' :
case 'a' :
{
z=0;
break;
}
case 'B' :
case 'b' :
{
z=1;
break;
}
case 'C' :
case 'c' :
{
z=2;
break;
}
case 'D' :
case 'd' :
{
z=3;
break;
}
case 'E' :
case 'e' :
{
z=4;
break;
}
case 'F' :
case 'f' :
{
z=5;
break;
}
default:
{goto error2;}
}
// Occupy seat
if(seat[x][z]!='X')
{seat[x][z]='X';}
else
{goto error2;}
//comfirmation report
system ("cls");
cout<<"\nYou seat["<<x+1<<static_cast<char>(toupper(y))<<"] has been succesfully booked.\nThis is the current seating for your flight.";
seating(0,12,seat);
//continue?
error3:
cin.ignore(1000,'\n');
cout<<"\nDo you wish to continue?\n[y/n] : ";
cin>>sent;
if (sent=='Y'||sent=='y')
{
system ("cls");
cout<<"You have chosen to continue.\n";
goto error0;
}
else if (sent=='n'||sent=='N')
{
cout <<"Thank you for using our service. Have a nice day.\n";
}
else
{
cout<< "\nInvalid selection.";
goto error3;
}
system ("pause");
return 0;
}
//Function Definitions
void seating (int k,int l,char seat[13][13])
{
cout <<"\n\t\tA\tB\tC\t\tD\tE\tF\n";
for (int i=k;i<=l;++i)
{
if (i<9)
{cout << "Row ["<<i+1<<"]\t\t";}
else if (i>=9)
{cout << "Row ["<<i+1<<"]\t";}
for (int j=0;j<=5;++j)
{
cout<<seat[i][j]<<"\t";
if (j==2)
{cout<<"\t";}
}
cout<<endl;
}
}
| |