82 lines
1.4 KiB
C++
82 lines
1.4 KiB
C++
/*
|
|
Nome: Mario
|
|
Cognome: Montanari
|
|
|
|
isMonovocalic
|
|
*/
|
|
|
|
#include <iostream>
|
|
#include <cctype>
|
|
|
|
#define SIZE 30+1
|
|
|
|
using namespace std;
|
|
|
|
/*
|
|
int isConsonant(char c);
|
|
*/
|
|
|
|
int isVowel(char c);
|
|
void isMonovocalic(const char *str);
|
|
|
|
int main(void) {
|
|
char str[SIZE];
|
|
|
|
cout << "Inserisci una parola: ";
|
|
cin >> str;
|
|
|
|
for (int i = 0; str[i] != '\0'; i++) {
|
|
str[i] = toupper(str[i]);
|
|
}
|
|
|
|
isMonovocalic(str);
|
|
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
int isConsonant(char c) {
|
|
return ((c >= 'A' && c <= 'Z') || (c > 'a' && c <= 'z'))
|
|
&& !isVowel(c);
|
|
}
|
|
*/
|
|
|
|
int isVowel(char c) {
|
|
return c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U'
|
|
|| c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
|
|
}
|
|
|
|
void isMonovocalic(const char *str) {
|
|
bool isA = false;
|
|
bool isE = false;
|
|
bool isI = false;
|
|
bool isO = false;
|
|
bool isU = false;
|
|
|
|
for (int i = 0; str[i] != '\0'; i++) {
|
|
if (str[i] == 'A') {
|
|
isA = true;
|
|
} else if (str[i] == 'E') {
|
|
isE = true;
|
|
} else if (str[i] == 'I') {
|
|
isI = true;
|
|
} else if (str[i] == 'O') {
|
|
isO = true;
|
|
} else if (str[i] == 'U') {
|
|
isU = true;
|
|
}
|
|
}
|
|
|
|
int vowelCount = 0;
|
|
if (isA) vowelCount++;
|
|
if (isE) vowelCount++;
|
|
if (isI) vowelCount++;
|
|
if (isO) vowelCount++;
|
|
if (isU) vowelCount++;
|
|
|
|
if (vowelCount == 1) {
|
|
cout << "Parola monovocalica" << endl;
|
|
} else {
|
|
cout << "Parola non monovocalica" << endl;
|
|
}
|
|
} |