49 lines
1.1 KiB
C++
49 lines
1.1 KiB
C++
/*
|
|
Nome: Mario
|
|
Cognome: Montanari
|
|
|
|
Generare una parola a caso (sicuramente pronunciabile), esempio: MUSETO.
|
|
Consonanti = "BCDFGLMNPRSTVZ".
|
|
Vocali = "AEIOU".
|
|
Ogni sillaba è consonante + vocale, esempio: BA.
|
|
Il numero di sillabe viene deciso da input o in modo randomico.
|
|
*/
|
|
|
|
#include <iostream>
|
|
#include <cstdlib>
|
|
#include <ctime>
|
|
|
|
#define MIN_SILLABE 2
|
|
#define MAX_SILLABE 5
|
|
|
|
using namespace std;
|
|
|
|
void creaParola(const char strVowel[], const char strConsonant[], int n);
|
|
|
|
int main(void) {
|
|
srand(time(NULL));
|
|
|
|
const char strVowel[] = "AEIOU";
|
|
const char strConsonant[] = "BCDFGLMNPRSTVZ";
|
|
|
|
int n = rand() % (MAX_SILLABE - MIN_SILLABE + 1) + MIN_SILLABE;
|
|
cout << "Numero di sillabe: " << n << endl;
|
|
|
|
creaParola(strVowel, strConsonant, n);
|
|
|
|
return 0;
|
|
}
|
|
|
|
void creaParola(const char strVowel[], const char strConsonant[], int n) {
|
|
int size = (n * 2) + 1;
|
|
char strParola[size];
|
|
int index = 0;
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
strParola[index++] = strConsonant[rand() % 14];
|
|
strParola[index++] = strVowel[rand() % 5];
|
|
}
|
|
|
|
strParola[index] = '\0';
|
|
cout << "Parola generata: " << strParola << endl;
|
|
} |