1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
#include <iostream>
#include <string>
using namespace std;
int main()
{
setlocale(LC_ALL, "Turkish");
string str;
cout << "Cümle girin:";
getline(cin, str);
char sesliHarfler[] = { 'a','e','ı','i','o','ö','u','ü' };
int sesliSayisi[] = { 0,0,0,0,0,0,0,0 };
int toplam = 0;
// Counting number of each novel
// If "tolower" functions works, you can use in loop
for (int i = 0; i < str.length(); i++)
{
if (str[i] == 'A' || str[i] == 'a') sesliSayisi[0]++;
else if (str[i] == 'E' || str[i] == 'e') sesliSayisi[1]++;
else if (str[i] == 'I' || str[i] == char(141)) sesliSayisi[2]++; // char(141) = 'ı'
else if (str[i] == char(152) || str[i] == 'i') sesliSayisi[3]++; // char(152) = 'İ'
else if (str[i] == 'O' || str[i] == 'o') sesliSayisi[4]++;
else if (str[i] == char(153) || str[i] == char(148)) sesliSayisi[5]++; // char(153) = 'Ö' and char(148) = 'ö'
else if (str[i] == 'U' || str[i] == 'u') sesliSayisi[6]++;
else if (str[i] == char(129) || str[i] == char(154)) sesliSayisi[7]++; // char(129) = 'Ü' and char(154) = 'ü'
}
// Printing number of each vowel
for (int i = 0; i < 8; i++)
{
cout << sesliHarfler[i] << " = " << sesliSayisi[i] << endl;
}
// Counting all vowels
for (int i = 0; i < 8; i++)
{
toplam += sesliSayisi[i];
}
cout << "Toplam " << toplam << " tane ünlü var" << endl;
system("pause");
return 0;
}
| |