Advertisement
Guest User

Untitled

a guest
Nov 13th, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. /* ******************************************
  2. *
  3. **/
  4. #include <bits/stdc++.h>
  5.  
  6. using namespace std;
  7. const char VOCALI[]="AEIOU";
  8. const char CONSONANTI[]="BCDFGHJKLMNPQRSTVWXYZ";
  9.  
  10. char codice[20];
  11. char genere;
  12.  
  13. /* ------------------------------------------------- */
  14. bool isConsonante (char c){
  15. return (strchr(CONSONANTI, c) != NULL);
  16. }
  17. /* ------------------------------------------------- */
  18. char* estraiConsonanti(char* s,char* contenitore) {
  19. int pos=0;
  20. char c;
  21. for (int i=0; i<strlen(s); i++){
  22. c = toupper(s[i]);
  23. if (isConsonante(c)) {
  24. contenitore[pos++] = c;
  25. }
  26. }
  27. contenitore[pos] = '\0';
  28. return contenitore;
  29. }
  30. /* ------------------------------------------------- */
  31. bool isVocale(char c){
  32. return (strchr(VOCALI, c) != NULL);
  33. }
  34. /* ------------------------------------------------- */
  35. char* estraiVocali(char* s,char* contenitore) {
  36. int pos=0;
  37. char c;
  38. for (int i=0; i<strlen(s); i++){
  39. c = toupper(s[i]);
  40. if (isVocale(c)) {
  41. contenitore[pos++] = c;
  42. }
  43. }
  44. contenitore[pos] = '\0';
  45. return contenitore;
  46. }
  47. /* ------------------------------------------------- */
  48. char* codificaCognome(char* s,char* contenitore) {
  49. char appoggio[20];
  50. estraiConsonanti(s, contenitore);
  51. estraiVocali(s, appoggio);
  52. strcat(contenitore, appoggio);
  53. strcat(contenitore, "XXX");
  54. contenitore[3] = '\0';
  55. strcat(codice, contenitore);
  56. }
  57.  
  58. char * codificaNome(char* s, char* contenitore) {
  59.  
  60. char appoggio[20];
  61. estraiConsonanti(s, contenitore);
  62. estraiVocali(s, appoggio);
  63.  
  64. if(strlen(contenitore) >= 4) {
  65. contenitore[1] = contenitore[2];
  66. contenitore[2] = contenitore[3];
  67. }
  68.  
  69. strcat(contenitore, appoggio);
  70. strcat(contenitore, "XXX");
  71. contenitore[3] = '\0';
  72. strcat(codice, contenitore);
  73.  
  74.  
  75. }
  76.  
  77.  
  78.  
  79. char* codificaData(char* date) {
  80.  
  81.  
  82.  
  83.  
  84.  
  85. char anno[3];
  86. anno[0] = date[6];
  87. anno[1] = date[7];
  88. anno[2] = '\0';
  89. strcat(codice, anno);
  90.  
  91.  
  92.  
  93. /* MESE */
  94.  
  95. char mese[2];
  96.  
  97. if(date[2] == 1) {
  98. mese[0] = date[2];
  99. mese[1] = date[3];
  100. mese[2] = '\0';
  101.  
  102. } else{
  103.  
  104. mese[0] = date[3];
  105. mese[1] = '\0';
  106. }
  107.  
  108. int meseInt = atoi (mese);
  109.  
  110. char MESI[] = "ABCDEHLMPRST";
  111.  
  112. mese[0] = MESI[meseInt - 1];
  113. mese[1] = '\0';
  114. strcat(codice, mese);
  115.  
  116. int giornoInt = 0;
  117. /* GIORNO */
  118.  
  119. char giorno[2];
  120. giorno [0] = date[0];
  121. giorno [1] = date[1];
  122. giorno [2] = '\0';
  123.  
  124. if(genere == 'M') {
  125. strcat(codice, giorno);
  126. } else if(genere == 'F') {
  127.  
  128. giornoInt = atoi (giorno);
  129. giornoInt += 40;
  130. sprintf(giorno, "%d", giornoInt);
  131. strcat(codice, giorno);
  132.  
  133. }
  134.  
  135. /* A gennaio E maggio P settembre
  136. B febbraio H giugno R ottobre
  137. C marzo L luglio S novembre
  138. D aprile M agosto T dicembre
  139. */
  140.  
  141. }
  142. /* ------------------------------------------------- */
  143. int main()
  144. {
  145. int codifica;
  146. char cognome[20];
  147. char nome[20];
  148. char str[20];
  149.  
  150. char date[9];
  151.  
  152.  
  153. cout <<"Cognome: ";
  154. cin.getline(cognome, 19);
  155. codificaCognome(cognome, str);
  156. cout <<"Nome: ";
  157. cin.getline(nome, 19);
  158. codificaNome(nome, str);
  159.  
  160.  
  161.  
  162.  
  163.  
  164. cout <<"Data (GGMMANNO): ";
  165. cin.getline(date, 9);
  166.  
  167. cout << "Sesso (M/F): ";
  168. cin >> genere;
  169. codificaData(date);
  170.  
  171.  
  172. cout << codice;
  173.  
  174. return 0;
  175. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement