Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef ADMIN_H
- #define ADMIN_H
- #include "user.h"
- #include <fstream>
- class Admin :public User
- {
- private:
- char* log;
- char* pass;
- public:
- Admin();
- Admin(const Admin&);
- ~Admin();
- void addNewUser();
- bool checkUser();
- bool checkAdmin();
- void delUser();
- void showUser();
- void enterData();
- };
- #endif
- #ifndef COMPANY_H
- #define COMPANY_H
- #include <iostream>
- #include <conio.h>
- using namespace std;
- const int N = 20;
- class Company
- {
- protected:
- char* activity;
- char* name;
- int capital;
- int quantityOrder;
- int turnover;
- public:
- Company();
- Company(const Company&);
- ~Company();
- virtual void input()=0;
- virtual void show()=0;
- void setActivity(char*);
- char* getActivity();
- void setName(char*);
- char* getName();
- void setCapital(int);
- int getCapital();
- void setQuantityOrder(int);
- int getQuantityOrder();
- void setTurnover(int);
- int getTurnover();
- void enterCheck(int&); // input check
- };
- #endif
- #ifndef INVESTMENT_H
- #define INVESTMENT_H
- #include "Investment_department.h"
- class Investment : public Investment_department
- {
- protected:
- char* model_investment;
- public:
- Investment();
- Investment(const Investment&);
- ~Investment();
- void input();
- void show();
- };
- #endif
- #ifndef INVESTMENT_DEPARTMENT_H
- #define INVESTMENT_DEPARTMENT_H
- #include "company.h"
- class Investment_department :public Company
- {
- protected:
- int profit;
- char* choice;
- public:
- Investment_department();
- Investment_department(const Investment_department&);
- ~Investment_department();
- void setProfit(int);
- int getProfit();
- void setChoice(char*);
- char* getChoice();
- void input();
- void show();
- void findProfit();
- };
- #endif
- #ifndef MENU_H
- #define MENU_H
- #include <iostream>
- #include <conio.h>
- using namespace std;
- class Menu
- {
- private:
- int key;
- int code;
- public:
- Menu();
- int menu();
- int menuAdmin();
- int menuUser();
- int menuBussinesUser();
- };
- #endif
- #ifndef USER_H
- #define USER_H
- #include <iostream>
- #include <conio.h>
- #include <fstream>
- #include <vector>
- #include <string>
- using namespace std;
- const int N = 20;
- class User
- {
- protected:
- char* login;
- char* password;
- public:
- virtual void addNewUser() = 0;
- virtual bool checkUser() = 0;
- virtual void delUser() = 0;
- virtual void showUser() = 0;
- virtual void enterData() = 0;
- User();
- User(const User&);
- virtual ~User();
- };
- #endif
- #include "admin.h"
- Admin::Admin()
- {
- log = new char[N];
- pass = new char[N];
- }
- Admin::Admin(const Admin& ob) :User(ob)
- {
- int n = strlen(ob.log) + 1;
- int s = strlen(ob.pass) + 1;
- log = new char[n];
- pass = new char[s];
- strcpy(log, ob.log);
- strcpy(pass, ob.pass);
- }
- Admin::~Admin()
- {
- delete[]log;
- delete[]pass;
- }
- void Admin::addNewUser()
- {
- int f = 0, f1 = 0, i = 0;
- char* loginUser;
- char* passwordUser;
- loginUser = new char[N];
- passwordUser = new char[N];
- ifstream in("user.txt");
- fstream out("user.txt", ios::out|ios::app);
- if (!out.is_open())
- {
- cout << "Ошибка открытия файл" << endl;
- return;
- }
- do
- {
- system("cls");
- cout << "Введите логин" << endl;
- cout << ">>> ";
- cin.getline(login, N);
- do
- {
- in >> loginUser;
- in >> passwordUser;
- if (strcmp(login, loginUser) == 0)
- {
- f = 1;
- break;
- }
- } while (!in.eof());
- if (f == 1)
- {
- system("cls");
- cout << "Пользователь с таким логином уже зарегестрирован!" << endl;
- _getch();
- }
- else
- break;
- } while (1);
- in.close();
- cout << "Введите пароль" << endl;
- cout << ">>> ";
- while ((password[i] = getch()) != '\r' && i != 19)
- {
- if (password[i] == '\b')
- {
- printf("%s", "\b \b");
- if (i > 0)
- i--;
- }
- else
- {
- printf("%c", '*');
- i++;
- }
- }
- password[i] = '\0';
- out << login;
- out << "\n";
- out << password;
- out << "\n";
- cout << "\n\t\t\tНовый пользователь успешно создан!" << endl;
- out.close();
- delete[] loginUser;
- delete[] passwordUser;
- }
- void Admin::showUser()
- {
- ifstream adin;
- adin.open("user.txt");
- system("cls");
- cout << "Список зарегестрированных пользователей" << endl;
- do
- {
- adin >> login;
- adin >> password;
- cout << login << endl;
- } while (!adin.eof());
- }
- void Admin::delUser()
- {
- vector<string> v;
- int f = 0, a = 0, b = 0, n = 0;
- char* loginUser;
- char* passwordUser;
- loginUser = new char[N];
- passwordUser = new char[N];
- fstream out("user.txt", ios::in | ios::out | ios::app);
- string s1,s2,s3;
- do
- {
- out >> s1;
- out >> s2;
- v.push_back(s1);
- } while (!out.eof());
- for (int i = 0; i < v.size(); i++)
- cout << v[i] << endl;
- do
- {
- cout << "Введите логин, который необходимо удалить" << endl;
- cin >> s3;
- for (int i = 0; i < v.size(); i++)
- {
- if (s3 == v[i])
- {
- f = 1;
- a = i;
- break;
- }
- }
- if (f == 1)
- v.erase(v.begin() + a);
- for (int i = 0; i < v.size(); i++)
- cout << v[i] << endl;
- _getch();
- if (v.size() == 0)
- break;
- } while (1);
- out.close();
- delete[] loginUser;
- delete[] passwordUser;
- }
- bool Admin::checkUser()
- {
- int f = 0, f1 = 0, i = 0;
- char* loginUser;
- char* passwordUser;
- loginUser = new char[N];
- passwordUser = new char[N];
- ifstream in("user.txt");
- do
- {
- system("cls");
- cout << "Авторизация пользователя:" << endl;
- cout << "Введите логин" << endl;
- cout << ">>> ";
- cin.getline(login, N);
- fflush(stdin);
- do
- {
- in >> loginUser;
- in >> passwordUser;
- if (strcmp(login, loginUser) == 0)
- {
- f = 1;
- break;
- }
- } while (!in.eof());
- if (f == 0)
- {
- system("cls");
- cout << "Логин введён неверно!\n" << endl;
- _getch();
- return false;
- }
- else
- break;
- } while (1);
- do
- {
- system("cls");
- cout << "Введите пароль" << endl;
- cout << ">>> ";
- while ((password[i] = getch()) != '\r' && i != 19)
- {
- if (password[i] == '\b')
- {
- printf("%s", "\b \b");
- if (i > 0)
- i--;
- }
- else
- {
- printf("%c", '*');
- i++;
- }
- }
- password[i] = '\0';
- if (strcmp(password, passwordUser) == 0)
- {
- f1 = 1;
- }
- if (f1 == 0)
- {
- system("cls");
- cout << "Пароль введён неверно!\n" << endl;
- _getch();
- return false;
- }
- else
- return true;
- } while (1);
- delete[]loginUser;
- delete[]passwordUser;
- in.close();
- }
- bool Admin::checkAdmin()
- {
- char ex;
- int i = 0, f = 0, f1 = 0;
- char* loginAdmin = new char[N];
- char* passwordAdmin = new char[N];
- ifstream in("admin.txt");
- f = 0;
- do
- {
- system("cls");
- cout << "Авторизация администратора" << endl;
- cout << "Введите логин администратора" << endl;
- cout << ">>> ";
- cin.getline(log, N);
- fflush(stdin);
- do
- {
- in >> loginAdmin;
- in >> passwordAdmin;
- if (strcmp(log, loginAdmin) == 0)
- {
- f = 1;
- break;
- }
- } while (!in.eof());
- if (f == 0)
- {
- system("cls");
- cout << "Логин введён неверно!\n" << endl;
- _getch();
- return false;
- }
- else
- break;
- } while (1);
- f1 = 0;
- do
- {
- system("cls");
- cout << "Введите пароль администратора" << endl;
- cout << ">>> ";
- while ((pass[i] = getch()) != '\r' && i != 19)
- {
- if (pass[i] == '\b')
- {
- printf("%s", "\b \b");
- if (i > 0)
- i--;
- }
- else
- {
- printf("%c", '*');
- i++;
- }
- }
- pass[i] = '\0';
- if (strcmp(pass, passwordAdmin) == 0)
- {
- f1 = 1;
- }
- if (f1 == 1)
- return true;
- else
- if (f1 == 0)
- {
- system("cls");
- cout << "Пароль введён неверно!\n" << endl;
- _getch();
- return false;
- }
- } while (1);
- in.close();
- delete[]loginAdmin;
- delete[]passwordAdmin;
- }
- void Admin::enterData()
- {
- int i = 0;
- cout << "Введите логин" << endl;
- cin.getline(login, N);
- cout << "Введите пароль" << endl;
- while ((password[i] = getch()) != '\r' && i != 19)
- {
- if (password[i] == '\b')
- {
- printf("%s", "\b \b");
- if (i > 0)
- i--;
- }
- else{
- printf("%c", '*');
- i++;
- }
- }
- password[i] = '\0';
- }
- #include "company.h"
- Company::Company() : capital(0), quantityOrder(0), turnover(0)
- {
- activity = new char[N];
- name = new char[N];
- }
- Company::Company(const Company& ob)
- {
- int n = strlen(ob.activity) + 1;
- int s = strlen(ob.name) + 1;
- activity = new char[n];
- name = new char[s];
- strcpy(activity, ob.activity);
- strcpy(name, ob.name);
- capital = ob.capital;
- quantityOrder = ob.quantityOrder;
- capital = ob.capital;
- turnover = ob.turnover;
- }
- Company::~Company()
- {
- delete[]activity;
- delete[]name;
- }
- void Company::setActivity(char* activity)
- {
- this->activity = activity;
- }
- char* Company::getActivity()
- {
- return this->activity;
- }
- void Company::setName(char* name)
- {
- this->name = name;
- }
- char* Company::getName()
- {
- return this->name;
- }
- void Company::setCapital(int capital)
- {
- this->capital = capital;
- }
- int Company::getCapital()
- {
- return capital;
- }
- void Company::setQuantityOrder(int quantityOrder)
- {
- this->quantityOrder = quantityOrder;
- }
- int Company::getQuantityOrder()
- {
- return this->quantityOrder;
- }
- void Company::setTurnover(int turnover)
- {
- this->turnover = turnover;
- }
- int Company::getTurnover()
- {
- return this->turnover;
- }
- void enterCheck(int& num)
- {
- do
- {
- cin >> num;
- if (cin.peek() == '\n' && num > 0)
- break;
- else
- {
- cout << "Invalid input! \nPlease repeat input: " << endl;
- cin.clear();
- while (cin.get() != '\n');
- }
- } while (1);
- }
- //#include "investment_department.h"
- //
- //Investment_department::Investment_department() : profit(0)
- //{
- // choice = new char[N];
- //}
- //
- //Investment_department::Investment_department(const Investment_department& ob) : Company(ob)
- //{
- // int n = strlen(ob.choice) + 1;
- // choice = new char[n];
- // strcpy(choice, ob.choice);
- //
- // profit = ob.profit;
- //}
- //
- //Investment_department::~Investment_department()
- //{
- // delete[]choice;
- //}
- //
- #include "admin.h"
- #include "menu.h"
- int main()
- {
- setlocale(LC_ALL, "Russian");
- int ch = 0, u = 0, a = 0, check = 0;
- char ex;
- Menu mnu;
- User *p;
- Admin ad;
- p = &ad;
- cout << "\t\t\tМеню" << endl;
- ad.delUser();
- /*do
- {
- system("cls");
- switch (mnu.menu())
- {
- case 0:
- check = 0;
- do{
- system("cls");
- if (ad.checkAdmin() == false)
- break;
- else
- {
- a = 0;
- do
- {
- switch (mnu.menuAdmin())
- {
- case 0: break;
- case 1: break;
- case 2: break;
- case 3:
- a = 1;
- check = 1;
- break;
- }
- } while (a != 1);
- }
- } while (check != 1);
- break;
- case 1:
- check = 0;
- system("cls");
- do
- {
- if (ad.checkUser() == false)
- break;
- else
- {
- system("cls");
- u = 0;
- do
- {
- switch (mnu.menuUser())
- {
- case 0: break;
- case 1: break;
- case 2:
- u = 1;
- check = 1;
- break;
- }
- } while (u != 1);
- }
- } while (check != 1);
- break;
- case 2:
- check = 0;
- do{
- system("cls");
- if (ad.checkAdmin() == false)
- break;
- else
- {
- a = 0;
- do
- {
- switch (mnu.menuBussinesUser())
- {
- case 0: break;
- case 1: break;
- case 2: break;
- case 3:
- a = 1;
- check = 1;
- break;
- }
- } while (a != 1);
- }
- } while (check != 1);
- break;
- case 3:
- ch = 1;
- break;
- }
- } while (ch != 1);*/
- return 0;
- }
- //Рез-т:
- //нужно дописать delUser.
- //разобраться с векторами.
- #include "menu.h"
- Menu::Menu()
- {
- key = 0;
- code = 0;
- }
- int Menu::menu()
- {
- do
- {
- system("cls");
- key = (key + 4) % 4;
- cout << "\tМеню" << endl;
- if (key == 0)
- cout << "> Администратор." << endl;
- else
- cout << " Администратор." << endl;
- if (key == 1)
- cout << "> Пользователь." << endl;
- else
- cout << " Пользователь." << endl;
- if (key == 2)
- cout << "> Бизнес пользователь." << endl;
- else
- cout << " Бизнес пользователь." << endl;
- if (key == 3)
- cout << "> Выход." << endl;
- else
- cout << " Выход." << endl;
- code = _getch();
- if (code == 224)
- {
- code = _getch();
- if (code == 80)
- key++;
- if (code == 72)
- key--;
- }
- } while (code != 13);
- return key;
- }
- int Menu::menuAdmin()
- {
- do
- {
- system("cls");
- key = (key + 4) % 4;
- if (key == 0)
- cout << "> Добавление пользователя." << endl;
- else
- cout << " Добавление пользователя." << endl;
- if (key == 1)
- cout << "> Удаление пользователей." << endl;
- else
- cout << " Удаление пользователей." << endl;
- if (key == 2)
- cout << "> Просмотр клиентов в базе." << endl;
- else
- cout << " Просмотр клиентов в базе." << endl;
- if (key == 3)
- cout << "> Выход." << endl;
- else
- cout << " Выход." << endl;
- code = _getch();
- if (code == 224)
- {
- code = _getch();
- if (code == 80)
- key++;
- if (code == 72)
- key--;
- }
- } while (code != 13);
- return key;
- }
- int Menu::menuUser()
- {
- do
- {
- system("cls");
- key = (key + 3) % 3;
- cout << "\tМеню пользователя" << endl;
- if (key == 0)
- cout << "> Формирование заявки." << endl;
- else
- cout << " Формирование заявки." << endl;
- if (key == 1)
- cout << "> Просмотреть отчёт об инвестиции." << endl;
- else
- cout << " Просмотреть отчёт об инвестиции." << endl;
- if (key == 2)
- cout << "> Выход." << endl;
- else
- cout << " Выход." << endl;
- code = _getch();
- if (code == 224)
- {
- code = _getch();
- if (code == 80)
- key++;
- if (code == 72)
- key--;
- }
- } while (code != 13);
- return key;
- }
- int Menu::menuBussinesUser()
- {
- do
- {
- system("cls");
- key = (key + 4) % 4;
- cout << "\tМеню бизнес пользователя" << endl;
- if (key == 0)
- cout << "> Рассмотрение заявки." << endl;
- else
- cout << " Рассмотрение заявки." << endl;
- if (key == 1)
- cout << "> Составление документации." << endl;
- else
- cout << " Составление документации." << endl;
- if (key == 2)
- cout << "> Инвестирование." << endl;
- else
- cout << " Инвестирование." << endl;
- if (key == 3)
- cout << "> Выход." << endl;
- else
- cout << " Выход." << endl;
- code = _getch();
- if (code == 224)
- {
- code = _getch();
- if (code == 80)
- key++;
- if (code == 72)
- key--;
- }
- } while (code != 13);
- return key;
- }
- #include "user.h"
- User::User()
- {
- login = new char[N];
- password = new char[N];
- }
- User::User(const User& ob)
- {
- int n = strlen(ob.login) + 1;
- int s = strlen(ob.password) + 1;
- login = new char[n];
- password = new char[s];
- strcpy(login, ob.login);
- strcpy(password, ob.password);
- }
- User::~User()
- {
- delete[]login;
- delete[]password;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement