diff --git a/1-ConsecutiveHeads/ConsecutiveHeads.pro b/1-ConsecutiveHeads/ConsecutiveHeads.pro index 85bdbce..35adfaf 100644 --- a/1-ConsecutiveHeads/ConsecutiveHeads.pro +++ b/1-ConsecutiveHeads/ConsecutiveHeads.pro @@ -110,7 +110,7 @@ win32 { QMAKE_LFLAGS += -Wl,--stack,536870912 LIBS += -lDbghelp LIBS += -lbfd - LIBS += -liberty + #LIBS += -liberty LIBS += -limagehlp } macx { diff --git a/1-ConsecutiveHeads/ConsecutiveHeads.pro.user.54c8766 b/1-ConsecutiveHeads/ConsecutiveHeads.pro.user.54c8766 new file mode 100644 index 0000000..dfab652 --- /dev/null +++ b/1-ConsecutiveHeads/ConsecutiveHeads.pro.user.54c8766 @@ -0,0 +1,257 @@ + + + + + + EnvironmentId + {54c87661-e3ed-4006-ade7-6bdf739d1ebd} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.4.1 MinGW 32bit + Desktop Qt 5.4.1 MinGW 32bit + qt.54.win32_mingw491_kit + 0 + 0 + 0 + + C:/Users/user/QT PROJECTS/cs-b-assignment1-master/cs-b-assignment1-master/build-ConsecutiveHeads-Desktop_Qt_5_4_1_MinGW_32bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + false + + + true + Сборка + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Сборка + + ProjectExplorer.BuildSteps.Build + + + + true + Сборка + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Очистка + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Отладка + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + C:/Users/user/QT PROJECTS/cs-b-assignment1-master/cs-b-assignment1-master/build-ConsecutiveHeads-Desktop_Qt_5_4_1_MinGW_32bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + false + + + true + Сборка + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Сборка + + ProjectExplorer.BuildSteps.Build + + + + true + Сборка + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Очистка + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Выпуск + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 2 + + + 0 + Установка + + ProjectExplorer.BuildSteps.Deploy + + 1 + Локальная установка + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + ConsecutiveHeads + ConsecutiveHeads2 + Qt4ProjectManager.Qt4RunConfiguration:C:/QT PROJECTS/cs-b-assignment1-master/cs-b-assignment1-master/1-ConsecutiveHeads/ConsecutiveHeads.pro + + ConsecutiveHeads.pro + false + false + + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 18 + + + Version + 18 + + diff --git a/1-ConsecutiveHeads/src/ConsecutiveHeads.cpp b/1-ConsecutiveHeads/src/ConsecutiveHeads.cpp index 4b7f6b3..4d23d8e 100644 --- a/1-ConsecutiveHeads/src/ConsecutiveHeads.cpp +++ b/1-ConsecutiveHeads/src/ConsecutiveHeads.cpp @@ -2,9 +2,66 @@ #include #include "console.h" #include "random.h" +#include using namespace std; +/* Sets console output */ +void consoleSettings(); +/* Lunch proces program */ +void consequtiveHeads(); +/* Main process loop */ +void dropCoin(int heads, int flips); +/* Sets chances parametr */ +const double chance = 0.5; +/* Program window title */ +const string programTitle = "Consequtive heads"; +/* Disable console dupplication */ +const bool consoleEcho = false; + int main() { - // TODO: fill in the code + /*Adjust console window features*/ + consoleSettings(); + /* Programms starts and coins game begins + * "heads" getting is monitored, and at 3-d consequtive head programm drops + * message and stops */ + consequtiveHeads(); + return 0; } +/* Lunch game and main counters */ +void consequtiveHeads(){ + int flipsCnt = 0; + int headsCnt = 0; + /* Coin is droped until game isn't finished */ + dropCoin(headsCnt, flipsCnt); +} + +/* Recursion loop + * After 3 consequtive heads print end message */ +void dropCoin (int heads, int flips){ + bool head = false; + + if(heads > 2){ + /* End game message */ + cout << "It took " << flips << " flips to get 3 consecutive heads."; + }else{ + /* Coin random result */ + head = randomChance(chance); + flips++; + + if(head){ + cout << "heads" << endl; + heads++; + }else{ + cout << "tails" << endl; + heads = 0; + } + /* Recursion loop */ + dropCoin(heads, flips); + } +} + +void consoleSettings(){ + setConsoleWindowTitle(programTitle); + setConsoleEcho(consoleEcho); +} diff --git a/2-Obenglobish/Obenglobish.pro b/2-Obenglobish/Obenglobish.pro index 85bdbce..35adfaf 100644 --- a/2-Obenglobish/Obenglobish.pro +++ b/2-Obenglobish/Obenglobish.pro @@ -110,7 +110,7 @@ win32 { QMAKE_LFLAGS += -Wl,--stack,536870912 LIBS += -lDbghelp LIBS += -lbfd - LIBS += -liberty + #LIBS += -liberty LIBS += -limagehlp } macx { diff --git a/2-Obenglobish/Obenglobish.pro.user.54c8766 b/2-Obenglobish/Obenglobish.pro.user.54c8766 new file mode 100644 index 0000000..0907c01 --- /dev/null +++ b/2-Obenglobish/Obenglobish.pro.user.54c8766 @@ -0,0 +1,257 @@ + + + + + + EnvironmentId + {54c87661-e3ed-4006-ade7-6bdf739d1ebd} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.4.1 MinGW 32bit + Desktop Qt 5.4.1 MinGW 32bit + qt.54.win32_mingw491_kit + 0 + 0 + 0 + + C:/QT PROJECTS/cs-b-assignment1-master/cs-b-assignment1-master/build-Obenglobish-Desktop_Qt_5_4_1_MinGW_32bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + false + + + true + Сборка + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Сборка + + ProjectExplorer.BuildSteps.Build + + + + true + Сборка + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Очистка + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Отладка + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + C:/QT PROJECTS/cs-b-assignment1-master/cs-b-assignment1-master/build-Obenglobish-Desktop_Qt_5_4_1_MinGW_32bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + false + + + true + Сборка + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Сборка + + ProjectExplorer.BuildSteps.Build + + + + true + Сборка + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Очистка + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Выпуск + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 2 + + + 0 + Установка + + ProjectExplorer.BuildSteps.Deploy + + 1 + Локальная установка + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + Obenglobish + + Qt4ProjectManager.Qt4RunConfiguration:C:/QT PROJECTS/cs-b-assignment1-master/cs-b-assignment1-master/2-Obenglobish/Obenglobish.pro + + Obenglobish.pro + false + false + + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 18 + + + Version + 18 + + diff --git a/2-Obenglobish/src/Obenglobish.cpp b/2-Obenglobish/src/Obenglobish.cpp index f9e31cb..438d40d 100644 --- a/2-Obenglobish/src/Obenglobish.cpp +++ b/2-Obenglobish/src/Obenglobish.cpp @@ -5,7 +5,92 @@ #include "strlib.h" using namespace std; +/* Return obenglobish word */ +string obenglobish(string word); +/* Main obenglobish process */ +string wordProcess(int index, string word, string result, int vowelsSum); +/* Check if this char is vowel */ +bool isVowel (char letter); +/* Sets console output */ +void consoleSettings(); +/* Program window title */ +const string programTitle = "Obenglobish"; +/* Disable console dupplication */ +const bool consoleEcho = false; + int main() { - // TODO: fill in the code + consoleSettings(); + + /* Program asks user to enter words infinitely */ + while(true){ + string word = getLine("Enter a word: "); + /* Empty string input isn't processing */ + if(word == ""){ + break; + } + /* Obenglobish translation */ + string translation = obenglobish(word); + cout << word << " -> " << translation << endl; + } + return 0; } + +/*Obenglobish translator: + *syllable 'ob' add before all vowels - a,e,i,o,u,y - only if not: + * - before this vowel is another vowel + * - this vowel is e at end of word */ +string obenglobish(string word){ + string result = ""; + int startAnalizeIndex = 0; + int vowelsSum = 0; + result = wordProcess(startAnalizeIndex, word, result, vowelsSum); + + return result; +} + +/* Recursive loop word process */ +string wordProcess(int index, string word, string result, int vowelsSum){ + bool lastLetterIndex = (index == (word.length() - 1)); + bool noVowelBefore = !isVowel(word[index-1]); + bool endECase = ((word[index] == 'e') && (lastLetterIndex)); + + if(index > (word.length() - 1)){ + /* If function analized all letters it returns result */ + return result; + }else{ + if(isVowel(word[index])){ + /* If current char is vowel */ + if(noVowelBefore){ + /* And no vowels before */ + if(!endECase){ + /* And this isn't "e" at the end */ + result += "OB"; + vowelsSum++; + }else{ + /* End "e" case - for "be" word example */ + if(vowelsSum == 0){ + result += "OB"; + } + } + } + } + result += word[index]; + index++; + /* Recursive loop */ + return wordProcess(index, word, result, vowelsSum); + } +} + +/* Checks if current char is vowel */ +bool isVowel (char letter){ + letter = tolower(letter); + string alphabetVowels = "aeiouy"; + bool isVowel = (alphabetVowels.find(letter) != std::string::npos); + return isVowel; +} + +void consoleSettings(){ + setConsoleWindowTitle(programTitle); + setConsoleEcho(consoleEcho); +} diff --git a/3-NumericConversion/NumericConversion.pro b/3-NumericConversion/NumericConversion.pro index 85bdbce..35adfaf 100644 --- a/3-NumericConversion/NumericConversion.pro +++ b/3-NumericConversion/NumericConversion.pro @@ -110,7 +110,7 @@ win32 { QMAKE_LFLAGS += -Wl,--stack,536870912 LIBS += -lDbghelp LIBS += -lbfd - LIBS += -liberty + #LIBS += -liberty LIBS += -limagehlp } macx { diff --git a/3-NumericConversion/src/NumericConversion.cpp b/3-NumericConversion/src/NumericConversion.cpp index d66d654..17671d8 100644 --- a/3-NumericConversion/src/NumericConversion.cpp +++ b/3-NumericConversion/src/NumericConversion.cpp @@ -1,14 +1,114 @@ #include #include #include "console.h" + using namespace std; -// Function prototypes +/* Task functions prototypes + * */ string intToString(int n); int stringToInt(string str); - +// Service functions prototypes +string recursiveIntToString(int n, string result); +int recursiveStrToInt(int index, string str, int result); +int rise10ToPower(int power); +// Console settings +void consoleSettings(); +const double chance = 0.5; +const string programTitle = "NumericConversion"; +const bool consoleEcho = false; int main() { - // TODO: fill in the code + consoleSettings(); + + cout << "Process STRING TO INT" << endl; + cout << stringToInt("2505") << endl; + cout << stringToInt("2") << endl; + cout << stringToInt("-252") << endl; + cout << stringToInt("0") << endl; + + cout << endl; + + cout << "Process INT TO STRING" << endl; + cout << intToString(-3956) << endl; + cout << intToString(-0) << endl; + cout << intToString(826) << endl; + return 0; } + +/* Converts integer to string */ +string intToString(int n){ + string result = ""; + if(n < 0){ + /* Solve negative values */ + return string("-") + recursiveIntToString(-1 * n, result); + }else{ + /* Main recursive loop */ + return recursiveIntToString(n, result); + } +} + +/* Recursive loop process */ +string recursiveIntToString(int intValue, string result){ + /* Divide input value in two parts - n/10 and n%10 */ + int nextValue = intValue/10; + if(nextValue == 0){ + /* Returns string value of integer */ + return ((char)(intValue + '0') + result); + }else{ + /* finds remain of n%10 process and concantenate it to result */ + int remain = intValue % 10; + char remainChar = (char)(remain + '0'); + result = remainChar + result; + return recursiveIntToString(nextValue, result); + } +} + +/* Converts string to integer + * Only if str is not object of integer (no comas or wrong input chars) */ +int stringToInt(string str){ + int startIndex = (str.length() - 1); + int result = 0; + /* Main conversion loop */ + return recursiveStrToInt(startIndex, str, result); +} + +/* Main conversion process */ +int recursiveStrToInt(int index, string str, int result){ + if(index < 0){ + /* If function processed all chars in str */ + return result; + } + else{ + /* If str stores negative value */ + if((index == 0) && (str[index] == '-')){ + return -1* result; + }else{ + /* Converts each char into integer */ + int digit = str[index] - '0'; + /* Defines decamical capacity of such integer value */ + int power = (str.length() - 1) - index; + /* Sums result with current integer decamical value */ + result += digit * rise10ToPower(power); + /* Prepares to get next char in string */ + index--; + /* Recursive loop */ + return recursiveStrToInt(index, str, result); + } + } +} + +/* Rise 10 to power */ +int rise10ToPower(int power){ + if(power <= 0){ + return 1; + }else{ + return 10 * rise10ToPower(power - 1); + } +} + +void consoleSettings(){ + setConsoleWindowTitle(programTitle); + setConsoleEcho(consoleEcho); +} diff --git a/4-Flesch-Kincaid/FleschKincaid.pro b/4-Flesch-Kincaid/FleschKincaid.pro index 85bdbce..35adfaf 100644 --- a/4-Flesch-Kincaid/FleschKincaid.pro +++ b/4-Flesch-Kincaid/FleschKincaid.pro @@ -110,7 +110,7 @@ win32 { QMAKE_LFLAGS += -Wl,--stack,536870912 LIBS += -lDbghelp LIBS += -lbfd - LIBS += -liberty + #LIBS += -liberty LIBS += -limagehlp } macx { diff --git a/4-Flesch-Kincaid/FleschKincaid.pro.user.7e1b340 b/4-Flesch-Kincaid/FleschKincaid.pro.user.7e1b340 new file mode 100644 index 0000000..9277c84 --- /dev/null +++ b/4-Flesch-Kincaid/FleschKincaid.pro.user.7e1b340 @@ -0,0 +1,257 @@ + + + + + + EnvironmentId + {7e1b340a-b4f8-4d4b-9a18-be64bacf8d5c} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.4.1 MinGW 32bit + Desktop Qt 5.4.1 MinGW 32bit + qt.54.win32_mingw491_kit + 0 + 0 + 0 + + C:/QT PROJECTS/cs-b-assignment1-master/build-FleschKincaid-Desktop_Qt_5_4_1_MinGW_32bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + false + + + true + Сборка + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Сборка + + ProjectExplorer.BuildSteps.Build + + + + true + Сборка + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Очистка + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Отладка + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + C:/QT PROJECTS/cs-b-assignment1-master/build-FleschKincaid-Desktop_Qt_5_4_1_MinGW_32bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + false + + + true + Сборка + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Сборка + + ProjectExplorer.BuildSteps.Build + + + + true + Сборка + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Очистка + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Выпуск + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 2 + + + 0 + Установка + + ProjectExplorer.BuildSteps.Deploy + + 1 + Локальная установка + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + FleschKincaid + + Qt4ProjectManager.Qt4RunConfiguration:C:/QT PROJECTS/cs-b-assignment1-master/4-Flesch-Kincaid/FleschKincaid.pro + + FleschKincaid.pro + false + false + + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 18 + + + Version + 18 + + diff --git a/4-Flesch-Kincaid/res/Test file.txt b/4-Flesch-Kincaid/res/Test file.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/4-Flesch-Kincaid/res/Test file.txt @@ -0,0 +1 @@ + diff --git a/4-Flesch-Kincaid/res/Test0.txt b/4-Flesch-Kincaid/res/Test0.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/4-Flesch-Kincaid/res/Test0.txt @@ -0,0 +1 @@ + diff --git a/4-Flesch-Kincaid/res/TestFile.txt b/4-Flesch-Kincaid/res/TestFile.txt new file mode 100644 index 0000000..c2d8ff0 --- /dev/null +++ b/4-Flesch-Kincaid/res/TestFile.txt @@ -0,0 +1,8 @@ +CHAPTER I + +In the low-ceili'nged cant'een, deep.... F-1 "Best" underground, the 1984 350 +lunch queue jerked slowly forward. The + +There was no possibility of taking a walk that day. We had been +wandering, indeed, in the leafless shrubbery an hour in the morning; but +since d diff --git a/4-Flesch-Kincaid/src/FleschKincaid.cpp b/4-Flesch-Kincaid/src/FleschKincaid.cpp index 0b16ad2..b5fd03b 100644 --- a/4-Flesch-Kincaid/src/FleschKincaid.cpp +++ b/4-Flesch-Kincaid/src/FleschKincaid.cpp @@ -1,8 +1,244 @@ #include +#include +#include "simpio.h" +#include "filelib.h" #include "console.h" +#include "tokenscanner.h" + + using namespace std; +/* Functions prototypes */ +string fileInput(string line); +void readFileProcess(istream & infile, string fileName); +void scanCPlusPlusTokens(TokenScanner & scanner); +bool isEndSentenceCharacter(string word); +void simpleTokenProcess(string word, int & syllablesCounter, + int & wordsCounter, + int & sentencesCounter); +int syllablesCountProcess(int index, string word, int result); +bool isVowel (char letter); +const bool showDebug = false; +/* FleschKincaid equation constatnts */ +const double C0 = -15.59; +const double C1 = 0.39; +const double C2 = 11.8; +/* Console settings */ +void consoleSettings(); +const double chance = 0.5; +const string programTitle = "FleschKincaid"; +const bool consoleEcho = false; + int main() { - // TODO: fill in the code + /* Adjust concole settings for programm */ + consoleSettings(); + /* User enters name of file from project directory */ + string fileName = fileInput("Enter file name: "); + + /* Prepare main input stream object */ + ifstream infile; + /* Lunch stream of file reading */ + infile.open(fileName.c_str()); + /* Main program process */ + readFileProcess(infile, fileName); + /* If whole file is read program closes stream */ + infile.close(); + return 0; } + +/* Makes file reading and shows results of process */ +void readFileProcess(istream & infile, string fileName){ + if (infile.fail()){ + /* Informs about problems at start of file reading */ + cout << "FAIL" << endl; + }else{ + /* Main process + * Scans input stream by TokenScanner object */ + TokenScanner scanner; + scanner.setInput(infile); + /* Settings of scanner */ + scanCPlusPlusTokens(scanner); + /* Main results counters */ + int syllablesCnt = 0; + int wordsCnt = 0; + int sentencesCnt = 0; + /* Main process loop */ + while (scanner.hasMoreTokens()) { + /* Take next token from scanner */ + string token = scanner.nextToken(); + /* Main sorting and counters incrementing */ + simpleTokenProcess(token, syllablesCnt, wordsCnt, sentencesCnt); + } + /* End of file detection */ + if(infile.fail()){ + if(infile.eof()){ + /* Case of empty file have return some results */ + if(sentencesCnt == 0){ + sentencesCnt++; + } + if(wordsCnt == 0){ + wordsCnt++; + } + } + } + /* Process results printing to user */ + cout << "IN FILE: " << fileName << endl; + cout << "WORDS = " << wordsCnt << endl; + cout << "SYLLABLES = " << syllablesCnt << endl; + cout << "SENTENCES = " << sentencesCnt << endl; + /* Result equation */ + double result = 0; + result += C0; + result += (C1* wordsCnt/ sentencesCnt); + result += (C2* syllablesCnt / wordsCnt); + /* Result printing */ + cout << "GRADE LEVEL = " << result; + } +} + +/* Shows this word syllables + * @word is recognized as valid word yet */ +int syllablesCountProcess(int index, string word, int result){ + bool lastLetterIndex = (index == (word.length() - 1)); + bool noVowelsBefore = !isVowel(word[index-1]); + bool endECase = ((word[index] == 'e') && (lastLetterIndex)); + + if(index > (word.length() - 1)){ + return result; + }else{ + if(isVowel(word[index])){ + if(noVowelsBefore){ + if(!endECase){ + result++; + }else{ + /* For cases like "me", "be" words - approve 1 syllable */ + if(result == 0){ + result++; + } + } + } + }else{ + /* For cases like "txt", "str" words - approve 1 syllable */ + if(lastLetterIndex && (result == 0)){ + result++; + } + } + /* Turn function to next letter to analize */ + index++; + /* Recursive loop of function */ + return syllablesCountProcess(index, word, result); + } +} + +/* Defines if current char is vowel */ +bool isVowel (char letter){ + letter = tolower(letter); + string alphabetVowels = "aeiouy"; + bool isVowel = (alphabetVowels.find(letter) != std::string::npos); + return isVowel; +} + +/* Sort tokens and count program parameters - + * syllables, words, sentences. + * Supose that every token which starts from letter is word + * Supose that every symbol like "." "!" or "?" is end of sentencse marker */ +void simpleTokenProcess(string token, int & syllablesCounter, + int & wordsCounter, + int & sentencesCounter){ + /* Tokens sorting */ + if(isalpha(token[0])){ + /* Words detection */ + int syllables = syllablesCountProcess(0, token, 0); + syllablesCounter += syllables; + wordsCounter++; + if(showDebug){ + cout << wordsCounter << " " << token << " = " << syllables << endl; + } + } + else if ((token.length() > 1) && (token[0] == '\'') && (isalpha(token[1]))){ + /* Case of quotes "'word" tokens counts as word */ + if(showDebug){ + cout << token << endl; + } + int syllables = syllablesCountProcess(1, token, 0); + syllablesCounter += syllables; + wordsCounter++; + } + else if ((token.length() > 2) && (token[0] == '-') && (isalpha(token[2]))){ + /* Case of "--ab" tokens counts as word */ + if(showDebug){ + cout << token << endl; + } + int syllables = syllablesCountProcess(1, token, 0); + syllablesCounter += syllables; + wordsCounter++; + } + else if (isEndSentenceCharacter(token)){ + /* Sentences detection */ + sentencesCounter++; + if(showDebug){ + cout << token << " ---------- end symbol " << sentencesCounter << endl; + } + }else{ + if(!(ispunct(token[0]))){ + if(showDebug){ + cout << token << " --------------------------- SOMETHING " << endl; + } + if(isdigit(token[0])){ + wordsCounter++; + } + } + } +} + +/* Recognize if this token is end of sentence symbol */ +bool isEndSentenceCharacter(string token){ + if(token == "..."){ + return true; + }else if(token == "."){ + return true; + }else if(token == "!"){ + return true; + }else if(token == "?"){ + return true; + }else{ + return false; + } +} + +/* Sets token scanner features */ +void scanCPlusPlusTokens(TokenScanner & scanner) { + scanner.ignoreWhitespace(); + /* To recognize words like "isn't" */ + scanner.addWordCharacters("'"); + /* Don't recognize words like "two-way" */ + //scanner.addWordCharacters("-"); + /* To recognize symbol "..." like end of sentence */ + scanner.addOperator("..."); + + /* Don't return strings with quotations */ + //scanner.scanStrings(); + /* Don't return numbers */ + //scanner.scanNumbers(); +} + +/* User input function + * Defines if this file exist in project directory */ +string fileInput(string enterText){ + while(true){ + string result = getLine(enterText); + if(fileExists(result)){ + return result; + break; + }else{ + cout << "Unfortunately your input is failed" << endl; + } + } +} + +/* Make console output window more convenient */ +void consoleSettings(){ + setConsoleWindowTitle(programTitle); + setConsoleEcho(consoleEcho); +}