Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 1-ConsecutiveHeads/ConsecutiveHeads.pro
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ win32 {
QMAKE_LFLAGS += -Wl,--stack,536870912
LIBS += -lDbghelp
LIBS += -lbfd
LIBS += -liberty
# LIBS += -liberty
LIBS += -limagehlp
}
macx {
Expand Down
26 changes: 25 additions & 1 deletion 1-ConsecutiveHeads/src/ConsecutiveHeads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,33 @@
#include <string>
#include "console.h"
#include "random.h"

using namespace std;

string dropCoin(){
string res="tails";
if (randomChance(.5))
res="heads";
return res;
}

int main() {
// TODO: fill in the code

int headsCounter=0;

while(true){
string currentSide=dropCoin();

cout << currentSide << endl;

if(currentSide=="heads"){
headsCounter++;
if (headsCounter==3)
break;
} else {
headsCounter=0;
}
}

return 0;
}
2 changes: 1 addition & 1 deletion 2-Obenglobish/Obenglobish.pro
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ win32 {
QMAKE_LFLAGS += -Wl,--stack,536870912
LIBS += -lDbghelp
LIBS += -lbfd
LIBS += -liberty
# LIBS += -liberty
LIBS += -limagehlp
}
macx {
Expand Down
56 changes: 54 additions & 2 deletions 2-Obenglobish/src/Obenglobish.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,61 @@
#include "console.h"
#include "simpio.h"
#include "strlib.h"

using namespace std;

/**
* @brief isVowel - function to check, if char is vowel
* @param letterToCheck
* @return true if vowel
*/
bool isVowel(char letterToCheck){
char ch=letterToCheck;
if (ch == 'a' || ch == 'A' || ch == 'e' || ch == 'E' || ch == 'i' || ch == 'I' || ch =='o' || ch=='O' ||
ch == 'u' || ch == 'U'){
return true;
}
return false;
}

/**
* @brief obenglobish function translates word to ob-language
* @param word to translate
* @return translated word as string
*/
string obenglobish(string word){
string res="";

bool lastCharIsVowel=false;

for(int i=0;i<word.length();i++){

char currentChar=word[i];

string prefix="";

if(isVowel(currentChar)){
if(!lastCharIsVowel){
if(!(((currentChar=='e')||(currentChar=='E'))&&(i==word.length()-1)))
prefix="ob";
}
lastCharIsVowel=true;
}else{
lastCharIsVowel=false;
}

res+=prefix+currentChar;
}
return res;
}

int main() {
// TODO: fill in the code
return 0;
while(true){
string word=getLine("Enter a word");
if (word=="")
break;
string translation=obenglobish(word);
cout << word << " -> " << translation << endl;
}
return 0;
}
2 changes: 1 addition & 1 deletion 3-NumericConversion/NumericConversion.pro
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ win32 {
QMAKE_LFLAGS += -Wl,--stack,536870912
LIBS += -lDbghelp
LIBS += -lbfd
LIBS += -liberty
# LIBS += -liberty
LIBS += -limagehlp
}
macx {
Expand Down
45 changes: 43 additions & 2 deletions 3-NumericConversion/src/NumericConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,49 @@ using namespace std;
string intToString(int n);
int stringToInt(string str);

string intToString(int n){
if(n<0){
return "-"+intToString(-n);
}
if(n<10){
return string()+char(n+'0');
}
return intToString(n/10)+char(n%10+'0');
}


int stringToInt(string str){
if(str[0]=='-')
return -stringToInt(str.substr(1,str.length()-1));

int lastN=char(str[str.length()-1]-'0');

if(str.length()==1)
return lastN;

return lastN+10*stringToInt(str.substr(0,str.length()-1));
}

int main() {
// TODO: fill in the code
return 0;
int n=1234;
string res=intToString(n);
cout<<res<<" "<<res.length()<<endl;

n=-1234;
res=intToString(n);
cout<<res<<" "<<res.length()<<endl;

n=0;
res=intToString(n);
cout<<res<<" "<<res.length()<<endl;

string tsts="1234";
int res2=stringToInt(tsts);
cout<<res2<<endl;

tsts="-1234";
res2=stringToInt(tsts);
cout<<res2<<endl;

return 0;
}
2 changes: 1 addition & 1 deletion 4-Flesch-Kincaid/FleschKincaid.pro
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ win32 {
QMAKE_LFLAGS += -Wl,--stack,536870912
LIBS += -lDbghelp
LIBS += -lbfd
LIBS += -liberty
# LIBS += -liberty
LIBS += -limagehlp
}
macx {
Expand Down
1 change: 1 addition & 0 deletions 4-Flesch-Kincaid/res/1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
In the low-ceilinged canteen, noisy.
90 changes: 89 additions & 1 deletion 4-Flesch-Kincaid/src/FleschKincaid.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,96 @@
#include <iostream>
#include "console.h"
#include <iostream>
#include <fstream>
#include <string>
#include "tokenscanner.h"

using namespace std;

string vowels="aeiouy";

/**
* @brief getFName takes from user name of file to work.
* @return filename as string
*/
string getFName(){
string fname;
while (true) {
cout<<"Enter file name: ";
getline(cin,fname);
ifstream fileIn(fname,ios::in); //ios::nocreate
if(fileIn.is_open()){
break;
} else {
cout<<"Such file name is wrong." << endl;
}
}
return fname;
}

/**
* @brief countSyllables - count number of syllables in word
* @param word - word, in which count syllables
* @return number of syllables as int
*/
int countSyllables(string word){
int res=0;

bool lastCharVowel=false;

for(int i=0;i<word.length();i++){

char currentChar=tolower(word[i]);

if (vowels.find(currentChar)!=string::npos){
if(!lastCharVowel){
if(!((currentChar=='e')&&(i==(word.length()-1)))){
res++;
}
}
lastCharVowel=true;
} else {
lastCharVowel=false;
}
}
if(res==0)res=1; // becouse all words have at least 1 syllable
return res;
}

int main() {
// TODO: fill in the code

string fname=getFName();

ifstream fileIn(fname,ios::in); //ios::nocreate

TokenScanner scanner;
scanner.setInput(fileIn);
//scanner.ignoreWhitespace();
string ignoringChars;
ignoringChars= "\'";
scanner.addWordCharacters(ignoringChars);

int numWords=0, numCentences=0, numSyllabels=0;

while (scanner.hasMoreTokens()) {
string token = scanner.nextToken();
cout << token;
if(!isalpha(token[0])==0){
numWords++;
numSyllabels+=countSyllables(token);
} else if ((token[0]=='.')||(token[0]=='!')||(token[0]=='?')){
numCentences++;
}
}

cout << "Syllables: " << numSyllabels << ", words: " << numWords << ", centences: " << numCentences << endl;

double c0=-15.59, c1=0.39, c2=11.8;
double k1=double(numWords)/numCentences;
double k2=double(numSyllabels)/numWords;
double grade=c0+c1*k1+c2*k2;

cout <<"Grade: " << grade;

return 0;
}