-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
246 lines (155 loc) · 5.65 KB
/
main.cpp
File metadata and controls
246 lines (155 loc) · 5.65 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
233
234
235
236
237
238
239
240
241
242
243
244
245
//
// main.cpp
// Progetto 1 Nunzio Depetro
//
// Created by Nuccio Depetro on 08/07/21.
//
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include "ListaDL.h"
using namespace std;
void ComandeFile(const string& str, string cont[4])
{
char delim = ',';
stringstream ss(str);
string token;
int i = 0;
while (getline(ss, token, delim)) {
cont[i] = token;
i++;
if(i==4) break;
}
}
//carico i dati del file .txt contenente le comande all'interno delle mie liste
static int punto1(const string filename, ListaDL& ls)
{
ifstream file;
string line;
string buff[4];
Cliente g;
file.open(filename);
int num = 0;
if(file.is_open())
{
while(getline(file, line)){
ComandeFile(line,buff);
g = Cliente(buff[0],buff[1],stoi(buff[2]),stod(buff[3]));
ls.inserisci(g);
num++;
}
file.close();
}
else
cout << "Non posso aprire il file!" << endl;
return num;
}
static void punto2(ListaDL& ls){
Nodo* iter=ls.getTesta();
string persona="";
string persona2="";
cout<<iter->valore.getCognome()<<endl;;
while(iter!=nullptr){
persona=iter->valore.getCognome();
if(iter->succ!=nullptr){
persona2=iter->succ->valore.getCognome();
if(persona==persona2){
cout <<"Pizza: "<< iter->valore.getPizza() << "\t Quantità:"<<iter->valore.getQuantita()<<"\tPrezzo : "<<iter->valore.getPrezzo()<<"€"<<endl;;
}
else{
cout <<"Pizza: "<< iter->valore.getPizza() << "\t Quantità:"<<iter->valore.getQuantita()<<"\tPrezzo : "<<iter->valore.getPrezzo()<<"€"<<endl;;
cout<<"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"<<endl;
cout<<"Stampo ordine: "<<persona2<<endl;
cout<<endl;
}
}
if(iter->succ==nullptr) cout <<"Pizza: "<< iter->valore.getPizza() << "\t Quantità:"<<iter->valore.getQuantita()<<"\tPrezzo : "<<iter->valore.getPrezzo()<<"€"<<endl;;
iter=iter->succ;
}
cout<<"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"<<endl;
}
//Metodo che stampa unicamente il cognome con ordine annesso ricercato dall'utente
static void punto3(ListaDL& ls, string cliente){
Cliente gg;
gg.setCognome(cliente);
Nodo* valore_cercato =ls.ricerca(gg);
Nodo* iter;
string persona=cliente;
double prezzo=0;
bool trovato=false;
iter = valore_cercato;
while(iter!=nullptr){
if (iter->valore.getCognome()==persona){ //stampo solo il cognome cercato con i relativi ordini
cout << iter->valore;
prezzo+=iter->valore.getPrezzo()*iter->valore.getQuantita();
trovato=true;
}
iter = iter->succ;
}
if(trovato==false)cout<<"Nessun Cliente trovato con questo cognome: "<<persona<<" !"<<endl;
cout<<endl;
cout<<"Prezzo totale speso: "<<prezzo<<"€"<<endl;
}
static bool punto4(ListaDL& ls){
Cliente cl;
Nodo* iter = ls.getTesta();
Nodo*tmp;
double prezzo=0;
double media;
int cont=0;
while(iter!=nullptr){
prezzo+=iter->valore.getPrezzo();
cont++;
iter = iter->succ;
}
media=prezzo/cont;
cout<<"La media spesa nella pizzeria è di: "<<media<<endl;
bool ret_val = false;
iter=ls.getTesta();
ofstream fout("eliminati.txt");; //creo il file txt
while(iter!=nullptr){
tmp=iter->succ;
if((iter->valore.getPrezzo()*iter->valore.getQuantita())<media ){
ret_val = true;
cout << "Elimino Ordine di:\t"<< iter->valore.getCognome()<< endl;
cout << iter->valore << endl;
cl.setCognome(iter->valore.getCognome());
fout<<iter->valore; //scrivo il valore nel file
ls.rimuovi(cl);
}
iter = tmp;
}
fout.close();
cout<<"File con gli ordini eliminati Salvato!"<<endl;
iter=ls.getTesta();
cout<<"Lista Aggiornata: \t"<<endl;
while(iter!=nullptr){
cout<<iter->valore<<endl;
iter=iter->succ;
}
return ret_val;
}
int main(){
int stampafile;
ListaDL listaCliente;
ListaDL listaClienteO;
stampafile = punto1("Comande.txt", listaCliente);
cout<<"---------------CARICO FILE ORDINI-----------------"<<endl;
cout << endl <<"----------------PRIMO PUNTO--------------------" << endl;
cout << endl <<"-----------------------------------------------" << endl;
cout << listaCliente;
cout << endl <<"----------------SECONDO PUNTO--------------------" << endl;
cout << endl <<"-----------------------------------------------" << endl;
punto2(listaCliente);
cout << endl <<"----------------TERZO PUNTO-------------------" << endl;
cout << endl <<"-----------------------------------------------" << endl;
string str;
cout << "Inserisci il cognome delL Cliente da cercare:\n (si prega di inserire la prima lettera del cognome in maiuscolo)"<<endl;;
cin >> str;
punto3(listaCliente,str);
cout << endl <<"----------------QUARTO PUNTO--------------------" << endl;
cout << endl <<"-----------------------------------------------" << endl;
punto4(listaCliente);
return 0;
}