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: 1 #11

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

Input: 1 #11

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

Comments

@alikzalikz
Copy link
Owner

alikzalikz commented Jan 24, 2023

Input 1. Reserve a Seat

RailwayCli/main.cpp

Lines 301 to 305 in 021ebb1

case e1:
{
AddSeat();
break;
}

so, we need to reserve a new seat between 10 compartments & 6 Seats on every of them

RailwayCli/main.cpp

Lines 140 to 181 in 021ebb1

void AddSeat()
{
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 (Availabe(0) != "0")
{
person.compartment = Availabe(0);
person.seat = Availabe(1);
File << person.name << ", " << person.family << ", " << person.compartment << ", " << person.seat << endl;
File.close();
cout << "\n-- Ticket Added Successfully! --" << endl;
ShowTicket(fullName);
}
else
{
cout << "\n-- Train Was Full! --\n\n\n";
}
}
}

i create an object of Person for working with input data
first we most initial an object from ifstream and ofstream on the fstream Library

give person.name & person.family from client and make those ::tolower

put name and family together and make new string fullName
maybe you question why we do that??
for better query on database Train.txt
cause data save like this:

sara, irani, 9, 6 
ehsan , reziea, 10, 1

when we gonna know about this name is record on database or not
we must use this format <person.name>, <person.family> for search

then pass fullName to bool HaveTicket(string searchContent) function

RailwayCli/main.cpp

Lines 16 to 34 in 021ebb1

bool HaveTicket(string searchContent)
{
ifstream inFile("Train.txt");
string line;
bool state = false;
while (getline(inFile, line))
{
if (line.find(searchContent) != string::npos)
{
state = true;
return true;
}
}
if (!state)
{
return false;
}
}

that a bool function, so, return true false value
if data base have same name and family call another method whose name void ShowTicket(string personFullName)

RailwayCli/main.cpp

Lines 82 to 120 in 021ebb1

void ShowTicket(string personFullName)
{
ifstream inFile("Train.txt");
string line;
while (getline(inFile, line))
{
if (line.find(personFullName) != string::npos)
{
cout << "---------TICKET----------" << endl;
int countComma = 0;
cout << "Name: ";
for (int i = 0; i < line.size(); i++)
{
if (line[i] != ',' && line[i] != ' ')
{
cout << line[i];
}
if (line[i] == ',')
{
countComma++;
cout << endl;
if (countComma == 1)
{
cout << "Family: ";
}
if (countComma == 2)
{
cout << "Compartment: ";
}
if (countComma == 3)
{
cout << "Seat: ";
}
}
}
cout << "\n-------------------------\n\n\n";
}
}
}

that output something like this

-- Ticket Added Successfully! --
---------TICKET----------
Name: sara
Family: irani
Compartment: 9
Seat: 6
-------------------------
This was referenced Jan 24, 2023
@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