Юра. Отчет. ВК.

  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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
class cGOODS{
private:
public:
int goodsId_, goodsCount_;
double goodsPrice_;
string goodsName_;
cGOODS() : goodsId_(1), goodsName_("Empty"), goodsPrice_(1), goodsCount_(1){}
cGOODS(int goodsId, string goodsName, double goodsPrice, int goodsCount) : goodsCount_(goodsCount), goodsId_(goodsId), goodsName_(goodsName), goodsPrice_(goodsPrice){}
//cGOODS::cGOODS(cGOODS &cGoods){ *this = cGoods; }
double getGoodsSum()
{
return goodsCount_ * goodsPrice_;
}
};
class UI{
protected:
template <typename T> static void InputValue(const char *message, T value){
cout << message; cin >> value;
}
static void Pause(){
cin.clear();
cin.sync();
cin.get();
}
static void OutputLine(){
cout << "\n******************************************************************\n";
}
static void GetTimeNow(string &DateToday, string &TimeNow){
char *temp = new char[4];
time_t t = time(NULL);
struct tm *t_m = localtime(&t);
_itoa(t_m->tm_mday, temp, 10);
DateToday = temp;
if (strlen(temp) < 2)
DateToday = "0" + DateToday;
DateToday += '.';
_itoa(t_m->tm_mon + 1, temp, 10);
if (strlen(temp) < 2)
DateToday += "0" + temp[0];
else DateToday += temp;
DateToday += '.';
_itoa(t_m->tm_year + 1900, temp, 10);
DateToday += temp;
*temp = NULL;
TimeNow = _itoa(t_m->tm_hour, temp, 10);
if (strlen(temp) < 2) TimeNow = "0" + TimeNow;
else TimeNow += temp;
*temp = NULL;
TimeNow += ':';
_itoa(t_m->tm_min, temp, 10);
if (strlen(temp) < 2)
TimeNow += ("0" + temp[0]);
else TimeNow += temp;
*temp = NULL;
TimeNow += ':';
_itoa(t_m->tm_sec, temp, 10);
if (strlen(temp) < 2)
TimeNow += ("0" + temp[0]);
else TimeNow += temp;
}
};
#pragma region "ХЗ"
class Check :UI
{
private:
vector<cGOODS> goods_;
int receiptId_;
string receiptDate_;
string receiptTime_;
void add(){
system("CLS");
cGOODS thisGoods;
OutputLine();
InputValue("\nID товара: ", thisGoods.goodsId_);
InputValue("Имя товара: ", thisGoods.goodsName_);
InputValue("Цена товара: ", thisGoods.goodsPrice_);
InputValue("Количество товара: ", thisGoods.goodsCount_);
OutputLine();
goods_.push_back(thisGoods);
Pause();
}
void del(){
system("CLS");
int Id = 0;
InputValue("Введите ID товара: ", Id);
if (searchGoodsById(Id) == -1) cout << "Данный товар не найден!" << endl;
else
{
deleteGoodsByIndex(searchGoodsById(Id));
cout << "Товар удалено!" << endl;
}
Pause();
}
void chn(){
system("CLS");
int Id = 0, count = 0;
string name;
double price = 0;
InputValue("Введите ID товара: ", Id);
int newId = 0;
if (searchGoodsById(Id) == -1) cout << "Данный товар не найден!" << endl;
else
{
OutputLine();
InputValue("\nID товара: ", newId);
InputValue("Имя товара: ", name);
InputValue("Цена товара: ", price);
InputValue("Количество товара: ", count);
OutputLine();
changeGoodsByIndex(searchGoodsById(Id), name, price, count, newId);
}
Pause();
system("CLS");
}
void prnt(){
system("CLS");
OutputLine();
cout << "ID чека: " << this->receiptId_ << endl << "Дата создания: " << this->receiptDate_ << endl << "Время создания: " << this->receiptTime_ << endl << "*************************" << endl;
for (int i(0); i < this->goods_.size(); i++) getGoodsInfoByIndex(i);
cout << "Сумма: " << getAllSum() << " рублей" << endl << "Спасибо за покупку !" << endl << "*************************" << endl;
Pause();
}
public:
Check() :receiptId_(1), receiptDate_("01.01.2015"), receiptTime_("00:00:00"){}
Check(int receiptId, string receiptDate, string receiptTime) : receiptId_(receiptId), receiptDate_(receiptDate), receiptTime_(receiptTime){}
Check(Check &receipt)
{
*this = receipt;
}
cGOODS operator[](int i)
{
return goods_[i];
}
void Menu()
{
GetTimeNow(receiptDate_, receiptTime_);
int command;
InputValue("Введите ID чека: ", receiptId_);
system("CLS");
while (true){
OutputLine();
cout << "ID чека: " << this->receiptId_ << endl << "Дата создания: " << this->receiptDate_ << endl << "Время создания: " << this->receiptTime_;
OutputLine();
cout << "Действия:" << endl;
cout << "1. Добавить товар в чек;" << endl;
cout << "2. Удалить товар из чека;" << endl;
cout << "3. Изменить товар в чеке" << endl;
cout << "4. Распечатать чек;" << endl;
cout << "5. Выход;" << endl;
cout << "Выбор: ";
cin >> command;
switch (command){
case 1:{ add(); break; }
case 2:{ del(); break; }
case 3:{ chn(); break; }
case 4:{ prnt(); break; }
case 5:{ return; }
default:
{
cout << "Ничего не выбрано, повторите попытку! " << endl;
Pause();
break;
}
}
}
}
int searchGoodsById(int goodsId)
{
if (this->goods_.size() < 2 && this->goods_[0].goodsId_ == goodsId) return 0;
if (this->goods_.size() < 2 && this->goods_[0].goodsId_ != goodsId) return -1;
int left = 0, right = this->goods_.size(), middle;
while (left <= right){
middle = left + (right - left) / 2;
if (goodsId < this->goods_[middle].goodsId_) right = middle - 1;
else if (goodsId > this->goods_[middle].goodsId_) left = middle + 1;
else return middle;
}
return -1;
}
void Check::deleteGoodsByIndex(int goodsIndex)
{
this->goods_.erase(this->goods_.begin() + goodsIndex);
}
void Check::addGoods(cGOODS goods)
{
this->goods_.push_back(goods);
}
void Check::changeGoodsByIndex(int goodsIndex, string goodsName, double goodsPrice, int goodsCount, int goodsId)
{
this->goods_[goodsIndex].goodsPrice_ = goodsPrice;
this->goods_[goodsIndex].goodsName_ = goodsName;
this->goods_[goodsIndex].goodsCount_ = goodsCount;
this->goods_[goodsIndex].goodsId_ = goodsId;
}
void Check::getGoodsInfoByIndex(int goodsIndex)
{
OutputLine();
cout << "ID товара: " << this->goods_[goodsIndex].goodsId_ << endl << "Имя товара: " << this->goods_[goodsIndex].goodsName_ << endl << "Цена единицы товара: " << this->goods_[goodsIndex].goodsPrice_ << endl << "Количество товара: " << this->goods_[goodsIndex].goodsCount_ << endl << "Сумма: " << this->goods_[goodsIndex].getGoodsSum() << endl;
OutputLine();
}
double Check::getAllSum()
{
double sum = 0;
for (int i(0); i < this->goods_.size(); i++)sum += goods_[i].getGoodsSum();
return sum;
}
};
#pragma endregion
int main()
{
setlocale(0, "");
Check rec;
rec.Menu();
return 0;
}