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 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
|
#include <iostream>
#include <iomanip>
#include <string>
#include <cctype>
using namespace std;
int Superior[4][6]={0};
int Economy[6][8]={0};
const int srow= 4 , scol= 6;
const int erow= 6 , ecol= 8;
const double sadult = 45.00 , schild = 22.50 ;
const double eadult = 25.00 , echild = 12.00 ;
void printSuperior(int Superior[4][6]);
string Superior_seats[srow][scol] = {
{"A01", "A02", "A03", "A04", "A05", "A06"},
{"B01", "B02", "B03", "B04", "B05", "B06"},
{"C01", "C02", "C03", "C04", "C05", "C06"},
{"D01", "D02", "D03", "D04", "D05", "D06"}
};
string error="";
struct Sbooking
{
string s_seat;
string s_age;
double price;
};
Sbooking s[srow][scol];
void initialize_S (Sbooking s[srow][scol])
{
for(int i=0;i<srow;i++)
{
for(int j=0;j<scol;j++)
{
s[i][j].s_seat="";
s[i][j].s_age="";
s[i][j].price=0;
}
}
}
bool verify_Superiorage(const string &ages)
{
error="";
if(ages != "A" && ages != "C")
{
error="Invalid age Please re-enter again.";
return false;
}
return true;
}
void get_Superiorage(Sbooking s[srow][scol],const string &seats)
{
string ages="";
do
{
if(error!="")
cout<<error<<endl;
cout<<"Enter Adult('A')/Child('C') : ";cin>>ages;
transform(ages.begin(),ages.end(),ages.begin(),toupper);
cout<<endl;
}
while(!verify_Superiorage(ages));
for(int i=0 ; i<srow ; i++)
{
for(int j=0 ; j<scol ; j++)
{
if(Superior_seats[i][j] == seats)
{
s[i][j].s_age=ages;
if(s[i][j].s_age == "A")
{
s[i][j].price=sadult;
}
else if(s[i][j].s_age == "C")
{
s[i][j].price=schild;
}
}
}
}
}
bool verify_Superiorseat(Sbooking s[srow][scol],const string &seats)
{
bool valid = false;
error="";
for(int i= 0 ; i<srow ; i++)
{
for(int j= 0 ; j<scol ; j++)
{
if(Superior_seats[i][j] == seats)
{
if(s[i][j].s_seat == "")
{
s[i][j].s_seat = Superior_seats[i][j];
Superior[i][j] =1;
valid = true;
}
else
{
error="This seat has been taken";
return false;
}
}
}
}
if(!valid)
{
error="Invalid seat ID please re-enter again.";
return false;
}
return true;
}
string get_Superiorseat(Sbooking s[srow][scol],int &seat_require)
{
string seats="";
for(int k=0 ; k<seat_require ; k++)
{
do
{
if(error!="")
cout<<error<<endl;
error="";
cout<<"Please select your seat ID : ";cin>>seats;
}
while(!verify_Superiorseat(s,seats));
get_Superiorage(s,seats);
}
return seats;
}
bool verify_seat_require(int seat_require)
{
bool valid = false;
error="";
if(seat_require <=(srow*scol) && seat_require >= -1)
{
return true;
}
else
{
error="Invalid seat requirement.";
return false;
}
return true;
}
int superior_seatrequire()
{
int seat_require=0;
do
{
if(error!="")
cout<<error<<endl;
cout<<"How many seat you required: ";cin>>seat_require;
}
while(!verify_seat_require(seat_require));
return seat_require;
}
void sticket(Sbooking s[srow][scol] , int seat_require , const string seats)
{
string superior_age="";
string superior_sit="";
int i=0, tnum=1000 ;
double s_price=0;
for(i=0;i<seat_require;i++)
{
for(int a=0 ; a<srow ; a++)
{
for(int b=0 ; b<scol ; b++)
{
if(s[a][b].s_seat == seats)
{
superior_sit = s[a][b].s_seat;
superior_age = s[a][b].s_age;
s_price = s[a][b].price;
}
}
}
cout<<"Seat ID : "<<superior_sit<<endl;
cout<<"Adult(A)/Child(C) : "<<left<<setw(22)<<superior_age<<endl;
cout<<"Price : "<<fixed<<setprecision(2)<<"RM"<<s_price<<endl;
}
}
int main()
{
int seat_require=0;
initialize_S (s);
seat_require = superior_seatrequire();
string seats = get_Superiorseat(s,seat_require);
sticket(s , seat_require , seats);
system("pause");
}
|