Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string.h>
  4. #define MAX 100
  5. using namespace std;
  6.  
  7. struct nomimaschili{
  8. char nomemaschio[MAX];
  9. };
  10.  
  11. struct nomifemminili{
  12. char nomefemmina[MAX];
  13. };
  14.  
  15. nomimaschili maschi [MAX];
  16. nomifemminili femmine [MAX];
  17.  
  18.  
  19. void apertura_file(fstream& file);
  20. int inserimento_nomi(fstream& file,int totalenomi,int& tot_m,int& tot_f);
  21. bool esiste_nelle_struct(nomimaschili records[],int size, char nome[]);
  22. bool esiste_nelle_struct(nomifemminili records[],int size, char nome[]);
  23.  
  24. int main()
  25. {
  26. int tot_nomi;
  27. int tot_maschi;
  28. int tot_femmine;
  29. fstream myfile;
  30. apertura_file(myfile);
  31. tot_nomi = inserimento_nomi(myfile,tot_nomi,tot_maschi,tot_femmine);
  32.  
  33.  
  34. }
  35.  
  36.  
  37. void apertura_file(fstream& file){
  38. char nomefile[MAX];
  39. cout<<"Inserisci nome del file: ";
  40. cin>>nomefile;
  41. file.open(nomefile,ios::in);
  42. if(!file){
  43. cout<<"Errore apertura file";
  44. exit(1);
  45. }
  46. }
  47.  
  48.  
  49. int inserimento_nomi(fstream& file,int totalenomi,int& tot_m,int& tot_f){
  50. int contatore_nomi;
  51. int contatore_m = 0;
  52. int contatore_f = 0;
  53. int i = 0;
  54. while(!file.eof()){
  55. char nome[MAX];
  56. int lunghezza;
  57. file>>nome;
  58. lunghezza = strlen(nome);
  59.  
  60. if(nome[lunghezza-1] == 'o' && esiste_nelle_struct(maschi,MAX,nome)){
  61. strcpy(maschi[i].nomemaschio,nome);
  62. contatore_m++;
  63. i++;
  64. }
  65. else if(nome[lunghezza-1] == 'a' && esiste_nelle_struct(femmine,MAX,nome)){
  66. strcpy(femmine[i].nomefemmina,nome);
  67. contatore_f++;
  68. i++;
  69. }
  70. }
  71. tot_m = contatore_m;
  72. tot_f = contatore_f;
  73. return contatore_nomi;
  74. }
  75.  
  76. bool esiste_nelle_struct(nomimaschili records[],int size, char nome[]){
  77.  
  78. for(int i = 0; i < size; i++)
  79. {
  80. if(records[i].nomemaschio == nome)
  81. return 1;
  82. }
  83.  
  84. return 0;
  85. }
  86.  
  87.  
  88. bool esiste_nelle_struct(nomifemminili records[],int size, char nome[]){
  89.  
  90. for(int i = 0; i < size; i++)
  91. {
  92. if(records[i].nomefemmina == nome)
  93. return 1;
  94. }
  95.  
  96. return 0;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement