Guest User

Untitled

a guest
Jun 17th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. #include<iostream.h>
  2. #include<iomanip.h>
  3. #include<cstring>
  4. #include<fstream.h>
  5.  
  6. using namespace std;
  7.  
  8. #define n 100
  9. #define maxnom 40
  10.  
  11. char path[30];
  12. int i,riemp;
  13.  
  14. fstream f1;
  15.  
  16. typedef char stringa[maxnom];
  17.  
  18. struct anagrafe
  19. {
  20. stringa nome;
  21. stringa cognome;
  22. stringa cell;
  23.  
  24. }datipers;
  25.  
  26. typedef struct anagrafe elenco;
  27. elenco t[n];
  28.  
  29. void inserimento();
  30. void ricerca ();
  31. void visualizzazione();
  32.  
  33. int main()
  34. {
  35. int scelta;
  36.  
  37. cout<<"Di seguito sono riportate le operazioni effettuabili"<<endl;
  38.  
  39. do
  40. {
  41. cout<<"[1]inserimento"<<endl;
  42. cout<<"[2]ricerca"<<endl;
  43. cout<<"[3]visualizzazione"<<endl;
  44. cout<<"[4]esci"<<endl;
  45. cin>>scelta;
  46.  
  47.  
  48.  
  49. switch (scelta)
  50. {
  51. case 1:
  52. inserimento();
  53. break;
  54.  
  55. case 2:
  56. ricerca();
  57. break;
  58.  
  59. case 3:
  60. visualizzazione();
  61. break;
  62. }
  63.  
  64. }while(scelta !=4);
  65.  
  66.  
  67. system("pause");
  68.  
  69.  
  70. }
  71.  
  72.  
  73. void inserimento()
  74.  
  75. {
  76. cout<<"inserire il percorso file in cui si desidera salvare il contenuto dell'agenda"<<endl;
  77. cin>>path;
  78.  
  79. f1.open(path,ios::out);
  80.  
  81. if(!f1)
  82. {
  83. cout<<"Errore"<<endl;
  84. exit(-1);
  85. }
  86.  
  87. cout<<"inserire il numero di contatti(persone) dal salvare in agenda"<<endl;
  88. cin>>riemp;
  89.  
  90. for (i=0;i< riemp; i++)
  91. {
  92. cout<<endl;
  93. cout<<"inserire il nome: ";
  94. cin>>t[i].nome;
  95. f1<<t[i].nome<<endl<<endl;
  96. cout<<endl;
  97.  
  98.  
  99. cout<<endl;
  100. cout<<"inserire cognome: ";
  101. cin>>t[i].cognome;
  102. f1<<t[i].cognome<<endl<<endl;
  103. cout<<endl;
  104.  
  105.  
  106. cout<<endl;
  107. cout<<"inserire numero di cellulare: ";
  108. cin>>t[i].cell;
  109. f1<<t[i].cell<<endl<<endl;
  110. cout<<endl;
  111.  
  112. cout<<endl;
  113.  
  114. }
  115. cout<<endl;
  116. cout<<endl;
  117.  
  118. f1.close();
  119.  
  120.  
  121. }
  122.  
  123.  
  124. void ricerca()
  125. {
  126. f1.open(path,ios::in);
  127.  
  128. char ricerca [100];
  129.  
  130. cout<<"inserire il nome o il cognome della persona che si desidera cercare in ribrica"<<endl;
  131. cin>>ricerca;
  132.  
  133.  
  134.  
  135. for(int f = 0 ;f < i ; f++)
  136. {
  137. if(!strcmp(t[i].nome,ricerca) || !strcmp (t[i].cognome,ricerca))
  138. {
  139. cout<<"Nome: " <<t[i].nome<<endl;
  140. cout<<endl;
  141. cout<<"Cognome: " <<t[i].cognome<<endl;
  142. cout<<endl;
  143. cout<<"cell: " <<t[i].cell<<endl;
  144. cout<<endl;
  145.  
  146. return;
  147. }
  148. cout<<endl;
  149. }
  150.  
  151. cout<<"nessun risultato trovato"<<endl;
  152. cout<<endl;
  153.  
  154. f1.close();
  155. }
  156.  
  157.  
  158. void visualizzazione()
  159. {
  160.  
  161. cout<<"visualizzazione contenuto rubrica"<<endl;
  162. cout<<endl<<endl;
  163.  
  164. f1.open(path,ios::in);
  165.  
  166. for(int i=0;i< riemp; i++)
  167. {
  168. cout<<"Nome: " <<t[i].nome<<endl;
  169. cout<<endl;
  170. cout<<"Cognome: " <<t[i].cognome<<endl;
  171. cout<<endl;
  172. cout<<"cell: " <<t[i].cell<<endl;
  173. cout<<endl;
  174. }
  175. cout<<endl;
  176. cout<<endl;
  177. cout<<endl;
  178.  
  179. f1.close();
  180. }
Add Comment
Please, Sign In to add comment