Browse Source

main commented

- main() is mostly/completely commented
- Added error handling for non-expected input for ‘choice’.
Fixing-travis-yml
BinHong Lee 8 years ago
parent
commit
731795da6a
1 changed files with 21 additions and 3 deletions
  1. +21
    -3
      LogInSystem.cpp

+ 21
- 3
LogInSystem.cpp View File

@@ -24,7 +24,7 @@ void chgEmail();
void chgPhoneNo(); void chgPhoneNo();
void quit(); void quit();


//Stacks to store the data
//Stacks to store the users' personal data
stack<Person> users; stack<Person> users;


//Declaration of place holding variables //Declaration of place holding variables
@@ -38,24 +38,33 @@ int wrongPass = 0;


int main() int main()
{ {
//Reading from file to build the database
ifstream fin("database.txt"); ifstream fin("database.txt");
int choice;

while (!fin.eof()) while (!fin.eof())
{ {
//Reading in line-by-line into the placeholding variables
fin >> username >> password >> email >> phoneNo; fin >> username >> password >> email >> phoneNo;

//Create the Person and push it into the stack
Person temp(username, password, email, phoneNo); Person temp(username, password, email, phoneNo);
users.push(temp); users.push(temp);
} }


//Pop off the additional data added into the stack due to the empty line
users.pop(); users.pop();


getOption:
//Display user input options
cout << "Please choose one of the following options :" << endl; cout << "Please choose one of the following options :" << endl;
cout << "Log In - 1" << endl; cout << "Log In - 1" << endl;
cout << "Registration - 2" << endl; cout << "Registration - 2" << endl;
cout << "Exit - 0" << endl; cout << "Exit - 0" << endl;


//Get user input
int choice;
cin >> choice; cin >> choice;

//Switch according to user input
switch (choice) switch (choice)
{ {
case 1: case 1:
@@ -66,16 +75,25 @@ int main()
break; break;
case 0: case 0:
break; break;
default:
//Display error message
cout << "Invalid input. Please try again." << endl;
goto getOption;
} }


//Saving data into file
ofstream fout("database.txt"); ofstream fout("database.txt");


//Check if the stack is empty
while (!users.empty()) while (!users.empty())
{ {
//Move the data into the files each Person per line
fout << users.top().getName() << " " << users.top().getPassword() << " " << users.top().getEmail() << " " << users.top().getPhoneNo() << " " << endl; fout << users.top().getName() << " " << users.top().getPassword() << " " << users.top().getEmail() << " " << users.top().getPhoneNo() << " " << endl;
//Pop the Person out of stack after the data is moved
users.pop(); users.pop();
} }


//End the program
return 0; return 0;
} }




Loading…
Cancel
Save