-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArticle.cpp
140 lines (111 loc) · 3.66 KB
/
Article.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
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
#include <iostream>
#include <utility>
#include "Article.h"
// Constructor
Article::Article(int numberOfArticles, int orderDuration, double costPrice, std::string description,
int maximumStock, int consumption, int articleNumber) :
numberOfArticles(numberOfArticles),
orderDuration(orderDuration),
costPrice(costPrice),
description(std::move(description)),
stock(articleNumber, numberOfArticles, maximumStock, consumption) {}
Article::Article() {}
int Article::getArticleNumber() const {
return stock.getArticleNumber();
}
void Article::setArticleNumber(int articleNumber) {
stock.setArticleNumber(articleNumber);
}
int Article::getActualStock() const {
return stock.getActualStock();
}
void Article::setActualStock(int actualStock) {
stock.setActualStock(actualStock);
}
int Article::getMaximumStock() const {
return stock.getMaximumStock();
}
void Article::setMaximumStock(int maximumStock) {
stock.setMaximumStock(maximumStock);
}
int Article::getConsumption() const {
return stock.getConsumption();
}
void Article::setConsumption(int consumption) {
stock.setConsumption(consumption);
}
int Article::getNumberOfArticles() const {
return numberOfArticles;
}
void Article::setNumberOfArticles(int numberOfArticles) {
Article::numberOfArticles = numberOfArticles;
}
void Article::setOrderDuration(int orderDuration) {
Article::orderDuration = orderDuration;
}
void Article::setCostPrice(double costPrice) {
Article::costPrice = costPrice;
}
void Article::setDescription(const std::string &description) {
Article::description = description;
}
int Article::getOrderDuration() const {
return orderDuration;
}
double Article::getCostPrice() const {
return costPrice;
}
const std::string &Article::getDescription() const {
return description;
}
const Stock &Article::getStock() const {
return stock;
}
void Article::setStock(const Stock &stock) {
Article::stock = stock;
}
// Functions
void Article::toString() {
std::cout << "No: " << getArticleNumber() << " ,Description: " << getDescription() <<
" ,Actual Stock: " << getNumberOfArticles() << " , Maximum Stock: " << getMaximumStock() <<
" ,Cost Price: " << getCostPrice() << " Euros" << " ,Consumption per Day: "
<< getConsumption() <<
" ,Order Duration: " << getOrderDuration() << std::endl;
}
double Article::totalStockValue() {
return getActualStock() * getCostPrice();
}
std::string Article::orderProposal(int resultFromOrderPoint) {
std::string result = "Order " + std::to_string(getMaximumStock());
if (resultFromOrderPoint > 0) {
return result + " in " + std::to_string(resultFromOrderPoint) + " Days.";
} else {
return result + " immediately.";
}
}
// Calculating the order point
int Article::orderPoint() {
int reserve = 2;
int result = ((getActualStock() / getConsumption())) - reserve;
if (result > getOrderDuration()) {
// returning how many stocks sufficient for more than the orderDuration
return result - getOrderDuration();
} else {
// returning 0 which means we need to order immediately
return 0;
}
}
std::ostream &Article::writeToFile(std::ostream &out) {
std::string temp;
out << getArticleNumber() << "\t\t" <<
getDescription() << "\t\t" <<
getActualStock() << "\t\t" <<
getMaximumStock() << "\t\t" <<
getCostPrice() << "\t\t" <<
getConsumption() << "\t\t" <<
getOrderDuration()<< "\t\t" <<
totalStockValue()<< "\t\t" <<
orderPoint()<< "\t\t" <<
orderProposal(orderPoint()) << "\t\t\n";
return out;
}