Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.74 KB | None | 0 0
  1. //CREARE UNA STRUTTURA PER GESTIRE L'AGENZIA MATRIMONIALE
  2. //GENERARE UN DATABASE DI 100 PERSONE IN MODALITA' RANDOM
  3. //ATTRAVERSO UN MENU L'UTNETE PUO VISUALIZZARE
  4. //1) LE CARATTERISTICHE DATO IL NOME
  5. //2) IL NUMERO DI MASCHI E FEMMINE PRESENTI NEL DATABASE
  6. //3) IL NUMERO DI PERSONE SUDDIVISE PER hobbies
  7.  
  8.     // M = Maschio, F = Femmina;           // Compatibilita obbligatoria
  9.     // C = Centro, S = Sud, N = NORD;      // Compatibilità obbligatoria
  10.     // Interessato/a a uomini o donne;     // Compatibilità obbligatoria
  11.     // M = Musica, S = Sport, C = Cinema e Teatro, A = Arte e cultura;
  12.     // True or False;
  13.  
  14. #include <stdlib.h>
  15. #include <time.h>
  16. #include <windows.h>
  17. #include <string>
  18. #include <iostream>
  19. #include <iomanip>
  20. using namespace std;
  21.  
  22. const int NUM=100;
  23. int const MAX=4;
  24. int const MIN=0;
  25.  
  26. //Variabili globali utilizzate per la creazione automatica del database dei candidati;
  27.     string nomi_maschili[20]={"Giovanni", "Matteo", "Lorenzo", "Alberto", "Guido", "Vittorio", "Emanuele", "Alessandro", "Antonio", "Gabriele", "Giorgio", "Rodolfo", "Alessio", "Andrea", "Alfonso", "Paolo", "Luca", "Alex", "Simone", "Claudio"};
  28.     string nomi_femminili[20]={"Giada", "Alessia", "Federica", "Ginevra", "Eleonora", "Beatrice", "Maria", "Sara", "Chiara", "Daniela", "Anna", "Francesca", "Giulia", "Laura", "Camilla", "Matilde", "Aurora", "Monica", "Mara", "Barbara"};
  29.     char sessi[2]={'F', 'M'};
  30.     char zone[3]={'C', 'S', 'N'};
  31.     char orientamenti[2]={'M', 'F'};
  32.     char hobbies[4]={'M', 'S', 'C', 'A'};
  33.     bool fumatori[2]={"si", "no"};
  34.  
  35. struct  date{
  36.     int anno;
  37.     int mese;
  38.     int giorno;
  39. };
  40.  
  41.  
  42. struct agenzia{
  43.     string nome;
  44.     char sesso;
  45.     char zona;
  46.     char orientamenti;
  47.     char hobbies;
  48.     bool fumatori;
  49.     date nascita;
  50. };
  51.  
  52. //Prototipi
  53. void input(agenzia v[], int n);
  54. void numero(int &x, int min, int max, string s);
  55. void visua_menu();
  56. void menu(agenzia v[], int n);
  57. void caratteristiche(agenzia v[], int n);
  58. void quantita(agenzia v[], int n);
  59. void suddivisione_hobbies(agenzia v[], int n);
  60. void output(agenzia v[], int n);
  61. void visua_info();
  62.  
  63. int main()
  64. {
  65.     agenzia v[NUM];
  66.     int n;
  67.     numero(n,0,NUM,"Inserisci la numerosita': ");
  68.     input(v,n);
  69.     menu(v,n);
  70. }
  71.  
  72. void numero(int &x, int min, int max, string s)
  73. {
  74.     cout<<s;
  75.     cin>>x;
  76.     while(x<min or x>max)
  77.     {
  78.         cout<<"re"<<s;
  79.         cin>>x;
  80.     }
  81. }
  82.  
  83.  
  84. void input(agenzia v[], int n)
  85. {
  86.     srand(time(NULL));
  87.     for(int i=0 ; i<n ; i++)
  88.     {
  89.         v[i].sesso=sessi[rand()%3];
  90.         if(v[i].sesso == 'M')
  91.         {
  92.             v[i].nome=nomi_maschili[rand()%21];
  93.         }
  94.         else
  95.         {
  96.             v[i].nome=nomi_femminili[rand()%21];
  97.         }
  98.         v[i].zona=zone[rand()%4];
  99.         v[i].orientamenti=orientamenti[rand()%3];
  100.         v[i].hobbies=hobbies[rand()%4];
  101.         v[i].fumatori=fumatori[rand()%3];
  102.         v[i].nascita.anno=1920+rand()%81;
  103.         v[i].nascita.mese=1+rand()%12;
  104.         v[i].nascita.giorno=1+rand()%31;
  105.     }
  106. }
  107.  
  108. void visua_menu()
  109. {
  110.     cout<<endl;
  111.     cout<<"\t AGENZIA MATRIMONIALE"<<endl;
  112.     cout<<"1) LE CARATTERISTICHE DATO IL NOME"<<endl;
  113.     cout<<"2) IL NUMERO DI MASCHI E FEMMINE PRESENTI NEL DATABASE"<<endl;
  114.     cout<<"3) IL NUMERO DI PERSONE SUDDIVISE PER hobbies"<<endl;
  115.     cout<<endl;
  116. }
  117.  
  118. void menu(agenzia v[], int n)
  119. {
  120.     int sc;
  121.     output(v,n);
  122.     cout<<endl;
  123.     visua_menu();
  124.     //numero(sc,"inserisci la scelta: ");
  125.     do{
  126.         numero(sc,MIN,MAX,"inserisci la scelta: ");
  127.         switch(sc)
  128.         {
  129.             case 0:
  130.                 system("exit");
  131.                 break;
  132.             case 1:
  133.                 caratteristiche(v,n);
  134.                 break;
  135.             case 2:
  136.                 quantita(v,n);
  137.                 break; 
  138.             case 3:
  139.                 suddivisione_hobbies(v,n);
  140.                 break;
  141.         }
  142.         system("pause");
  143.         system("cls");
  144.         visua_menu();
  145.     }while(sc != 0);
  146. }
  147.  
  148. void caratteristiche(agenzia v[], int n)
  149. {
  150.     string nm;
  151.     bool pres=false;
  152.     cout<<"Inserisci il nome della persona che vuoi cercare: ";
  153.     cin>>nm;
  154.     visua_info();
  155.    
  156.     for(int i=0 ; i<n ; i++)
  157.     {
  158.         if(v[i].nome == nm)    
  159.         {
  160.             pres=true;
  161.             cout<<v[i].nome<<setw(10)<<right;
  162.             cout<<v[i].nascita.anno<<"-";
  163.             cout<<v[i].nascita.mese<<"-";
  164.             cout<<v[i].nascita.giorno<<setw(10);
  165.             cout<<v[i].sesso<<setw(10)<<right;
  166.             cout<<v[i].zona<<setw(10)<<right;
  167.             cout<<v[i].orientamenti<<setw(10)<<right;
  168.             cout<<v[i].hobbies<<setw(11)<<right;
  169.             cout<<v[i].fumatori<<setw(10)<<right;
  170.             cout<<endl;
  171.         }
  172.     }
  173.     if(pres==false)     cout<<nm<<" non e' presente nel database!"<<endl;
  174. }
  175.  
  176. void quantita(agenzia v[], int n)
  177. {
  178.     int m=0, f=0;
  179.     for(int i=0 ; i<n ; i++)
  180.     {
  181.         if(v[i].sesso == 'M')
  182.         {
  183.             m++;
  184.         }
  185.         else
  186.         {
  187.             f++;
  188.         }
  189.     }
  190.     cout<<"Maschi"<<setw(10);
  191.     cout<<"Femmine"<<endl;
  192.     cout<<m<<setw(9)<<f<<endl;
  193. }
  194.  
  195. void suddivisione_hobbies(agenzia v[], int n)
  196. {
  197.     int musica=0,sport=0,cinema=0,arte=0;
  198.     for(int i=0 ; i<n ; i++)
  199.     {
  200.         switch(v[i].hobbies)
  201.         {
  202.             case 'M':
  203.                 musica++;
  204.                 break;
  205.                
  206.             case 'S':
  207.                 sport++;
  208.                 break;
  209.            
  210.             case 'C':
  211.                 cinema++;
  212.                 break;
  213.                
  214.             case 'A':
  215.                 arte++;
  216.                 break;
  217.         }
  218.     }
  219.     cout<<"Musica"<<setw(10);
  220.     cout<<"Sport"<<setw(10);
  221.     cout<<"Cinema"<<setw(10);
  222.     cout<<"Arte"<<endl;
  223.     cout<<musica<<setw(11);
  224.     cout<<sport<<setw(11);
  225.     cout<<cinema<<setw(11);
  226.     cout<<arte<<setw(11)<<endl;
  227. }
  228.  
  229. void output(agenzia v[], int n)
  230. {
  231.     visua_info();
  232.     for(int i=0 ; i<n ; i++)
  233.     {
  234.     //  cout<<right;
  235.         cout<<v[i].nome<<setw(10)<<right;
  236.         cout<<v[i].nascita.anno<<"-"<<right;
  237.         cout<<v[i].nascita.mese<<"-"<<right;
  238.         cout<<v[i].nascita.giorno<<setw(10);
  239.         cout<<v[i].sesso<<setw(10)<<right;
  240.         cout<<v[i].zona<<setw(10)<<right;
  241.         cout<<v[i].orientamenti<<setw(10)<<right;
  242.         cout<<v[i].hobbies<<setw(11)<<right;
  243.         cout<<v[i].fumatori<<setw(10)<<right;
  244.         cout<<endl;
  245.     }
  246. }
  247.  
  248. void visua_info()
  249. {
  250.     cout<<setw(10);
  251.     cout<<"Nome"<<setw(15);
  252.     cout<<"Nascita"<<setw(10);
  253.     cout<<"Sesso"<<setw(10);
  254.     cout<<"Zona"<<setw(15);
  255.     cout<<"Orientamento"<<setw(10);
  256.     cout<<"Hobbies"<<setw(10);
  257.     cout<<"Fumatore"<<setw(10)<<endl;
  258. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement