Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input: 2 #12

Open
Tracked by #10
alikzalikz opened this issue Jan 24, 2023 · 0 comments
Open
Tracked by #10

Input: 2 #12

alikzalikz opened this issue Jan 24, 2023 · 0 comments
Labels
documentation Improvements or additions to documentation

Comments

@alikzalikz
Copy link
Owner

Input: 2. Reserve a Compartment

RailwayCli/main.cpp

Lines 306 to 310 in 021ebb1

case e2:
{
AddCompartment();
break;
}

void AddCompartment()

RailwayCli/main.cpp

Lines 183 to 226 in 021ebb1

void AddCompartment()
{
cout << endl;
Person person;
ofstream File("Train.txt", ios::app);
ifstream InFile("Train.txt");
cin.ignore();
cout << "Enter Passenger name: ";
getline(cin, person.name);
transform(person.name.begin(), person.name.end(), person.name.begin(), ::tolower);
cout << "Enter Passenger family: ";
getline(cin, person.family);
transform(person.family.begin(), person.family.end(), person.family.begin(), ::tolower);
string fullName = person.name + ", " + person.family;
if (HaveTicket(fullName))
{
cout << "\n-- Passenger Have Ticket Already! --" << endl;
ShowTicket(fullName);
}
else
{
if (AvailabeCompartment() != "0")
{
person.compartment = AvailabeCompartment();
for (int seatsI = 0; seatsI < 6; seatsI++)
{
person.seat = Availabe(1);
File << person.name << ", " << person.family << ", " << person.compartment << ", " << person.seat << endl;
}
File.close();
cout << "\n-- Tickets Added Successfully! --" << endl;
ShowTicket(fullName);
}
else
{
cout << "\n-- Don't Have Empty Compartment! --\n\n\n";
}
}
}

string AvailabeCompartment()

RailwayCli/main.cpp

Lines 67 to 80 in 021ebb1

string AvailabeCompartment()
{
string compartmentNum = "0";
for (int compartmentsI = 1; compartmentsI <= 10; compartmentsI++)
{
string str = " " + to_string(compartmentsI) + ", ";
if (!HaveTicket(str))
{
compartmentNum = to_string(compartmentsI);
break;
}
}
return compartmentNum;
}

string Availabe(int state)

RailwayCli/main.cpp

Lines 36 to 65 in 021ebb1

string Availabe(int state)
{
string stateNum = "0";
for (int compartmentsI = 1; compartmentsI <= 10; compartmentsI++)
{
for (int seatsI = 1; seatsI <= 6; seatsI++)
{
string str = " " + to_string(compartmentsI) + ", " + to_string(seatsI);
if (!HaveTicket(str))
{
if (state == 0)
{
stateNum = to_string(compartmentsI);
break;
}
if (state == 1)
{
stateNum = to_string(seatsI);
break;
}
}
}
if (stateNum != "0")
{
break;
}
}
return stateNum;
}

@alikzalikz alikzalikz mentioned this issue Jan 24, 2023
8 tasks
@alikzalikz alikzalikz added the documentation Improvements or additions to documentation label Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant