School-Coding-Cpp/sfusi/pigLatin.cpp

62 lines
991 B
C++

/*
Nome: Mario
Cognome: Montanari
pigLatin
*/
#include <iostream>
#include <cstring>
#define SIZE 100+1
using namespace std;
bool isVowel(char chr);
void pigLatin(char *mssg);
int main(void) {
char mssg[SIZE];
cout << "Inserisci una frase: ";
cin.getline(mssg, SIZE);
pigLatin(mssg);
return 0;
}
bool isVowel(char chr) {
return (
chr == 'A' || chr == 'a' ||
chr == 'E' || chr == 'e' ||
chr == 'I' || chr == 'i' ||
chr == 'O' || chr == 'o' ||
chr == 'U' || chr == 'u'
);
}
void pigLatin(char *mssg) {
char *token = strtok(mssg, " ");
while (token != nullptr) {
int len = strlen(token);
if (isVowel(token[0])) {
cout << token << "way ";
} else {
char first = token[0];
for (int i = 0; i < len - 1; i++) {
token[i] = token[i + 1];
}
token[len - 1] = first;
token[len] = '\0';
cout << token << "ay ";
}
token = strtok(nullptr, " ");
}
cout << endl;
}