From 54dfb6bad45e578eefb0f187001e92c002286ab3 Mon Sep 17 00:00:00 2001 From: vhrebenko Date: Sat, 22 Aug 2015 02:09:39 +0300 Subject: [PATCH 1/5] [assignment1.1 done] --- 1-ConsecutiveHeads/ConsecutiveHeads.pro | 2 +- 1-ConsecutiveHeads/src/ConsecutiveHeads.cpp | 39 +++++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/1-ConsecutiveHeads/ConsecutiveHeads.pro b/1-ConsecutiveHeads/ConsecutiveHeads.pro index 85bdbce..4570e8d 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/src/ConsecutiveHeads.cpp b/1-ConsecutiveHeads/src/ConsecutiveHeads.cpp index 4b7f6b3..883dbe2 100644 --- a/1-ConsecutiveHeads/src/ConsecutiveHeads.cpp +++ b/1-ConsecutiveHeads/src/ConsecutiveHeads.cpp @@ -4,7 +4,42 @@ #include "random.h" using namespace std; +//initialization function prototype +int coinToss(int &numberOfMatches,int &count); + + int main() { - // TODO: fill in the code - return 0; +//Initialization of variables: the number of matches +//and a variable number of attempts + int numberOfMatches = 0; + int count = 0; + coinToss(numberOfMatches,count); + cout<<"It took "< Date: Sun, 23 Aug 2015 00:49:05 +0300 Subject: [PATCH 2/5] Assignment1.2 done --- 2-Obenglobish/Obenglobish.pro | 2 +- 2-Obenglobish/src/Obenglobish.cpp | 75 ++++++++++++++++++- 2-Obenglobish/src/Obenglobish.cpp.autosave | 83 ++++++++++++++++++++++ 3 files changed, 158 insertions(+), 2 deletions(-) create mode 100644 2-Obenglobish/src/Obenglobish.cpp.autosave diff --git a/2-Obenglobish/Obenglobish.pro b/2-Obenglobish/Obenglobish.pro index 85bdbce..4570e8d 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/src/Obenglobish.cpp b/2-Obenglobish/src/Obenglobish.cpp index f9e31cb..ae12c6d 100644 --- a/2-Obenglobish/src/Obenglobish.cpp +++ b/2-Obenglobish/src/Obenglobish.cpp @@ -5,7 +5,80 @@ #include "strlib.h" using namespace std; +bool isVowel(char letter); +string obenglobish(string word); + int main() { - // TODO: fill in the code + while(true){ + string word = getLine("Enter a word: "); + if(word == "")break; + string translation = obenglobish(word); + cout<< word<<" -> "<0){ + if(word[0]=='e'&& word.length()==1){ + str +=word[0]; + } + else if(isVowel(word[0])&&isVowel(word[1])){ + str = str+string("ob")+word[0] + word[1] + obenglobish(word.substr(2,word.length()-2)); + } + else if(isVowel(word[0])&&!isVowel(word[1])){ + str = str+string("ob")+ word[0] + obenglobish(word.substr(1,word.length()-1)); + } + + else if(!isVowel(word[0])&& word.length() != 1){ + str +=word[0] + obenglobish(word.substr(1,word.length()-1)); + } + else{ + str +=word[0]; + } + } + else{ + str=""; + } + return str; +} diff --git a/2-Obenglobish/src/Obenglobish.cpp.autosave b/2-Obenglobish/src/Obenglobish.cpp.autosave new file mode 100644 index 0000000..ca4b5dc --- /dev/null +++ b/2-Obenglobish/src/Obenglobish.cpp.autosave @@ -0,0 +1,83 @@ +#include +#include +#include "console.h" +#include "simpio.h" +#include "strlib.h" +using namespace std; + +bool isVowel(char letter); +string obenglobish(string word); + +int main() { + while(true){ + string word = getLine("Enter a word: "); + if(word == "")break; + string translation = obenglobish(word); + cout<< word<<" -> "<0){ + if(word[0]=='e'&& word.length()==1){ + str +=word[0]; + } + else if(isVowel(word[0])&&isVowel(word[1])){ + str = str+string("ob")+word[0] + word[1] + obenglobish(word.substr(2,word.length()-2)); + } + else if(isVowel(word[0])&&!isVowel(word[1])){ + str = str+string("ob")+ word[0] + obenglobish(word.substr(1,word.length()-1)); + } + + else if(!isVowel(word[0])&& word.length() != 1){ + str +=word[0] + obenglobish(word.substr(1,word.length()-1)); + } + else{ + str +=word[0]; + } + } + else{ + str=""; + } + return str; +} From 23ff7df9290b09f942a20bfb7d9c941ff0cf95db Mon Sep 17 00:00:00 2001 From: vhrebenko Date: Mon, 24 Aug 2015 00:19:27 +0300 Subject: [PATCH 3/5] Assignment1.3 done --- 2-Obenglobish/src/Obenglobish.cpp | 4 +- 3-NumericConversion/NumericConversion.pro | 2 +- 3-NumericConversion/src/NumericConversion.cpp | 79 ++++++++++++++++++- 3 files changed, 82 insertions(+), 3 deletions(-) diff --git a/2-Obenglobish/src/Obenglobish.cpp b/2-Obenglobish/src/Obenglobish.cpp index ae12c6d..bfc0184 100644 --- a/2-Obenglobish/src/Obenglobish.cpp +++ b/2-Obenglobish/src/Obenglobish.cpp @@ -55,7 +55,9 @@ bool isVowel(char letter){ //} /***Implementing functions using recursion***/ - +//Each subsequent recursive call function divides +//the string that the user enters and performs +//actions with each individual Elements line. string obenglobish(string wordLine){ string str; string word = toLowerCase(wordLine); diff --git a/3-NumericConversion/NumericConversion.pro b/3-NumericConversion/NumericConversion.pro index 85bdbce..4570e8d 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..7ce11fe 100644 --- a/3-NumericConversion/src/NumericConversion.cpp +++ b/3-NumericConversion/src/NumericConversion.cpp @@ -1,6 +1,7 @@ #include #include #include "console.h" +#include using namespace std; // Function prototypes @@ -9,6 +10,82 @@ int stringToInt(string str); int main() { - // TODO: fill in the code +/****Testing functions intToString****/ + const int N = 10; + int numTest[N] = {2565,-2565,505,-505,50,-50,1,-1,0,0}; + for(int i=0;i Date: Fri, 28 Aug 2015 23:25:56 +0300 Subject: [PATCH 4/5] Assignmen_1.4 done --- 4-Flesch-Kincaid/FleschKincaid.pro | 2 +- 4-Flesch-Kincaid/src/FleschKincaid.cpp | 116 ++++++++++++++++++++++++- 2 files changed, 116 insertions(+), 2 deletions(-) diff --git a/4-Flesch-Kincaid/FleschKincaid.pro b/4-Flesch-Kincaid/FleschKincaid.pro index 85bdbce..e03d563 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/src/FleschKincaid.cpp b/4-Flesch-Kincaid/src/FleschKincaid.cpp index 0b16ad2..526cb37 100644 --- a/4-Flesch-Kincaid/src/FleschKincaid.cpp +++ b/4-Flesch-Kincaid/src/FleschKincaid.cpp @@ -1,8 +1,122 @@ #include #include "console.h" +#include +#include "tokenscanner.h" using namespace std; +//Function prototypes +void settingFile(); +void fleschKincaid(ifstream &infile); +int syllablesIn(string word); +bool checkVowels(char letter); +double grade(int words,int sentens,int syllables); + + int main() { - // TODO: fill in the code +settingFile(); return 0; } + +/*The function prompts the user for a filename. +Checks whether there is such a file. +If there is the object -ifstream infile-(The object read from the stream file) creates the file and +passes it to the function fleschKincaid */ +void settingFile(){ + string s; + cout<<"Enter input file name: "; + if(cin>>s){ + ifstream infile(s,ios::in); + if(infile.is_open()){ + fleschKincaid(infile); + } + else{ + cout<<"This file does not exist"< 0) { + if (letter != 'e' && !checkVowels(word[i - 1])) { + countWSyllables++; + } + } + + } + } + if (countWSyllables == 0) { + countWSyllables = 1; + } + return countWSyllables; + } + +//Determination of whether the letter is a vowel + bool checkVowels(char letter) { + if (letter == 'a' || letter == 'e' || letter == 'y' + || letter == 'i' || letter == 'u' || letter == 'o') { + return true; + } + return false; + } + +//Calculation Grade Level formula with pre-defined constants. + double grade(int words,int sentens,int syllables){ + double grade=0; + double const c0=-15.59; + double const c1=0.39; + double const c2=11.8; + grade = c0+c1*((double)words/sentens)+c2*((double)syllables/words); + return grade; + } From 27a932975ba456dbf043678878ee14ff64a41d7f Mon Sep 17 00:00:00 2001 From: vhrebenko Date: Wed, 2 Sep 2015 22:55:36 +0300 Subject: [PATCH 5/5] [The final adjustment] --- 2-Obenglobish/src/Obenglobish.cpp | 28 +------------------------- 4-Flesch-Kincaid/src/FleschKincaid.cpp | 9 +++++---- 2 files changed, 6 insertions(+), 31 deletions(-) diff --git a/2-Obenglobish/src/Obenglobish.cpp b/2-Obenglobish/src/Obenglobish.cpp index bfc0184..4fdf07a 100644 --- a/2-Obenglobish/src/Obenglobish.cpp +++ b/2-Obenglobish/src/Obenglobish.cpp @@ -26,33 +26,7 @@ bool isVowel(char letter){ return true; else return false; } -/*****Implementing functions using a loop****/ -//Function in a loop to iterate over all the -//letters of the string and if it finds a vowel, -//and in front of it is not worth another vowel confronts her line "ob". -//string obenglobish(string wordLine){ -// string str; -// string word = toLowerCase(wordLine); -// for(int i = 0;i>s){ - ifstream infile(s,ios::in); + if(cin.getline(str, sizeof(str))){ + ifstream infile(str,ios::in); if(infile.is_open()){ fleschKincaid(infile); + infile.close(); } else{ cout<<"This file does not exist"<