-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProdotto.cpp
More file actions
181 lines (124 loc) · 3.82 KB
/
Copy pathProdotto.cpp
File metadata and controls
181 lines (124 loc) · 3.82 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
#include <iostream>
#include <vector>
using namespace std;
class Prodotto {
private:
int code;
double price;
public:
Prodotto(int code, double price) : code(code), price(price) {}
const int& get_code() {
return code;
}
const double& get_price() {
return price;
}
void set_code(int code) {
this->code = code;
}
void set_price(double price) {
this->price = price;
}
virtual void print() const {
cout << "Codice Prodotto: " << code << " Prezzo Prodotto: " << price << endl;
}
friend ostream& operator<< (ostream& os, Prodotto& p){
p.print();
return os;
}
virtual bool verify() const {
return true;
}
virtual ~Prodotto() {}
};
class ProdottoAlimentare : public Prodotto {
private:
int expire;
public:
ProdottoAlimentare(int code, double price, int expire) :
Prodotto(code, price), expire(expire) {}
bool verify() const override {
if(expire < 2025 ){
return false;
}else{
return true;
}
}
void print() const override {
Prodotto::print();
cout << "Data di Scadenza: " << expire << endl;
}
};
class ProdottoPerBambini : public Prodotto {
private:
string years;
public:
ProdottoPerBambini(int code, double price, string years) :
Prodotto(code, price) , years(years) {}
void print() const override {
Prodotto::print();
cout << " Fascia di eta': " << years << "anni" << endl;
}
};
class Venditore {
private:
int vencode;
Prodotto** elenco;
int size;
public:
Venditore(int vencode, Prodotto** elenco, int size) : vencode(vencode), elenco(elenco), size(size) {}
friend ostream& operator<< (ostream& os, Venditore& v) {
os << " Codice Venditore" << v.vencode << endl;
for(int i = 0; i<v.size; i++){
os << *(v.elenco[i]) << endl;
}
return os;
}
double CalcolaPrezzoTotale() {
double totale = 0;
for(int i = 0; i<size; i++) {
totale += elenco[i]->get_price();
}
return totale;
}
void addProdotto(Prodotto *p) {
Prodotto** nuovo_elenco = new Prodotto*[size+1];
//copio vecchi elementi
for(int i = 0; i<size; i++){
nuovo_elenco[i] = elenco[i];
}
nuovo_elenco[size] = p;
delete[] elenco;
elenco = nuovo_elenco;
size++;
}
double CalcolaValoreMagazzino() {
double totale = 0;
for(int i = 0; i<size; i++) {
if(elenco[i]->verify()){
totale += elenco[i]->get_price();
}
}
return totale;
}
};
int main() {
Prodotto* elenco[4];
elenco[0] = new ProdottoAlimentare(9, 5.80, 2027);
elenco[1] = new ProdottoPerBambini(10, 3.20, "10-15");
elenco[2] = new ProdottoAlimentare(11, 10.50, 2028);
elenco[3] = new ProdottoAlimentare(20, 7.80, 2024);
Venditore v5(34, elenco, 4);
cout << v5 << endl;
cout << "Prezzo Totale: "<< v5.CalcolaPrezzoTotale() << " euro" << endl;
cout << "Valore Magazzino: "<< v5.CalcolaValoreMagazzino() << " euro" << endl;
Venditore v1(756, nullptr, 0);
Venditore v2(453, nullptr, 0);
Venditore v3(350, nullptr, 0);
v1.addProdotto(new ProdottoAlimentare(1, 3.50, 2026));
v1.addProdotto(new ProdottoAlimentare(4, 7.50, 2024));
v1.addProdotto(new ProdottoPerBambini(5, 20.00, "4-6"));
// v1.CalcolaPrezzoTotale();
cout << "Prezzo Totale: "<< v1.CalcolaPrezzoTotale() << " euro" << endl;
cout << v1 <<endl;
}