Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //CREARE UNA STRUTTURA PER GESTIRE L'AGENZIA MATRIMONIALE
- //GENERARE UN DATABASE DI 100 PERSONE IN MODALITA' RANDOM
- //ATTRAVERSO UN MENU L'UTNETE PUO VISUALIZZARE
- //1) LE CARATTERISTICHE DATO IL NOME
- //2) IL NUMERO DI MASCHI E FEMMINE PRESENTI NEL DATABASE
- //3) IL NUMERO DI PERSONE SUDDIVISE PER hobbies
- // M = Maschio, F = Femmina; // Compatibilita obbligatoria
- // C = Centro, S = Sud, N = NORD; // Compatibilità obbligatoria
- // Interessato/a a uomini o donne; // Compatibilità obbligatoria
- // M = Musica, S = Sport, C = Cinema e Teatro, A = Arte e cultura;
- // True or False;
- #include <stdlib.h>
- #include <time.h>
- #include <windows.h>
- #include <string>
- #include <iostream>
- #include <iomanip>
- using namespace std;
- const int NUM=100;
- int const MAX=4;
- int const MIN=0;
- //Variabili globali utilizzate per la creazione automatica del database dei candidati;
- string nomi_maschili[20]={"Giovanni", "Matteo", "Lorenzo", "Alberto", "Guido", "Vittorio", "Emanuele", "Alessandro", "Antonio", "Gabriele", "Giorgio", "Rodolfo", "Alessio", "Andrea", "Alfonso", "Paolo", "Luca", "Alex", "Simone", "Claudio"};
- string nomi_femminili[20]={"Giada", "Alessia", "Federica", "Ginevra", "Eleonora", "Beatrice", "Maria", "Sara", "Chiara", "Daniela", "Anna", "Francesca", "Giulia", "Laura", "Camilla", "Matilde", "Aurora", "Monica", "Mara", "Barbara"};
- char sessi[2]={'F', 'M'};
- char zone[3]={'C', 'S', 'N'};
- char orientamenti[2]={'M', 'F'};
- char hobbies[4]={'M', 'S', 'C', 'A'};
- bool fumatori[2]={"si", "no"};
- struct date{
- int anno;
- int mese;
- int giorno;
- };
- struct agenzia{
- string nome;
- char sesso;
- char zona;
- char orientamenti;
- char hobbies;
- bool fumatori;
- date nascita;
- };
- //Prototipi
- void input(agenzia v[], int n);
- void numero(int &x, int min, int max, string s);
- void visua_menu();
- void menu(agenzia v[], int n);
- void caratteristiche(agenzia v[], int n);
- void quantita(agenzia v[], int n);
- void suddivisione_hobbies(agenzia v[], int n);
- void output(agenzia v[], int n);
- void visua_info();
- int main()
- {
- agenzia v[NUM];
- int n;
- numero(n,0,NUM,"Inserisci la numerosita': ");
- input(v,n);
- menu(v,n);
- }
- void numero(int &x, int min, int max, string s)
- {
- cout<<s;
- cin>>x;
- while(x<min or x>max)
- {
- cout<<"re"<<s;
- cin>>x;
- }
- }
- void input(agenzia v[], int n)
- {
- srand(time(NULL));
- for(int i=0 ; i<n ; i++)
- {
- v[i].sesso=sessi[rand()%3];
- if(v[i].sesso == 'M')
- {
- v[i].nome=nomi_maschili[rand()%21];
- }
- else
- {
- v[i].nome=nomi_femminili[rand()%21];
- }
- v[i].zona=zone[rand()%4];
- v[i].orientamenti=orientamenti[rand()%3];
- v[i].hobbies=hobbies[rand()%4];
- v[i].fumatori=fumatori[rand()%3];
- v[i].nascita.anno=1920+rand()%81;
- v[i].nascita.mese=1+rand()%12;
- v[i].nascita.giorno=1+rand()%31;
- }
- }
- void visua_menu()
- {
- cout<<endl;
- cout<<"\t AGENZIA MATRIMONIALE"<<endl;
- cout<<"1) LE CARATTERISTICHE DATO IL NOME"<<endl;
- cout<<"2) IL NUMERO DI MASCHI E FEMMINE PRESENTI NEL DATABASE"<<endl;
- cout<<"3) IL NUMERO DI PERSONE SUDDIVISE PER hobbies"<<endl;
- cout<<endl;
- }
- void menu(agenzia v[], int n)
- {
- int sc;
- output(v,n);
- cout<<endl;
- visua_menu();
- //numero(sc,"inserisci la scelta: ");
- do{
- numero(sc,MIN,MAX,"inserisci la scelta: ");
- switch(sc)
- {
- case 0:
- system("exit");
- break;
- case 1:
- caratteristiche(v,n);
- break;
- case 2:
- quantita(v,n);
- break;
- case 3:
- suddivisione_hobbies(v,n);
- break;
- }
- system("pause");
- system("cls");
- visua_menu();
- }while(sc != 0);
- }
- void caratteristiche(agenzia v[], int n)
- {
- string nm;
- bool pres=false;
- cout<<"Inserisci il nome della persona che vuoi cercare: ";
- cin>>nm;
- visua_info();
- for(int i=0 ; i<n ; i++)
- {
- if(v[i].nome == nm)
- {
- pres=true;
- cout<<v[i].nome<<setw(10)<<right;
- cout<<v[i].nascita.anno<<"-";
- cout<<v[i].nascita.mese<<"-";
- cout<<v[i].nascita.giorno<<setw(10);
- cout<<v[i].sesso<<setw(10)<<right;
- cout<<v[i].zona<<setw(10)<<right;
- cout<<v[i].orientamenti<<setw(10)<<right;
- cout<<v[i].hobbies<<setw(11)<<right;
- cout<<v[i].fumatori<<setw(10)<<right;
- cout<<endl;
- }
- }
- if(pres==false) cout<<nm<<" non e' presente nel database!"<<endl;
- }
- void quantita(agenzia v[], int n)
- {
- int m=0, f=0;
- for(int i=0 ; i<n ; i++)
- {
- if(v[i].sesso == 'M')
- {
- m++;
- }
- else
- {
- f++;
- }
- }
- cout<<"Maschi"<<setw(10);
- cout<<"Femmine"<<endl;
- cout<<m<<setw(9)<<f<<endl;
- }
- void suddivisione_hobbies(agenzia v[], int n)
- {
- int musica=0,sport=0,cinema=0,arte=0;
- for(int i=0 ; i<n ; i++)
- {
- switch(v[i].hobbies)
- {
- case 'M':
- musica++;
- break;
- case 'S':
- sport++;
- break;
- case 'C':
- cinema++;
- break;
- case 'A':
- arte++;
- break;
- }
- }
- cout<<"Musica"<<setw(10);
- cout<<"Sport"<<setw(10);
- cout<<"Cinema"<<setw(10);
- cout<<"Arte"<<endl;
- cout<<musica<<setw(11);
- cout<<sport<<setw(11);
- cout<<cinema<<setw(11);
- cout<<arte<<setw(11)<<endl;
- }
- void output(agenzia v[], int n)
- {
- visua_info();
- for(int i=0 ; i<n ; i++)
- {
- // cout<<right;
- cout<<v[i].nome<<setw(10)<<right;
- cout<<v[i].nascita.anno<<"-"<<right;
- cout<<v[i].nascita.mese<<"-"<<right;
- cout<<v[i].nascita.giorno<<setw(10);
- cout<<v[i].sesso<<setw(10)<<right;
- cout<<v[i].zona<<setw(10)<<right;
- cout<<v[i].orientamenti<<setw(10)<<right;
- cout<<v[i].hobbies<<setw(11)<<right;
- cout<<v[i].fumatori<<setw(10)<<right;
- cout<<endl;
- }
- }
- void visua_info()
- {
- cout<<setw(10);
- cout<<"Nome"<<setw(15);
- cout<<"Nascita"<<setw(10);
- cout<<"Sesso"<<setw(10);
- cout<<"Zona"<<setw(15);
- cout<<"Orientamento"<<setw(10);
- cout<<"Hobbies"<<setw(10);
- cout<<"Fumatore"<<setw(10)<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement