-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
232 lines (225 loc) · 6.16 KB
/
main.cpp
File metadata and controls
232 lines (225 loc) · 6.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
using namespace std;
struct Clients
{
int id;
string name;
int phone;
Clients *nextClient;
Clients *prevClient;
};
Clients *headClient;
struct Services {
int id;
char name;
float price;
Services *nextService;
Services *prevService;
};
Clients *headService;
struct Payment {
int id;
int id_client;
int id_service;
float sum;
int date;
Payment *nextPayment;
Payment *prevPayment;
};
Clients *headPayment;
struct Spending {
int id;
int id_client;
int id_service;
float count;
int date;
Spending *nextSpending;
Spending *prevSpending;
};
Clients *headSpending;
class Work {
private:
int clientsCount = 0;
int servicesCount = 0;
int paymentCount = 0;
int spendingCount = 0;
public:
void loadClients(string file) {
Clients *node = new Clients;
string client;
ifstream usersFile(file.c_str());
while (std::getline(usersFile, client)) {
stringstream item(client);
string id;
string name;
string phone;
getline(item, id, ';');
getline(item, name, ';');
getline(item, phone, ';');
this->addClients(name, atoi(phone.c_str()), atoi(id.c_str()));
}
cout << "\Êëèåíòû çàãðóæåíû...\n\n";
}
void showClients() {
if (headClient == NULL)
{
cout << "\nÑïèñîê ïóñò\n\n";
}
else
{
Clients *a = headClient;
cout << "\nÝëåìåíòû ñïèñêà: " << endl;
do
{
cout << "ID: " << a->id << '\n';
cout << "NAME: " << a->name << '\n';
cout << "PHONE: " << a->phone << '\n';
a = a->nextClient;
} while(a != headClient);
cout << "\n\n";
}
}
void addClients(string name, int phone, int id) {
Clients *node = new Clients;
if(id == -1)
{
clientsCount++;
}
else
{
clientsCount = id;
}
node->id = clientsCount;
node->name = name;
node->phone = phone;
if (headClient == NULL)
{
node->nextClient = node;
node->prevClient = node;
headClient = node;
}
else
{
Clients *p = headClient;
for(int i = clientsCount; i > 1; i--)
{
p = p->nextClient;
}
p->prevClient->nextClient = node;
node->prevClient = p->prevClient;
node->nextClient = p;
p->prevClient = node;
}
cout << "\Êëèåíò äîáàâëåí...\n\n";
}
void editClients() {
}
int deleteClients(int position) {
if (headClient == NULL)
{
cout << "\nÑïèñîê ïóñò\n\n";
return 0;
}
if (headClient == headClient->nextClient)
{
delete headClient;
headClient = NULL;
}
else
{
Clients *a = headClient;
for (int i = position; i > 1; i--)
{
a = a->nextClient;
}
if (a == headClient)
{
headClient = a->nextClient;
}
a->prevClient->nextClient = a->nextClient;
a->nextClient->prevClient = a->prevClient;
delete a;
}
cout << "\nÝëåìåíò óäàëåí...\n\n";
}
};
int main(void)
{
setlocale(LC_ALL, "rus");
int x, y;
Work work;
string name;
do
{
cout << "1. Òàáëèöà êëèåíòîâ" << endl;
cout << "2. Òàáëèöà óñëóã" << endl;
cout << "3. Òàáëèöà îïëàò" << endl;
cout << "4. Òàáëèöà ðàñõîäîâ" << endl;
cout << "5. Îò÷åò çàäîëæåííîñòè" << endl;
cout << "6. Îò÷åò ïî òðàôèêó" << endl;
cout << "0. Âûéòè" << endl;
cout << "\nÍîìåð îïåðàöèè > ";
cin >> x;
switch (x)
{
case 1:
do
{
cout << "1. Çàãðóçèòü èç ôàéëà" << endl;
cout << "2. Äîáàâèòü" << endl;
cout << "3. Ðåäàêòèðîâàòü" << endl;
cout << "4. Óäàëèòü" << endl;
cout << "5. Ñïèñîê" << endl;
cout << "6. Ñîõðàíèòü â ôàéë" << endl;
cout << "0. Íàçàä" << endl;
cout << "\nÍîìåð îïåðàöèè > ";
cin >> y;
switch (y)
{
case 1:
{
string path;
cout << "Ïóòü ê ôàéëó > ";
cin >> path;
work.loadClients(path);
break;
}
case 2:
{
string name;
int phone;
cout << "NAME > ";
cin >> name;
cout << "PHONE > ";
cin >> phone;
work.addClients(name, phone, -1);
break;
}
case 3:
{
work.editClients();
break;
}
case 4:
int position;
cout << "ID > ";
cin >> position;
work.deleteClients(position);
break;
case 5:
work.showClients();
case 6:
//work.saveClients();
break;
}
} while (y!=0);
case 2:
break;
case 3:
break;
}
} while (x!=0);
}