Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* ******************************************
- *
- **/
- #include <bits/stdc++.h>
- using namespace std;
- const char VOCALI[]="AEIOU";
- const char CONSONANTI[]="BCDFGHJKLMNPQRSTVWXYZ";
- char codice[20];
- char genere;
- /* ------------------------------------------------- */
- bool isConsonante (char c){
- return (strchr(CONSONANTI, c) != NULL);
- }
- /* ------------------------------------------------- */
- char* estraiConsonanti(char* s,char* contenitore) {
- int pos=0;
- char c;
- for (int i=0; i<strlen(s); i++){
- c = toupper(s[i]);
- if (isConsonante(c)) {
- contenitore[pos++] = c;
- }
- }
- contenitore[pos] = '\0';
- return contenitore;
- }
- /* ------------------------------------------------- */
- bool isVocale(char c){
- return (strchr(VOCALI, c) != NULL);
- }
- /* ------------------------------------------------- */
- char* estraiVocali(char* s,char* contenitore) {
- int pos=0;
- char c;
- for (int i=0; i<strlen(s); i++){
- c = toupper(s[i]);
- if (isVocale(c)) {
- contenitore[pos++] = c;
- }
- }
- contenitore[pos] = '\0';
- return contenitore;
- }
- /* ------------------------------------------------- */
- char* codificaCognome(char* s,char* contenitore) {
- char appoggio[20];
- estraiConsonanti(s, contenitore);
- estraiVocali(s, appoggio);
- strcat(contenitore, appoggio);
- strcat(contenitore, "XXX");
- contenitore[3] = '\0';
- strcat(codice, contenitore);
- }
- char * codificaNome(char* s, char* contenitore) {
- char appoggio[20];
- estraiConsonanti(s, contenitore);
- estraiVocali(s, appoggio);
- if(strlen(contenitore) >= 4) {
- contenitore[1] = contenitore[2];
- contenitore[2] = contenitore[3];
- }
- strcat(contenitore, appoggio);
- strcat(contenitore, "XXX");
- contenitore[3] = '\0';
- strcat(codice, contenitore);
- }
- char* codificaData(char* date) {
- char anno[3];
- anno[0] = date[6];
- anno[1] = date[7];
- anno[2] = '\0';
- strcat(codice, anno);
- /* MESE */
- char mese[2];
- if(date[2] == 1) {
- mese[0] = date[2];
- mese[1] = date[3];
- mese[2] = '\0';
- } else{
- mese[0] = date[3];
- mese[1] = '\0';
- }
- int meseInt = atoi (mese);
- char MESI[] = "ABCDEHLMPRST";
- mese[0] = MESI[meseInt - 1];
- mese[1] = '\0';
- strcat(codice, mese);
- int giornoInt = 0;
- /* GIORNO */
- char giorno[2];
- giorno [0] = date[0];
- giorno [1] = date[1];
- giorno [2] = '\0';
- if(genere == 'M') {
- strcat(codice, giorno);
- } else if(genere == 'F') {
- giornoInt = atoi (giorno);
- giornoInt += 40;
- sprintf(giorno, "%d", giornoInt);
- strcat(codice, giorno);
- }
- /* A gennaio E maggio P settembre
- B febbraio H giugno R ottobre
- C marzo L luglio S novembre
- D aprile M agosto T dicembre
- */
- }
- /* ------------------------------------------------- */
- int main()
- {
- int codifica;
- char cognome[20];
- char nome[20];
- char str[20];
- char date[9];
- cout <<"Cognome: ";
- cin.getline(cognome, 19);
- codificaCognome(cognome, str);
- cout <<"Nome: ";
- cin.getline(nome, 19);
- codificaNome(nome, str);
- cout <<"Data (GGMMANNO): ";
- cin.getline(date, 9);
- cout << "Sesso (M/F): ";
- cin >> genere;
- codificaData(date);
- cout << codice;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement