Advertisement
huynhngochai97bp

Untitled

May 21st, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.09 KB | None | 0 0
  1. #include<iostream>
  2. #include<iomanip>
  3. #include<vector>
  4. #include<iomanip>
  5. #include<string>
  6. using namespace std;
  7. struct Account {
  8. vector<string> user;
  9. vector<string> password;
  10. };
  11. struct Role {
  12. vector<string> user;
  13. vector<string> namework;
  14. };
  15. struct Account_to_role {
  16. vector<string> user;
  17. vector<string> chucnang;
  18. };
  19. bool test_account_to_login(Account &acc, Role &role, string &a, string &b,string &c);
  20. bool logintk(Account &acc, Role &role, string &a, string &b, string &c);
  21. void allocation(Account &acc, Account_to_role &acc_role, Role &role);
  22. bool captk(Account &acc, Account_to_role &acc_role, Role &role, string &a, string&b);
  23. bool resetpassword(Account &acc);
  24. bool for_admin(Account &acc, Account_to_role &acc_role, Role &role, string &a, string &b, string &c);
  25. bool phanvungtk(Account &acc, Account_to_role &acc_role, Role &role, string &a, string &b, string &c);
  26. bool forstaff(Account &acc, Account_to_role &acc_role, Role &role);
  27. bool test_user(Account &acc, string testuser);
  28. bool test_user_to_delete(Account &acc,Account_to_role &acc_role,Role &role, string testuser);
  29. bool delete_account(Account &acc, Account_to_role &acc_role, Role &role);
  30. bool information_acc_present(Account &acc, Account_to_role &acc_role, Role &role,string a);
  31. bool information_list_acc(Account &acc, Account_to_role &acc_role, Role &role);
  32. bool serch_account(Account &acc, Account_to_role &acc_role, Role &role);
  33. int main() {
  34. bool dk;
  35.  
  36. Account acc;
  37. Role role;
  38. Account_to_role acc_role;
  39. allocation(acc, acc_role, role);
  40. string a, b, c;
  41. do {
  42. do {
  43. dk = logintk(acc, role, a, b, c);
  44. } while (dk == false);
  45.  
  46. dk = phanvungtk(acc, acc_role, role, a, b, c);
  47. } while (dk == false);
  48. system("pause");
  49. return 0;
  50. }
  51. bool phanvungtk(Account &acc, Account_to_role &acc_role, Role &role, string &a, string &b,string &c ) {
  52. system("cls");
  53. cout << c << endl;
  54. if (c == "storemanager") {
  55.  
  56. return for_admin(acc, acc_role, role, a, b, c);
  57. }
  58. else if (c == "staff") {
  59. return forstaff(acc, acc_role, role);
  60. }
  61. else {
  62. cout << 3 << endl;
  63. }
  64. }
  65. bool test_account_to_login(Account &acc, Role &role, string &a, string &b,string &c) {
  66. for (int j = 0;j < acc.user.size();j++) {
  67. if (a == acc.user[j] && b == acc.password[j]) {
  68. c = role.user[j];
  69.  
  70. return 1;
  71. }
  72. }
  73. return 0;
  74. }
  75. bool logintk(Account &acc, Role &role, string &a, string &b, string &c) {
  76.  
  77. system("cls");
  78. cout << " LOGIN with your account " << endl;
  79. cout << "Nhap user: ";
  80. getline(cin, a);
  81. cout << "Nhap password: ";
  82. getline(cin, b);
  83. return test_account_to_login(acc, role, a, b,c);
  84. }
  85. void allocation(Account &acc, Account_to_role &acc_role, Role &role) {
  86.  
  87. acc.user.push_back("admin");
  88. acc.password.push_back ( "12345");
  89.  
  90. acc.user.push_back("staff");
  91. acc.password.push_back("12345");
  92.  
  93. acc.user.push_back("customer");
  94. acc.password.push_back("12345");
  95.  
  96. acc_role.user.push_back ("quantrivien");
  97. acc_role.chucnang.push_back("storemanager");
  98.  
  99. acc_role.user.push_back("nhanvien");
  100. acc_role.chucnang.push_back("storemanager");
  101.  
  102. acc_role.user.push_back("khachhang");
  103. acc_role.chucnang.push_back("customer");
  104.  
  105. role.user.push_back ("storemanager");
  106. role.namework.push_back("quan li nhan vien");
  107.  
  108.  
  109. role.user.push_back("staff");
  110. role.namework.push_back("nhan vien ban hang");
  111.  
  112.  
  113. role.user.push_back("customer");
  114. role.namework.push_back("khach hang");
  115. }
  116. bool captk(Account &acc, Account_to_role &acc_role, Role &role, string &a, string&b) {
  117. _flushall;
  118. system("cls");
  119. cout << "Nhap user: ";
  120. string testuser;
  121. getline(cin, testuser);
  122.  
  123. if (test_user(acc, testuser) == false) {
  124. cout << "Account da ton tai.";
  125. cout << "Lua chon: 1.nhap lai 2.logout ";
  126. int m;
  127. cin >> m;
  128. cin.ignore(1);
  129. switch (m) {
  130. case 1: return 1;
  131. case 2: return 0;
  132. default: return 1;
  133. }
  134. }
  135.  
  136.  
  137. acc.user.push_back(testuser);
  138. _flushall;
  139. cout << "Cap password: ";
  140. string pass1;
  141. getline(cin, pass1);
  142. acc.password.push_back(pass1);
  143. _flushall;
  144. cout << "Chon loai account: 1.admin 2.nhanvien 3.khachhang ";
  145. int z;
  146. cin >> z;
  147. cin.ignore(1);
  148. switch (z) {
  149. case 1: {
  150. acc_role.user.push_back("quantrivien");
  151. acc_role.chucnang.push_back("storemanager");
  152.  
  153.  
  154. role.user.push_back("storemanager");
  155. role.namework.push_back("quan li nhan vien");
  156. break;
  157. }
  158. case 2: {
  159.  
  160. acc_role.user.push_back("nhanvien");
  161. acc_role.chucnang.push_back("storemanager");
  162.  
  163. role.user.push_back("staff");
  164. role.namework.push_back("nhan vien ban hang");
  165. break;
  166. }
  167. case 3: {
  168.  
  169. acc_role.user.push_back("khachhang");
  170. acc_role.chucnang.push_back("customer");
  171. role.user.push_back("customer");
  172. role.namework.push_back("khach hang");
  173. break;
  174. }
  175. default:
  176. break;
  177. }
  178.  
  179. int k;
  180. cout << "Cap thanh cong! ";
  181. cout << " 1.Goback 2.Logout ";
  182. cin >> k;
  183. cin.ignore(1);
  184. switch (k) {
  185. case 1: return 1;
  186. case 2: return 0;
  187. }
  188. }
  189. bool resetpassword(Account &acc) {
  190. bool dk3 ;
  191. do {
  192. system("cls");
  193. cout << "Nhap account can reset: ";
  194. string nameacc;
  195. getline(cin, nameacc);
  196. for (int i = 0;i < acc.user.size();i++) {
  197. if (nameacc == acc.user[i]) {
  198. string x;
  199. cout << "Nhap new password: ";
  200. getline(cin, x);
  201. acc.password[i] = x;
  202. cout << "Success!" << endl;
  203. return 1;
  204. }
  205. }
  206. cout << "Account ko ton tai.";
  207. cout << "Lua chon: 1.nhap lai 2.Goback 3.Logout ";
  208. int m;
  209. cin >> m;
  210. cin.ignore(1);
  211. switch (m) {
  212. case 1: dk3 = false;break;
  213. case 2: return 1;
  214. case 3: return 0;
  215. default: dk3 = false;break;
  216. }
  217.  
  218. } while (dk3 == false);
  219.  
  220. }
  221. bool for_admin(Account &acc, Account_to_role &acc_role, Role &role, string &a, string &b, string &c ) {
  222.  
  223. bool dk2;
  224. do {
  225. system("cls");
  226. cout << "-----------------MENU-------------------" << endl;
  227. cout << setw(35) << left << "- 1.Cap account" << setw(5)<<right << "-"<< endl;
  228. cout << setw(35) << left << "- 2.Reset password" << setw(5) <<right <<"-" << endl;
  229. cout << setw(35) << left << "- 3.Xem thong tin account" << setw(5) <<right<< "-" << endl;
  230. cout << setw(35) << left << "- 4.Delete account" << setw(5) << right << "-" << endl;
  231. cout << setw(35) << left << "- 5.Information list acc" << setw(5) << right << "-" << endl;
  232. cout << setw(35) << left << "- 6.Search information account" << setw(5) << right << "-" << endl;
  233. cout << setw(35) << left << "- 7.Logout" << setw(5) << right << "-" << endl;
  234. cout << "----------------------------------------" << endl;
  235. int r;
  236. cin >> r;
  237. cin.ignore(1);
  238. switch (r) {
  239. case 1: {
  240. if (captk(acc, acc_role, role, a, b) == false) return 0;
  241. else dk2 = true;
  242. break;
  243. }
  244. case 2: if (resetpassword(acc) == true) { dk2 = true;break; }
  245. else return 0;
  246. case 3:if (information_acc_present(acc, acc_role, role, a) == true) { dk2 = true;break; }
  247. else return 0;
  248. case 4:if (delete_account(acc, acc_role, role) == true) { dk2 = true;break; }
  249. else return 0;
  250. case 5:if(information_list_acc(acc, acc_role, role) == true) { dk2 = true;break; }
  251. else return 0;
  252. case 6:if (serch_account(acc, acc_role, role) == true) { dk2 = true;break; }
  253. else return 0;
  254. case 7: return 0;
  255. }
  256. } while (dk2 == true);
  257.  
  258. }
  259.  
  260. bool forstaff(Account &acc, Account_to_role &acc_role, Role &role) {
  261. bool dk = true;
  262. do {
  263. system("cls");
  264. cout << "=====================menu=================" << endl;
  265. cout << "1Them Hang Hoa " << endl;
  266. cout << "2.Xoa Hang Hoa " << endl;
  267. cout << "3.Chinh sua Hang Hoa " << endl;
  268. cout << "4.Tim Kiem Hang Hoa" << endl;
  269. cout << "5.Thong Ke" << endl;
  270. int m;
  271. cout << "Moi nhap lua chon ";
  272. cin >> m;
  273. cin.ignore(1);
  274. switch (m) {
  275. case 1:cout << "1" << endl;break;
  276. case 2:cout << "2" << endl;break;
  277. case 3:cout << "3" << endl;break;
  278. case 4:cout << "4" << endl;break;
  279. case 5:cout << "5" << endl;break;
  280. }
  281. } while (dk == true);
  282. return 0;
  283. }
  284. bool test_user(Account &acc, string testuser) {
  285.  
  286. for (int j = 0;j < acc.user.size();j++) {
  287. if (testuser == acc.user[j]) return 0;
  288. }
  289. return 1;
  290. }
  291. bool delete_account(Account &acc, Account_to_role &acc_role, Role &role) {
  292. bool dk2=true;
  293. do {
  294. system("cls");
  295. cout << "Nhap account can delete: ";
  296. string nameacc;
  297. getline(cin, nameacc);
  298.  
  299. if (test_user_to_delete(acc,acc_role,role,nameacc) == true) {
  300. system("cls");
  301. cout << "Delete Success!";
  302. int a;
  303. cout << "Lua chon: 1.Goback 2.logout " ;
  304. cin >> a;
  305. cin.ignore(1);
  306. switch (a)
  307. {
  308. case 1: return 1;
  309. case 2: return 0;
  310. default:
  311. return 0;
  312. }
  313. }
  314. else {
  315. cout << "Account can delete ko ton tai"<<endl;
  316. int a;
  317. cout << "Lua chon: 1.Nhap lai 2.Goback 3.Logout ";
  318. cin >> a;
  319. cin.ignore(1);
  320. switch (a)
  321. {
  322. case 1: dk2 = false;break;
  323. case 2: return 1;
  324. case 3: return 0;
  325. default:
  326. return 1;
  327. }
  328. }
  329. } while (dk2==false);
  330.  
  331. }
  332. bool test_user_to_delete(Account &acc, Account_to_role &acc_role, Role &role, string testuser) {
  333. for ( int i = 0;i < acc.user.size();i++) {
  334. if (testuser == acc.user[i]) {
  335. acc.user.erase(acc.user.begin() + i);
  336. acc.password.erase(acc.password.begin()+i);
  337. acc_role.user.erase(acc_role.user.begin() + i);
  338. acc_role.chucnang.erase(acc_role.chucnang.begin() + i);
  339. role.namework.erase(role.namework.begin() + i);
  340. role.user.erase(role.user.begin() + i);
  341. return 1;
  342. }
  343. }
  344.  
  345. return 0;
  346. }
  347. bool information_acc_present(Account &acc, Account_to_role &acc_role, Role &role,string a) {
  348. int i;
  349. for ( i = 0;i < acc.user.size();i++) {
  350. if (acc.user[i] == a) break;
  351. }
  352. system("cls");
  353. cout << "Name account: " << acc.user[i] << endl;
  354. cout << "Password: " << acc.password[i] << endl;
  355. cout << "Loai account: " << role.user[i] << endl;
  356. cout << "Lua chon: 1.Goback 2.Logout " ;
  357. int n;
  358. cin >> n;
  359. cin.ignore(1);
  360. switch (n)
  361. {
  362. case 1: return 1;
  363. case 2: return 0;
  364. default:
  365. return 1;
  366. }
  367. }
  368. bool information_list_acc(Account &acc, Account_to_role &acc_role, Role &role) {
  369. system("cls");
  370. cout << "==========List_Account==========" << endl;
  371. cout <<setw(20)<< "User" <<setw(20)<<"Password" <<setw(20)<<"Loai account"<< endl;
  372. int x = acc.user.size();
  373. for (int i = 0;i < x;i++) {
  374. cout << setw(20) << acc.user[i] << setw(20) << acc.password[i] << setw(20) <<role.user[i] << endl;
  375. }
  376. cout << "Tong so account trong he thong: " <<x<<endl;
  377. cout << "Lua chon: 1.quay lai 2.logout " ;
  378. int n;
  379. cin >> n;
  380. cin.ignore(1);
  381. switch (n)
  382. {
  383. case 1: return 1;
  384. case 2: return 0;
  385. default:
  386. return 1;
  387. }
  388.  
  389. }
  390. bool serch_account(Account &acc, Account_to_role &acc_role, Role &role) {
  391. system("cls");
  392. string a;
  393. int n=acc.user.size();
  394. cout << "Nhap vao name account can tim: " ;
  395. getline(cin, a);
  396. int i;
  397. for ( i = 0;i < n;i++) {
  398. if (a == acc.user[i])break;
  399. }
  400. if (i < n) {
  401. system("cls");
  402. cout << "Name account: " << acc.user[i] << endl;
  403. cout << "Pass: " << acc.password[i] << endl;
  404. cout << "Loai account: " << role.user[i] << endl;
  405. }
  406. else cout << "Khong tim thay." << endl;
  407. cout << "Lua chon: 1.quay lai 2.logout " ;
  408. int m;
  409. cin >> m;
  410. cin.ignore(1);
  411. switch (m)
  412. {
  413. case 1: return 1;
  414. case 2: return 0;
  415. default:
  416. return 1;
  417. }
  418. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement