Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<iomanip>
- #include<vector>
- #include<iomanip>
- #include<string>
- using namespace std;
- struct Account {
- vector<string> user;
- vector<string> password;
- };
- struct Role {
- vector<string> user;
- vector<string> namework;
- };
- struct Account_to_role {
- vector<string> user;
- vector<string> chucnang;
- };
- bool test_account_to_login(Account &acc, Role &role, string &a, string &b,string &c);
- bool logintk(Account &acc, Role &role, string &a, string &b, string &c);
- void allocation(Account &acc, Account_to_role &acc_role, Role &role);
- bool captk(Account &acc, Account_to_role &acc_role, Role &role, string &a, string&b);
- bool resetpassword(Account &acc);
- bool for_admin(Account &acc, Account_to_role &acc_role, Role &role, string &a, string &b, string &c);
- bool phanvungtk(Account &acc, Account_to_role &acc_role, Role &role, string &a, string &b, string &c);
- bool forstaff(Account &acc, Account_to_role &acc_role, Role &role);
- bool test_user(Account &acc, string testuser);
- bool test_user_to_delete(Account &acc,Account_to_role &acc_role,Role &role, string testuser);
- bool delete_account(Account &acc, Account_to_role &acc_role, Role &role);
- bool information_acc_present(Account &acc, Account_to_role &acc_role, Role &role,string a);
- bool information_list_acc(Account &acc, Account_to_role &acc_role, Role &role);
- bool serch_account(Account &acc, Account_to_role &acc_role, Role &role);
- int main() {
- bool dk;
- Account acc;
- Role role;
- Account_to_role acc_role;
- allocation(acc, acc_role, role);
- string a, b, c;
- do {
- do {
- dk = logintk(acc, role, a, b, c);
- } while (dk == false);
- dk = phanvungtk(acc, acc_role, role, a, b, c);
- } while (dk == false);
- system("pause");
- return 0;
- }
- bool phanvungtk(Account &acc, Account_to_role &acc_role, Role &role, string &a, string &b,string &c ) {
- system("cls");
- cout << c << endl;
- if (c == "storemanager") {
- return for_admin(acc, acc_role, role, a, b, c);
- }
- else if (c == "staff") {
- return forstaff(acc, acc_role, role);
- }
- else {
- cout << 3 << endl;
- }
- }
- bool test_account_to_login(Account &acc, Role &role, string &a, string &b,string &c) {
- for (int j = 0;j < acc.user.size();j++) {
- if (a == acc.user[j] && b == acc.password[j]) {
- c = role.user[j];
- return 1;
- }
- }
- return 0;
- }
- bool logintk(Account &acc, Role &role, string &a, string &b, string &c) {
- system("cls");
- cout << " LOGIN with your account " << endl;
- cout << "Nhap user: ";
- getline(cin, a);
- cout << "Nhap password: ";
- getline(cin, b);
- return test_account_to_login(acc, role, a, b,c);
- }
- void allocation(Account &acc, Account_to_role &acc_role, Role &role) {
- acc.user.push_back("admin");
- acc.password.push_back ( "12345");
- acc.user.push_back("staff");
- acc.password.push_back("12345");
- acc.user.push_back("customer");
- acc.password.push_back("12345");
- acc_role.user.push_back ("quantrivien");
- acc_role.chucnang.push_back("storemanager");
- acc_role.user.push_back("nhanvien");
- acc_role.chucnang.push_back("storemanager");
- acc_role.user.push_back("khachhang");
- acc_role.chucnang.push_back("customer");
- role.user.push_back ("storemanager");
- role.namework.push_back("quan li nhan vien");
- role.user.push_back("staff");
- role.namework.push_back("nhan vien ban hang");
- role.user.push_back("customer");
- role.namework.push_back("khach hang");
- }
- bool captk(Account &acc, Account_to_role &acc_role, Role &role, string &a, string&b) {
- _flushall;
- system("cls");
- cout << "Nhap user: ";
- string testuser;
- getline(cin, testuser);
- if (test_user(acc, testuser) == false) {
- cout << "Account da ton tai.";
- cout << "Lua chon: 1.nhap lai 2.logout ";
- int m;
- cin >> m;
- cin.ignore(1);
- switch (m) {
- case 1: return 1;
- case 2: return 0;
- default: return 1;
- }
- }
- acc.user.push_back(testuser);
- _flushall;
- cout << "Cap password: ";
- string pass1;
- getline(cin, pass1);
- acc.password.push_back(pass1);
- _flushall;
- cout << "Chon loai account: 1.admin 2.nhanvien 3.khachhang ";
- int z;
- cin >> z;
- cin.ignore(1);
- switch (z) {
- case 1: {
- acc_role.user.push_back("quantrivien");
- acc_role.chucnang.push_back("storemanager");
- role.user.push_back("storemanager");
- role.namework.push_back("quan li nhan vien");
- break;
- }
- case 2: {
- acc_role.user.push_back("nhanvien");
- acc_role.chucnang.push_back("storemanager");
- role.user.push_back("staff");
- role.namework.push_back("nhan vien ban hang");
- break;
- }
- case 3: {
- acc_role.user.push_back("khachhang");
- acc_role.chucnang.push_back("customer");
- role.user.push_back("customer");
- role.namework.push_back("khach hang");
- break;
- }
- default:
- break;
- }
- int k;
- cout << "Cap thanh cong! ";
- cout << " 1.Goback 2.Logout ";
- cin >> k;
- cin.ignore(1);
- switch (k) {
- case 1: return 1;
- case 2: return 0;
- }
- }
- bool resetpassword(Account &acc) {
- bool dk3 ;
- do {
- system("cls");
- cout << "Nhap account can reset: ";
- string nameacc;
- getline(cin, nameacc);
- for (int i = 0;i < acc.user.size();i++) {
- if (nameacc == acc.user[i]) {
- string x;
- cout << "Nhap new password: ";
- getline(cin, x);
- acc.password[i] = x;
- cout << "Success!" << endl;
- return 1;
- }
- }
- cout << "Account ko ton tai.";
- cout << "Lua chon: 1.nhap lai 2.Goback 3.Logout ";
- int m;
- cin >> m;
- cin.ignore(1);
- switch (m) {
- case 1: dk3 = false;break;
- case 2: return 1;
- case 3: return 0;
- default: dk3 = false;break;
- }
- } while (dk3 == false);
- }
- bool for_admin(Account &acc, Account_to_role &acc_role, Role &role, string &a, string &b, string &c ) {
- bool dk2;
- do {
- system("cls");
- cout << "-----------------MENU-------------------" << endl;
- cout << setw(35) << left << "- 1.Cap account" << setw(5)<<right << "-"<< endl;
- cout << setw(35) << left << "- 2.Reset password" << setw(5) <<right <<"-" << endl;
- cout << setw(35) << left << "- 3.Xem thong tin account" << setw(5) <<right<< "-" << endl;
- cout << setw(35) << left << "- 4.Delete account" << setw(5) << right << "-" << endl;
- cout << setw(35) << left << "- 5.Information list acc" << setw(5) << right << "-" << endl;
- cout << setw(35) << left << "- 6.Search information account" << setw(5) << right << "-" << endl;
- cout << setw(35) << left << "- 7.Logout" << setw(5) << right << "-" << endl;
- cout << "----------------------------------------" << endl;
- int r;
- cin >> r;
- cin.ignore(1);
- switch (r) {
- case 1: {
- if (captk(acc, acc_role, role, a, b) == false) return 0;
- else dk2 = true;
- break;
- }
- case 2: if (resetpassword(acc) == true) { dk2 = true;break; }
- else return 0;
- case 3:if (information_acc_present(acc, acc_role, role, a) == true) { dk2 = true;break; }
- else return 0;
- case 4:if (delete_account(acc, acc_role, role) == true) { dk2 = true;break; }
- else return 0;
- case 5:if(information_list_acc(acc, acc_role, role) == true) { dk2 = true;break; }
- else return 0;
- case 6:if (serch_account(acc, acc_role, role) == true) { dk2 = true;break; }
- else return 0;
- case 7: return 0;
- }
- } while (dk2 == true);
- }
- bool forstaff(Account &acc, Account_to_role &acc_role, Role &role) {
- bool dk = true;
- do {
- system("cls");
- cout << "=====================menu=================" << endl;
- cout << "1Them Hang Hoa " << endl;
- cout << "2.Xoa Hang Hoa " << endl;
- cout << "3.Chinh sua Hang Hoa " << endl;
- cout << "4.Tim Kiem Hang Hoa" << endl;
- cout << "5.Thong Ke" << endl;
- int m;
- cout << "Moi nhap lua chon ";
- cin >> m;
- cin.ignore(1);
- switch (m) {
- case 1:cout << "1" << endl;break;
- case 2:cout << "2" << endl;break;
- case 3:cout << "3" << endl;break;
- case 4:cout << "4" << endl;break;
- case 5:cout << "5" << endl;break;
- }
- } while (dk == true);
- return 0;
- }
- bool test_user(Account &acc, string testuser) {
- for (int j = 0;j < acc.user.size();j++) {
- if (testuser == acc.user[j]) return 0;
- }
- return 1;
- }
- bool delete_account(Account &acc, Account_to_role &acc_role, Role &role) {
- bool dk2=true;
- do {
- system("cls");
- cout << "Nhap account can delete: ";
- string nameacc;
- getline(cin, nameacc);
- if (test_user_to_delete(acc,acc_role,role,nameacc) == true) {
- system("cls");
- cout << "Delete Success!";
- int a;
- cout << "Lua chon: 1.Goback 2.logout " ;
- cin >> a;
- cin.ignore(1);
- switch (a)
- {
- case 1: return 1;
- case 2: return 0;
- default:
- return 0;
- }
- }
- else {
- cout << "Account can delete ko ton tai"<<endl;
- int a;
- cout << "Lua chon: 1.Nhap lai 2.Goback 3.Logout ";
- cin >> a;
- cin.ignore(1);
- switch (a)
- {
- case 1: dk2 = false;break;
- case 2: return 1;
- case 3: return 0;
- default:
- return 1;
- }
- }
- } while (dk2==false);
- }
- bool test_user_to_delete(Account &acc, Account_to_role &acc_role, Role &role, string testuser) {
- for ( int i = 0;i < acc.user.size();i++) {
- if (testuser == acc.user[i]) {
- acc.user.erase(acc.user.begin() + i);
- acc.password.erase(acc.password.begin()+i);
- acc_role.user.erase(acc_role.user.begin() + i);
- acc_role.chucnang.erase(acc_role.chucnang.begin() + i);
- role.namework.erase(role.namework.begin() + i);
- role.user.erase(role.user.begin() + i);
- return 1;
- }
- }
- return 0;
- }
- bool information_acc_present(Account &acc, Account_to_role &acc_role, Role &role,string a) {
- int i;
- for ( i = 0;i < acc.user.size();i++) {
- if (acc.user[i] == a) break;
- }
- system("cls");
- cout << "Name account: " << acc.user[i] << endl;
- cout << "Password: " << acc.password[i] << endl;
- cout << "Loai account: " << role.user[i] << endl;
- cout << "Lua chon: 1.Goback 2.Logout " ;
- int n;
- cin >> n;
- cin.ignore(1);
- switch (n)
- {
- case 1: return 1;
- case 2: return 0;
- default:
- return 1;
- }
- }
- bool information_list_acc(Account &acc, Account_to_role &acc_role, Role &role) {
- system("cls");
- cout << "==========List_Account==========" << endl;
- cout <<setw(20)<< "User" <<setw(20)<<"Password" <<setw(20)<<"Loai account"<< endl;
- int x = acc.user.size();
- for (int i = 0;i < x;i++) {
- cout << setw(20) << acc.user[i] << setw(20) << acc.password[i] << setw(20) <<role.user[i] << endl;
- }
- cout << "Tong so account trong he thong: " <<x<<endl;
- cout << "Lua chon: 1.quay lai 2.logout " ;
- int n;
- cin >> n;
- cin.ignore(1);
- switch (n)
- {
- case 1: return 1;
- case 2: return 0;
- default:
- return 1;
- }
- }
- bool serch_account(Account &acc, Account_to_role &acc_role, Role &role) {
- system("cls");
- string a;
- int n=acc.user.size();
- cout << "Nhap vao name account can tim: " ;
- getline(cin, a);
- int i;
- for ( i = 0;i < n;i++) {
- if (a == acc.user[i])break;
- }
- if (i < n) {
- system("cls");
- cout << "Name account: " << acc.user[i] << endl;
- cout << "Pass: " << acc.password[i] << endl;
- cout << "Loai account: " << role.user[i] << endl;
- }
- else cout << "Khong tim thay." << endl;
- cout << "Lua chon: 1.quay lai 2.logout " ;
- int m;
- cin >> m;
- cin.ignore(1);
- switch (m)
- {
- case 1: return 1;
- case 2: return 0;
- default:
- return 1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement