#include #include #include using namespace std; struct Staff { string account; string password; string fullName; int gender; }; bool Compare(string s1, string s2) { if (s1 == s2) return true; return false; } void ReadStaff(ifstream& fin, Staff& a) { getline(fin, a.account,'\n'); getline(fin, a.password, '\n'); getline(fin, a.fullName, '\n'); fin >> a.gender; } void StaffLogin(Staff *&a,int &n) { ifstream fin; fin.open("C:\\Users\\pc\\Desktop\\Staff.txt",ios::in); if (!fin.is_open()) return; fin >> n; a = new Staff[n]; for (int i = 0; i < n; i++) { fin.ignore(); ReadStaff(fin, a[i]); } fin.close(); string username; cout << "Enter username: "; cin >> username; for (int i = 0; i < n; i++) { if (Compare(username, a[i].account)) { string password; do { cout << "Enter password: "; cin >> password; if (!Compare(password, a[i].password)) { cout << "Wrong password please enter password again!" << endl; } } while (!Compare(password, a[i].password)); if (a[i].gender == 1) cout << "Welcome MR. " << a[i].fullName << "!" << endl; else cout << "Welcome MISS. " << a[i].fullName << "!" << endl; } } } int main() { Staff* a=nullptr; int n=0; StaffLogin(a, n); delete[]a; return 0; }