#include <iostream> #include <sstream> #include <ctime> #include <unistd.h> using namespace std; #define M 5 struct Cosa{ string nome="Pippo"; int pos; int q; }; struct Persona{ string nome; Cosa oggetto; double soldi; }; struct Negozio{ string nome; Cosa cose[M]; int N=M; Persona commessa; double fatturato; }; struct Centro{ string nome; Negozio negozi[M]; int N=M; }; void inizializzaNegozio(Negozio &neg, string nome){ srand(time(0)); string nomi[]={"Ada","Gioia","Aurora","Tonia","Eva"}; neg.nome=nome; neg.commessa.nome=nomi[rand()%5]; stringstream ss; for(int i=0;i<neg.N;i++) { ss.str(""); ss<<"Cosa_"<< i; neg.cose[i].nome= ss.str(); neg.cose[i].q=10+i; } } void preleva(Negozio &neg,int pos,int quant){ if(neg.cose[pos].q >= quant) { neg.cose[pos].q -=quant; }else { neg.cose[pos].q=0; cout << "scorte non sufficienti!!!\n"; } } void deposita(Negozio &neg,int pos,int quant){ neg.cose[pos].q += quant; } void stampaNegozio(Negozio neg){ cout<<neg.nome<<" gestita da "+neg.commessa.nome+" ha "<<neg.N<<" parti:\n"; for(int i=0;i<neg.N;i++) cout<<neg.cose[i].nome<<" con la quantita\' di "<< neg.cose[i].q<<"\n"; } void gestioneNegozio(Negozio &neg,string nome){ inizializzaNegozio(neg, nome); stampaNegozio(neg); preleva(neg,2,5); deposita(neg,0,7); stampaNegozio(neg); } int main() { cout << "Centro commerciale" << endl; for(int i=0;i<M;i++){ switch (i+1){ case 1: Negozio emporio; gestioneNegozio(emporio,"Ferramenta"); break; case 2: Negozio farmacia; gestioneNegozio(farmacia,"Farmacia"); break; case 3: Negozio frutta; gestioneNegozio(frutta,"Frutta e verdura"); break; case 4: Negozio giochi; gestioneNegozio(giochi,"GameStop"); break; case 5: Negozio ottica; gestioneNegozio(ottica,"Ottica"); break; }; } return 0; }
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more