Advertisement
Guest User

Untitled

a guest
Nov 24th, 2016
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.73 KB | None | 0 0
  1. #ifndef ADMIN_H
  2. #define ADMIN_H
  3.  
  4. #include "user.h"
  5. #include <fstream>
  6.  
  7. class Admin :public User
  8. {
  9. private:
  10. char* log;
  11. char* pass;
  12. public:
  13. Admin();
  14. Admin(const Admin&);
  15. ~Admin();
  16. void addNewUser();
  17. bool checkUser();
  18. bool checkAdmin();
  19. void delUser();
  20. void showUser();
  21. void enterData();
  22. };
  23.  
  24. #endif
  25.  
  26. #ifndef COMPANY_H
  27. #define COMPANY_H
  28.  
  29. #include <iostream>
  30. #include <conio.h>
  31.  
  32. using namespace std;
  33.  
  34. const int N = 20;
  35.  
  36. class Company
  37. {
  38. protected:
  39. char* activity;
  40. char* name;
  41. int capital;
  42. int quantityOrder;
  43. int turnover;
  44. public:
  45. Company();
  46. Company(const Company&);
  47. ~Company();
  48. virtual void input()=0;
  49. virtual void show()=0;
  50. void setActivity(char*);
  51. char* getActivity();
  52. void setName(char*);
  53. char* getName();
  54. void setCapital(int);
  55. int getCapital();
  56. void setQuantityOrder(int);
  57. int getQuantityOrder();
  58. void setTurnover(int);
  59. int getTurnover();
  60. void enterCheck(int&); // input check
  61. };
  62.  
  63.  
  64. #endif
  65.  
  66. #ifndef INVESTMENT_H
  67. #define INVESTMENT_H
  68.  
  69. #include "Investment_department.h"
  70.  
  71. class Investment : public Investment_department
  72. {
  73. protected:
  74. char* model_investment;
  75. public:
  76. Investment();
  77. Investment(const Investment&);
  78. ~Investment();
  79. void input();
  80. void show();
  81. };
  82.  
  83. #endif
  84.  
  85. #ifndef INVESTMENT_DEPARTMENT_H
  86. #define INVESTMENT_DEPARTMENT_H
  87.  
  88. #include "company.h"
  89.  
  90. class Investment_department :public Company
  91. {
  92. protected:
  93. int profit;
  94. char* choice;
  95. public:
  96. Investment_department();
  97. Investment_department(const Investment_department&);
  98. ~Investment_department();
  99. void setProfit(int);
  100. int getProfit();
  101. void setChoice(char*);
  102. char* getChoice();
  103. void input();
  104. void show();
  105. void findProfit();
  106. };
  107.  
  108. #endif
  109.  
  110. #ifndef MENU_H
  111. #define MENU_H
  112.  
  113. #include <iostream>
  114. #include <conio.h>
  115.  
  116. using namespace std;
  117.  
  118. class Menu
  119. {
  120. private:
  121. int key;
  122. int code;
  123. public:
  124. Menu();
  125. int menu();
  126. int menuAdmin();
  127. int menuUser();
  128. int menuBussinesUser();
  129. };
  130.  
  131. #endif
  132.  
  133. #ifndef USER_H
  134. #define USER_H
  135.  
  136. #include <iostream>
  137. #include <conio.h>
  138. #include <fstream>
  139. #include <vector>
  140. #include <string>
  141.  
  142. using namespace std;
  143.  
  144. const int N = 20;
  145.  
  146. class User
  147. {
  148. protected:
  149. char* login;
  150. char* password;
  151. public:
  152. virtual void addNewUser() = 0;
  153. virtual bool checkUser() = 0;
  154. virtual void delUser() = 0;
  155. virtual void showUser() = 0;
  156. virtual void enterData() = 0;
  157. User();
  158. User(const User&);
  159. virtual ~User();
  160. };
  161.  
  162. #endif
  163.  
  164. #include "admin.h"
  165.  
  166. Admin::Admin()
  167. {
  168. log = new char[N];
  169. pass = new char[N];
  170. }
  171.  
  172. Admin::Admin(const Admin& ob) :User(ob)
  173. {
  174. int n = strlen(ob.log) + 1;
  175. int s = strlen(ob.pass) + 1;
  176.  
  177. log = new char[n];
  178. pass = new char[s];
  179.  
  180. strcpy(log, ob.log);
  181. strcpy(pass, ob.pass);
  182. }
  183.  
  184. Admin::~Admin()
  185. {
  186. delete[]log;
  187. delete[]pass;
  188. }
  189.  
  190. void Admin::addNewUser()
  191. {
  192. int f = 0, f1 = 0, i = 0;
  193. char* loginUser;
  194. char* passwordUser;
  195. loginUser = new char[N];
  196. passwordUser = new char[N];
  197. ifstream in("user.txt");
  198. fstream out("user.txt", ios::out|ios::app);
  199. if (!out.is_open())
  200. {
  201. cout << "Ошибка открытия файл" << endl;
  202. return;
  203. }
  204.  
  205. do
  206. {
  207. system("cls");
  208. cout << "Введите логин" << endl;
  209. cout << ">>> ";
  210. cin.getline(login, N);
  211. do
  212. {
  213. in >> loginUser;
  214. in >> passwordUser;
  215. if (strcmp(login, loginUser) == 0)
  216. {
  217. f = 1;
  218. break;
  219. }
  220. } while (!in.eof());
  221.  
  222. if (f == 1)
  223. {
  224. system("cls");
  225. cout << "Пользователь с таким логином уже зарегестрирован!" << endl;
  226. _getch();
  227. }
  228. else
  229. break;
  230. } while (1);
  231. in.close();
  232. cout << "Введите пароль" << endl;
  233. cout << ">>> ";
  234. while ((password[i] = getch()) != '\r' && i != 19)
  235. {
  236. if (password[i] == '\b')
  237. {
  238. printf("%s", "\b \b");
  239. if (i > 0)
  240. i--;
  241. }
  242. else
  243. {
  244. printf("%c", '*');
  245. i++;
  246. }
  247. }
  248. password[i] = '\0';
  249.  
  250. out << login;
  251. out << "\n";
  252. out << password;
  253. out << "\n";
  254. cout << "\n\t\t\tНовый пользователь успешно создан!" << endl;
  255. out.close();
  256.  
  257. delete[] loginUser;
  258. delete[] passwordUser;
  259. }
  260.  
  261. void Admin::showUser()
  262. {
  263. ifstream adin;
  264. adin.open("user.txt");
  265. system("cls");
  266. cout << "Список зарегестрированных пользователей" << endl;
  267. do
  268. {
  269. adin >> login;
  270. adin >> password;
  271. cout << login << endl;
  272. } while (!adin.eof());
  273. }
  274.  
  275. void Admin::delUser()
  276. {
  277. vector<string> v;
  278. int f = 0, a = 0, b = 0, n = 0;
  279. char* loginUser;
  280. char* passwordUser;
  281. loginUser = new char[N];
  282. passwordUser = new char[N];
  283. fstream out("user.txt", ios::in | ios::out | ios::app);
  284. string s1,s2,s3;
  285. do
  286. {
  287. out >> s1;
  288. out >> s2;
  289. v.push_back(s1);
  290. } while (!out.eof());
  291. for (int i = 0; i < v.size(); i++)
  292. cout << v[i] << endl;
  293. do
  294. {
  295. cout << "Введите логин, который необходимо удалить" << endl;
  296. cin >> s3;
  297. for (int i = 0; i < v.size(); i++)
  298. {
  299. if (s3 == v[i])
  300. {
  301. f = 1;
  302. a = i;
  303. break;
  304. }
  305. }
  306. if (f == 1)
  307. v.erase(v.begin() + a);
  308. for (int i = 0; i < v.size(); i++)
  309. cout << v[i] << endl;
  310. _getch();
  311. if (v.size() == 0)
  312. break;
  313. } while (1);
  314.  
  315. out.close();
  316. delete[] loginUser;
  317. delete[] passwordUser;
  318. }
  319.  
  320. bool Admin::checkUser()
  321. {
  322. int f = 0, f1 = 0, i = 0;
  323. char* loginUser;
  324. char* passwordUser;
  325. loginUser = new char[N];
  326. passwordUser = new char[N];
  327. ifstream in("user.txt");
  328.  
  329. do
  330. {
  331. system("cls");
  332. cout << "Авторизация пользователя:" << endl;
  333. cout << "Введите логин" << endl;
  334. cout << ">>> ";
  335. cin.getline(login, N);
  336. fflush(stdin);
  337. do
  338. {
  339. in >> loginUser;
  340. in >> passwordUser;
  341. if (strcmp(login, loginUser) == 0)
  342. {
  343. f = 1;
  344. break;
  345. }
  346. } while (!in.eof());
  347. if (f == 0)
  348. {
  349. system("cls");
  350. cout << "Логин введён неверно!\n" << endl;
  351. _getch();
  352. return false;
  353. }
  354. else
  355. break;
  356. } while (1);
  357. do
  358. {
  359. system("cls");
  360. cout << "Введите пароль" << endl;
  361. cout << ">>> ";
  362. while ((password[i] = getch()) != '\r' && i != 19)
  363. {
  364. if (password[i] == '\b')
  365. {
  366. printf("%s", "\b \b");
  367. if (i > 0)
  368. i--;
  369. }
  370. else
  371. {
  372. printf("%c", '*');
  373. i++;
  374. }
  375. }
  376. password[i] = '\0';
  377. if (strcmp(password, passwordUser) == 0)
  378. {
  379. f1 = 1;
  380. }
  381. if (f1 == 0)
  382. {
  383. system("cls");
  384. cout << "Пароль введён неверно!\n" << endl;
  385. _getch();
  386. return false;
  387. }
  388. else
  389. return true;
  390.  
  391. } while (1);
  392.  
  393. delete[]loginUser;
  394. delete[]passwordUser;
  395. in.close();
  396. }
  397.  
  398. bool Admin::checkAdmin()
  399. {
  400. char ex;
  401. int i = 0, f = 0, f1 = 0;
  402. char* loginAdmin = new char[N];
  403. char* passwordAdmin = new char[N];
  404. ifstream in("admin.txt");
  405. f = 0;
  406. do
  407. {
  408. system("cls");
  409. cout << "Авторизация администратора" << endl;
  410. cout << "Введите логин администратора" << endl;
  411. cout << ">>> ";
  412. cin.getline(log, N);
  413. fflush(stdin);
  414. do
  415. {
  416. in >> loginAdmin;
  417. in >> passwordAdmin;
  418. if (strcmp(log, loginAdmin) == 0)
  419. {
  420. f = 1;
  421. break;
  422. }
  423. } while (!in.eof());
  424. if (f == 0)
  425. {
  426. system("cls");
  427. cout << "Логин введён неверно!\n" << endl;
  428. _getch();
  429. return false;
  430. }
  431. else
  432. break;
  433. } while (1);
  434. f1 = 0;
  435. do
  436. {
  437. system("cls");
  438. cout << "Введите пароль администратора" << endl;
  439. cout << ">>> ";
  440. while ((pass[i] = getch()) != '\r' && i != 19)
  441. {
  442. if (pass[i] == '\b')
  443. {
  444. printf("%s", "\b \b");
  445. if (i > 0)
  446. i--;
  447. }
  448. else
  449. {
  450. printf("%c", '*');
  451. i++;
  452. }
  453. }
  454. pass[i] = '\0';
  455. if (strcmp(pass, passwordAdmin) == 0)
  456. {
  457. f1 = 1;
  458. }
  459. if (f1 == 1)
  460. return true;
  461. else
  462. if (f1 == 0)
  463. {
  464. system("cls");
  465. cout << "Пароль введён неверно!\n" << endl;
  466. _getch();
  467. return false;
  468. }
  469. } while (1);
  470.  
  471. in.close();
  472. delete[]loginAdmin;
  473. delete[]passwordAdmin;
  474. }
  475.  
  476. void Admin::enterData()
  477. {
  478. int i = 0;
  479. cout << "Введите логин" << endl;
  480. cin.getline(login, N);
  481. cout << "Введите пароль" << endl;
  482. while ((password[i] = getch()) != '\r' && i != 19)
  483. {
  484. if (password[i] == '\b')
  485. {
  486. printf("%s", "\b \b");
  487. if (i > 0)
  488. i--;
  489. }
  490. else{
  491. printf("%c", '*');
  492. i++;
  493. }
  494. }
  495. password[i] = '\0';
  496. }
  497.  
  498.  
  499.  
  500. #include "company.h"
  501.  
  502. Company::Company() : capital(0), quantityOrder(0), turnover(0)
  503. {
  504. activity = new char[N];
  505. name = new char[N];
  506. }
  507.  
  508. Company::Company(const Company& ob)
  509. {
  510. int n = strlen(ob.activity) + 1;
  511. int s = strlen(ob.name) + 1;
  512. activity = new char[n];
  513. name = new char[s];
  514.  
  515. strcpy(activity, ob.activity);
  516. strcpy(name, ob.name);
  517. capital = ob.capital;
  518. quantityOrder = ob.quantityOrder;
  519. capital = ob.capital;
  520. turnover = ob.turnover;
  521. }
  522.  
  523. Company::~Company()
  524. {
  525. delete[]activity;
  526. delete[]name;
  527. }
  528.  
  529. void Company::setActivity(char* activity)
  530. {
  531. this->activity = activity;
  532. }
  533.  
  534. char* Company::getActivity()
  535. {
  536. return this->activity;
  537. }
  538.  
  539. void Company::setName(char* name)
  540. {
  541. this->name = name;
  542. }
  543.  
  544. char* Company::getName()
  545. {
  546. return this->name;
  547. }
  548.  
  549. void Company::setCapital(int capital)
  550. {
  551. this->capital = capital;
  552. }
  553.  
  554. int Company::getCapital()
  555. {
  556. return capital;
  557. }
  558.  
  559. void Company::setQuantityOrder(int quantityOrder)
  560. {
  561. this->quantityOrder = quantityOrder;
  562. }
  563.  
  564. int Company::getQuantityOrder()
  565. {
  566. return this->quantityOrder;
  567. }
  568.  
  569. void Company::setTurnover(int turnover)
  570. {
  571. this->turnover = turnover;
  572. }
  573.  
  574. int Company::getTurnover()
  575. {
  576. return this->turnover;
  577. }
  578.  
  579. void enterCheck(int& num)
  580. {
  581. do
  582. {
  583. cin >> num;
  584. if (cin.peek() == '\n' && num > 0)
  585. break;
  586. else
  587. {
  588. cout << "Invalid input! \nPlease repeat input: " << endl;
  589. cin.clear();
  590. while (cin.get() != '\n');
  591. }
  592. } while (1);
  593. }
  594.  
  595.  
  596. //#include "investment_department.h"
  597. //
  598. //Investment_department::Investment_department() : profit(0)
  599. //{
  600. // choice = new char[N];
  601. //}
  602. //
  603. //Investment_department::Investment_department(const Investment_department& ob) : Company(ob)
  604. //{
  605. // int n = strlen(ob.choice) + 1;
  606. // choice = new char[n];
  607. // strcpy(choice, ob.choice);
  608. //
  609. // profit = ob.profit;
  610. //}
  611. //
  612. //Investment_department::~Investment_department()
  613. //{
  614. // delete[]choice;
  615. //}
  616. //
  617.  
  618.  
  619. #include "admin.h"
  620. #include "menu.h"
  621.  
  622. int main()
  623. {
  624. setlocale(LC_ALL, "Russian");
  625. int ch = 0, u = 0, a = 0, check = 0;
  626. char ex;
  627. Menu mnu;
  628. User *p;
  629. Admin ad;
  630. p = &ad;
  631. cout << "\t\t\tМеню" << endl;
  632.  
  633. ad.delUser();
  634. /*do
  635. {
  636. system("cls");
  637. switch (mnu.menu())
  638. {
  639. case 0:
  640. check = 0;
  641. do{
  642. system("cls");
  643. if (ad.checkAdmin() == false)
  644. break;
  645. else
  646. {
  647. a = 0;
  648. do
  649. {
  650. switch (mnu.menuAdmin())
  651. {
  652. case 0: break;
  653. case 1: break;
  654. case 2: break;
  655. case 3:
  656. a = 1;
  657. check = 1;
  658. break;
  659. }
  660. } while (a != 1);
  661. }
  662. } while (check != 1);
  663. break;
  664. case 1:
  665. check = 0;
  666. system("cls");
  667. do
  668. {
  669. if (ad.checkUser() == false)
  670. break;
  671. else
  672. {
  673. system("cls");
  674. u = 0;
  675. do
  676. {
  677. switch (mnu.menuUser())
  678. {
  679. case 0: break;
  680. case 1: break;
  681. case 2:
  682. u = 1;
  683. check = 1;
  684. break;
  685. }
  686. } while (u != 1);
  687. }
  688. } while (check != 1);
  689. break;
  690. case 2:
  691. check = 0;
  692. do{
  693. system("cls");
  694. if (ad.checkAdmin() == false)
  695. break;
  696. else
  697. {
  698. a = 0;
  699. do
  700. {
  701. switch (mnu.menuBussinesUser())
  702. {
  703. case 0: break;
  704. case 1: break;
  705. case 2: break;
  706. case 3:
  707. a = 1;
  708. check = 1;
  709. break;
  710. }
  711. } while (a != 1);
  712. }
  713. } while (check != 1);
  714. break;
  715. case 3:
  716. ch = 1;
  717. break;
  718. }
  719. } while (ch != 1);*/
  720.  
  721. return 0;
  722. }
  723.  
  724. //Рез-т:
  725. //нужно дописать delUser.
  726. //разобраться с векторами.
  727.  
  728.  
  729. #include "menu.h"
  730.  
  731. Menu::Menu()
  732. {
  733. key = 0;
  734. code = 0;
  735. }
  736.  
  737. int Menu::menu()
  738. {
  739.  
  740. do
  741. {
  742. system("cls");
  743. key = (key + 4) % 4;
  744. cout << "\tМеню" << endl;
  745. if (key == 0)
  746. cout << "> Администратор." << endl;
  747. else
  748. cout << " Администратор." << endl;
  749. if (key == 1)
  750. cout << "> Пользователь." << endl;
  751. else
  752. cout << " Пользователь." << endl;
  753. if (key == 2)
  754. cout << "> Бизнес пользователь." << endl;
  755. else
  756. cout << " Бизнес пользователь." << endl;
  757. if (key == 3)
  758. cout << "> Выход." << endl;
  759. else
  760. cout << " Выход." << endl;
  761. code = _getch();
  762. if (code == 224)
  763. {
  764. code = _getch();
  765. if (code == 80)
  766. key++;
  767. if (code == 72)
  768. key--;
  769. }
  770. } while (code != 13);
  771.  
  772. return key;
  773. }
  774.  
  775. int Menu::menuAdmin()
  776. {
  777. do
  778. {
  779. system("cls");
  780. key = (key + 4) % 4;
  781.  
  782. if (key == 0)
  783. cout << "> Добавление пользователя." << endl;
  784. else
  785. cout << " Добавление пользователя." << endl;
  786. if (key == 1)
  787. cout << "> Удаление пользователей." << endl;
  788. else
  789. cout << " Удаление пользователей." << endl;
  790. if (key == 2)
  791. cout << "> Просмотр клиентов в базе." << endl;
  792. else
  793. cout << " Просмотр клиентов в базе." << endl;
  794. if (key == 3)
  795. cout << "> Выход." << endl;
  796. else
  797. cout << " Выход." << endl;
  798. code = _getch();
  799. if (code == 224)
  800. {
  801. code = _getch();
  802. if (code == 80)
  803. key++;
  804. if (code == 72)
  805. key--;
  806. }
  807. } while (code != 13);
  808.  
  809. return key;
  810. }
  811.  
  812. int Menu::menuUser()
  813. {
  814. do
  815. {
  816. system("cls");
  817. key = (key + 3) % 3;
  818. cout << "\tМеню пользователя" << endl;
  819. if (key == 0)
  820. cout << "> Формирование заявки." << endl;
  821. else
  822. cout << " Формирование заявки." << endl;
  823. if (key == 1)
  824. cout << "> Просмотреть отчёт об инвестиции." << endl;
  825. else
  826. cout << " Просмотреть отчёт об инвестиции." << endl;
  827. if (key == 2)
  828. cout << "> Выход." << endl;
  829. else
  830. cout << " Выход." << endl;
  831. code = _getch();
  832. if (code == 224)
  833. {
  834. code = _getch();
  835. if (code == 80)
  836. key++;
  837. if (code == 72)
  838. key--;
  839. }
  840. } while (code != 13);
  841.  
  842. return key;
  843. }
  844.  
  845. int Menu::menuBussinesUser()
  846. {
  847. do
  848. {
  849. system("cls");
  850. key = (key + 4) % 4;
  851. cout << "\tМеню бизнес пользователя" << endl;
  852. if (key == 0)
  853. cout << "> Рассмотрение заявки." << endl;
  854. else
  855. cout << " Рассмотрение заявки." << endl;
  856. if (key == 1)
  857. cout << "> Составление документации." << endl;
  858. else
  859. cout << " Составление документации." << endl;
  860. if (key == 2)
  861. cout << "> Инвестирование." << endl;
  862. else
  863. cout << " Инвестирование." << endl;
  864. if (key == 3)
  865. cout << "> Выход." << endl;
  866. else
  867. cout << " Выход." << endl;
  868. code = _getch();
  869. if (code == 224)
  870. {
  871. code = _getch();
  872. if (code == 80)
  873. key++;
  874. if (code == 72)
  875. key--;
  876. }
  877. } while (code != 13);
  878.  
  879. return key;
  880. }
  881.  
  882. #include "user.h"
  883.  
  884. User::User()
  885. {
  886. login = new char[N];
  887. password = new char[N];
  888. }
  889.  
  890. User::User(const User& ob)
  891. {
  892. int n = strlen(ob.login) + 1;
  893. int s = strlen(ob.password) + 1;
  894. login = new char[n];
  895. password = new char[s];
  896. strcpy(login, ob.login);
  897. strcpy(password, ob.password);
  898. }
  899.  
  900. User::~User()
  901. {
  902. delete[]login;
  903. delete[]password;
  904. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement