Oct 11, 2016 at 11:37pm UTC
i am new to programming. i was given an assignment where we had to write a code in which we had to make an airline reservation system where a user could choose from 5 options:
1.reserve a seat
2.change a seat
3.cancel a seat
4.seek help(provide roll number and name to obtain seat number)
5.exit program
The problem i am facing is that i can store the name and roll number of an individual and reserve a seat against it but when someone else enters his name and roll number it replaces the previous persons details and so when someone seeks help the program does not return the value. I tried to make a structure and pass it in an array so that each persons details gets stored in it but it did not work. Help me please.
[code]
#include <iostream>
#include <iomanip>
using namespace std;
struct passinfo
{
string firstname;
string lastname;
int rollnumber;
int rowno;
int colno;
};
template<int counter>
void reservation(char BorE, passinfo (&passengers[counter]),string arry[10][4]) //,string arry2[10][4],string arry3[10][4])
{
cout<<"Enter B for business class or E for economy class: ";
cin>>BorE;
{
cout<<"Please enter your first name: ";
cin>>passengers.firstname;
cout<<"Please enter your last name: ";
cin>>passengers.lastname;
cout<<"Please enter your roll number: ";
cin>>passengers.rollnumber;
if(BorE == 'B')
{
cout<<setw(10)<<"Current seating plan of business class"<<endl;
char * ROWS[] = {"A1", "A2", "A3"," ", "B4", "B5", "B6", "B7", "B8", "B9", "B10"};
char * column[] = {"column1", "column2", "column3", "column4"};
int i;
for (i = 0; i < 4; i++) cout << setw(10) << column[i];
for (i = 0; i < 1; i++) cout << endl << ROWS[i];
{
for(int row=0; row<1;row++)
for(int col=0; col < 4; col++)
cout<<setw(5)<<arry[row][col]<<" ";
}
for (i = 1; i < 2; i++) cout << endl << ROWS[i];
{
for(int row=1; row<2;row++)
for(int col=0; col < 4; col++)
cout<<setw(5)<<arry[row][col]<<" ";
}
for (i = 2; i < 3; i++) cout << endl << ROWS[i];
{
for(int row=2; row<3;row++)
for(int col=0; col < 4; col++)
cout<<setw(5)<<arry[row][col]<<" ";
cout<<endl;
}
cout<<"*=Available seat"<<" "<<"o=reserved seat";
cout<<endl;
cout<<"Please enter row number";
cin>>passengers.rowno;
cout<<"Please enter column number: ";
cin>>passengers.colno;
for(int row=passengers.rowno;row<=passengers.rowno;row++)
{
for(int col=passengers.colno;col<=passengers.colno;col++)
arry[row][col]='o';
}
cout<<"Dear"<<" "<<passengers.firstname<<" "<<passengers.lastname<<","<<"Seat number"<<" "<<passengers.rowno<<"."<<passengers.colno<<" "<<"has successfully been reserved"<<endl<<endl;
for (i = 0; i < 4; i++) cout << setw(10) << column[i];
for (i = 0; i < 1; i++) cout << endl << ROWS[i];
{
for(int row=0; row<1;row++)
for(int col=0; col < 4; col++)
cout<<setw(5)<<arry[row][col]<<" ";
}
for (i = 1; i < 2; i++) cout << endl << ROWS[i];
{
for(int row=1; row<2;row++)
for(int col=0; col < 4; col++)
cout<<setw(5)<<arry[row][col]<<" ";
}
for (i = 2; i < 3; i++) cout << endl << ROWS[i];
{
for(int row=2; row<3;row++)
for(int col=0; col < 4; col++)
cout<<setw(5)<<arry[row][col]<<" ";
cout<<endl<<endl;
}
}
if(BorE == 'E')
{
cout<<setw(10)<<"Current seating plan of Economy class"<<endl;
char * ROWS[] = {"A1", "A2", "A3","B4", "B5", "B6", "B7", "B8", "B9", "B10"};
char * column[] = {"column1", "column2", "column3", "column4"};
int i;
for (i = 0; i < 4; i++) cout << setw(10) << column[i];
for (i = 3; i < 4; i++) cout << endl << ROWS[i];
{
for(int row=3; row<4;row++)
for(int col=0; col < 4; col++)
cout<<setw(5)<<arry[row][col]<<" ";
}
for (i = 4; i < 5; i++) cout << endl << ROWS[i];
{
for(int row=4; row<5;row++)
for(int col=0; col < 4; col++)
cout<<setw(5)<<arry[row][col]<<" ";
}
for (i = 5; i < 6; i++) cout << endl << ROWS[i];
{
for(int row=5; row<6;row++)
for(int col=0; col < 4; col++)
cout<<setw(5)<<arry[row][col]<<" ";
}
for (i = 6; i < 7; i++) cout << endl << ROWS[i];
{
for(int row=6; row<7;row++)
for(int col=0; col < 4; col++)
cout<<setw(5)<<arry[row][col]<<" ";
}
for (i = 7; i < 8; i++) cout << endl << ROWS[i];
{
for(int row=7; row<8;row++)
for(int col=0; col < 4; col++)
cout<<setw(5)<<arry[row][col]<<" ";
}
for (i = 8; i < 9; i++) cout << endl << ROWS[i];
{
for(int row=8; row<9;row++)
for(int col=0; col < 4; col++)
cout<<setw(5)<<arry[row][col]<<" ";
}
for (i = 9; i < 10; i++) cout << endl << ROWS[i];
{
for(int row=9; row<10;row++)
for(int col=0; col < 4; col++)
cout<<setw(4)<<arry[row][col]<<" ";
cout<<endl;
}
cout<<"*=Available seat"<<" "<<"o=reserved seat";
cout<<endl;
cout<<"Please enter row number";
cin>>passengers.rowno;
cout<<"Please enter column number: ";
cin>>passengers.colno;
for(int row=passengers.rowno;row<=passengers.rowno;row++)
{
for(int col=passengers.colno;col<=passengers.colno;col++)
arry[row][col]='o';
}
cout<<"Dear"<<" "<<passengers.firstname<<" "<<passengers.lastname<<","<<"Seat number"<<" "<<passengers.rowno<<"."<<passengers.colno<<" "<<"has successfully been reserved"<<endl<<endl;
for (i = 0; i < 4; i++) cout << setw(10) << column[i];
for (i = 3; i < 4; i++) cout << endl << ROWS[i];
{
for(int row=3; row<4;row++)
for(int col=0; col < 4; col++)
cout<<setw(5)<<arry[row][col]<<" ";
}
for (i = 4; i < 5; i++) cout << endl << ROWS[i];
{
for(int row=4; row<5;row++)
for(int col=0; col < 4; col++)
cout<<setw(5)<<arry[row][col]<<" ";
}
for (i = 5; i < 6; i++) cout << endl << ROWS[i];
{
for(int row=5; row<6;row++)
for(int col=0; col < 4; col++)
cout<<setw(5)<<arry[row][col]<<" ";
}
for (i = 6; i < 7; i++) cout << endl << ROWS[i];
{
for(int row=6; row<7;row++)
for(int col=0; col < 4; col++)
cout<<setw(5)<<arry[row][col]<<" ";
}
for (i = 7; i < 8; i++) cout << endl << ROWS[i];
{
for(int row=7; row<8;row++)
for(int col=0; col < 4; col++)
cout<<setw(5)<<arry[row][col]<<" ";
}
for (i = 8; i < 9; i++) cout << endl << ROWS[i];
{
for(int row=8; row<9;row++)
for(int col=0; col < 4; col++)
cout<<setw(5)<<arry[row][col]<<" ";
}
for (i = 9; i < 10; i++) cout << endl << ROWS[i];
{
for(int row=9; row<10;row++)
for(int col=0; col < 4; col++)
cout<<setw(4)<<arry[row][col]<<" ";
cout<<endl;
}
}
}
}