50 lines
831 B
C++
50 lines
831 B
C++
/*
|
|
Nome: Mario
|
|
Cognome: Montanari
|
|
Classe: 3AIN
|
|
Data: 07/03/2025
|
|
|
|
es1E: Scrivere una funzione che, ricevuta una
|
|
stringa, ne restituisca il numero di vocali.
|
|
Prototipo richiesto:
|
|
unsigned vowelscount(const char *str);
|
|
Esempio:
|
|
"25dic2018" ? 1
|
|
*/
|
|
|
|
#include <iostream>
|
|
|
|
#define SIZE 100+1
|
|
|
|
using namespace std;
|
|
|
|
int isVowel(char chr);
|
|
unsigned vowelscount(const char *str);
|
|
|
|
int main(void) {
|
|
char str[SIZE];
|
|
|
|
cin.getline(str, SIZE);
|
|
|
|
cout << vowelscount(str);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int isVowel(char chr) {
|
|
chr = toupper(chr);
|
|
|
|
return (chr == 'A' || chr == 'E' || chr == 'I' || chr == 'O' || chr == 'U');
|
|
}
|
|
|
|
unsigned vowelscount(const char *str) {
|
|
int contaVowel = 0;
|
|
|
|
for (int i = 0; str[i] != '\0'; i++) {
|
|
if (isVowel(str[i])) {
|
|
contaVowel++;
|
|
}
|
|
}
|
|
|
|
return contaVowel;
|
|
} |