-
Notifications
You must be signed in to change notification settings - Fork 0
/
Order.cpp
61 lines (55 loc) · 1.02 KB
/
Order.cpp
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
#include "Order.h"
Order::Order()
{
this->id = 1;
this->sum = 0;
}
Order::Order(const Order& other)
{
this->id = other.id;
this->sum = other.sum;
}
Order& Order::operator=(const Order& other)
{
if (this != &other)
{
this->id = other.id;
this->sum = other.sum;
}
return *this;
}
void Order::setSum(double sum)
{
this->sum = sum;
}
void Order::generateId()
{
this->id = 1;
int fileId;
this->idCounter.open("IDs.txt", ios::in);
if (this->idCounter.is_open())
{
while (idCounter >> fileId)
{
this->id++;
}
}
this->idCounter.close();
}
void Order::writeOrderToLog()
{
this->idCounter.open("IDs.txt", ios::out | ios::app);
if (this->idCounter.is_open())
{
idCounter << this->id << endl;
}
this->orderHistory.close();
this->orderHistory.open("orders.txt", ios::out | ios::app);
if (this->orderHistory.is_open())
{
time_t ttime = time(0);
char* dt = ctime(&ttime);
orderHistory << "ID: " << this->id << ", " << "Date: " << dt << ", " << "Sum: " << this->sum << endl;
}
this->orderHistory.close();
}