( 2.1).
( 2.2).
( 2.3).
( 2.4). ( 2.5), ( 2.6), , ( 2.7).
, , ( 2.8).
, , ( 2.9).
, UserContainer ( 2.10).
2.1
2.2
2.3
2.4
2.5
2.6
2.7
2.8
2.9
2.10
(STL). , C++ Visual Studio 2015 Comunity.
1. : STL
2. , ++, , , 2010
3. , , ++ , , 1993
5. . ., . . ++. - UML. / . . .: < >, 2009.
6. . ++: . .: , 2009.
. CourseWORK.cpp:
#include "stdafx.h"
#include "User.h"
#include "UserContainer.h"
#include "Menu.h"
#include <locale.h>
using namespace std;
|
|
int main()
{
setlocale(LC_CTYPE, "Russian");
UserContainer *container = new UserContainer();
Menu *menu = new Menu();
menu->container = container;
menu->mainMenu();
return 0;
}
Menu.h:
#pragma once
#include "iostream"
#include "conio.h"
#include "User.h"
#include "UserContainer.h"
using namespace std;
class Menu
{
public:
UserContainer *container;
Menu();
~Menu();
void mainMenu();
};
Menu.cpp:
#include "stdafx.h"
#include "Menu.h"
Menu::Menu()
{
}
Menu::~Menu()
{
}
void Menu::mainMenu() {
system("CLS");
cout << " : " << container->userList.size() << endl << endl;
cout << " " << endl << endl;
cout << "1 - " << endl;
cout << "2 - " << endl; ///
cout << "3 - " << endl;
cout << "0 - " << endl;
std::cin.clear();
int c;
cin >> c;
if (c == 0) {
return;
}
if (c == 1) {
system("CLS");
User *user = new User();
cout << " (int)" << endl;
cin >> user->userId;
cout << " (string)" << endl;
cin >> user->name;
cout << " (string)" << endl;
cin >> user->surname;
cout << " (string)" << endl;
cin >> user->patronymic;
cout << " (string)" << endl;
cin >> user->login;
cout << " email (string)" << endl;
cin >> user->email;
cout << " (string)" << endl;
cin >> user->password;
cout << " (int)" << endl;
cin >> user->phone;
cout << " (string)" << endl;
cin >> user->regDate;
cout << " (string)" << endl;
cin >> user->lastActivityDate;
cout << " / (bool)" << endl;
cin >> user->onlineFlag;
cout << " (int)" << endl;
cin >> user->roleCode;
cout << " (int)" << endl;
cin >> user->branchCode;
cout << " (int)" << endl;
cin >> user->partCode;
cout << " (int)" << endl;
cin >> user->userPositionCode;
container->addUser(*user);
|
|
mainMenu();
}
if (c == 2) {
system("CLS");
cout << "1 - " << endl;
cout << "0 - " << endl;
std::cin.clear();
int c;
cin >> c;
if (c == 1)
{
system("CLS");
string surname;
cout << " " << endl;
cin >> surname;
cout << endl;
cout << " :" << endl << endl;
User user = container->findUserBySurname(surname);
if (user.userId < 0)
cout << " " << endl << endl;
else
user.printUser();
cout << "1 - " << endl;
cout << "2 - " << endl;
cout << "0 - " << endl;
std::cin.clear();
int c;
cin >> c;
if (c == 0) {
mainMenu();
}
if (c == 1) {
system("CLS");
cout << " (string)" << endl;
cin >> user.name;
cout << " (string)" << endl;
cin >> user.surname;
cout << " (string)" << endl;
cin >> user.patronymic;
cout << " (string)" << endl;
cin >> user.login;
cout << " email (string)" << endl;
cin >> user.email;
cout << " (string)" << endl;
cin >> user.password;
cout << " (int)" << endl;
cin >> user.phone;
cout << " (string)" << endl;
cin >> user.regDate;
cout << " (string)" << endl;
cin >> user.lastActivityDate;
cout << " / (bool)" << endl;
cin >> user.onlineFlag;
cout << " (int)" << endl;
cin >> user.roleCode;
cout << " (int)" << endl;
cin >> user.branchCode;
cout << " (int)" << endl;
cin >> user.partCode;
cout << " (int)" << endl;
cin >> user.userPositionCode;
container->updateUser(user);
mainMenu();
}
if (c == 2) {
container->deleteUser(user);
mainMenu();
}
}
if (c == 0)
{
system("CLS");
mainMenu();
}
}
if (c == 3) {
system("CLS");
cout << " " << endl << endl;
container->printAllUsers();
cout << "0 - " << endl;
std::cin.clear();
int c;
cin >> c;
if (c == 0)
{
mainMenu();
}
}
mainMenu();
}
UserContainer.h:
#pragma once
#include "User.h"
#include "deque"
using namespace std;
class UserContainer
{
public:
UserContainer();
~UserContainer();
User findUserBySurname(string surname);
void printAllUsers();
void addUser(User user);
void deleteUser(User user);
void updateUser(User user);
deque<User> userList;
};
UserContainer.cpp:
#include "stdafx.h"
#include "UserContainer.h"
|
|
#include "iostream"
UserContainer::UserContainer()
{
}
UserContainer::~UserContainer()
{
}
void UserContainer::addUser(User user) {
userList.push_front(user);
}
void UserContainer::printAllUsers() {
for (int i = 0; i < userList.size(); i++)
{
userList[i].printUser();
}
}
User UserContainer::findUserBySurname(string surname)
{
User findUser;
for (int i = 0; i < userList.size(); i ++)
{
if (userList[i].surname == surname)
{
findUser = userList[i];
break;
}
}
return findUser;
}
void UserContainer::deleteUser(User user)
{
for (int i = 0; i < userList.size(); i++) {
if (userList[i].userId == user.userId) {
userList.erase(userList.begin() + i);
break;
}
}
}
void UserContainer::updateUser(User user)
{
for (int i = 0; i < userList.size(); i++) {
if (userList[i].userId == user.userId) {
userList[i] = user;
break;
}
}
}
User.h:
#pragma once
#include <string>
using namespace std;
class User
{
public:
int userId;
string name;
string surname;
string patronymic;
string login;
string email;
string password;
string phone;
string regDate;
string lastActivityDate;
bool onlineFlag;
int roleCode;
int branchCode;
int partCode;
int userPositionCode;
User();
~User();
void printUser();
};
User.cpp:
#include "stdafx.h"
#include "User.h"
#include "iostream"
using namespace std;
User::User()
{
}
User::~User()
{
}
void User::printUser()
{
cout << " " << userId << endl;
cout << " " << name << endl;
cout << " " << surname << endl;
cout << " " << patronymic << endl;
cout << " " << login << endl;
cout << "Email " << email << endl;
cout << " " << password << endl;
cout << " " << phone << endl;
cout << " " << regDate << endl;
cout << " " << lastActivityDate << endl;
cout << "/ " << onlineFlag << endl;
cout << " " << roleCode << endl;
cout << " " << branchCode << endl;
cout << " " << partCode << endl;
cout << " " << userPositionCode << endl << endl;
}