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
259 changes: 259 additions & 0 deletions 1-ConsecutiveHeads/ConsecutiveHeads.pro.user.1636703

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions 1-ConsecutiveHeads/src/ConsecutiveHeads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,18 @@ using namespace std;

int main() {
// TODO: fill in the code
int countFlips = 0;
int countFlipsToWin = 0;
while (countFlipsToWin < 3){
if (randomBool()) {
cout<<"heads"<<endl;
countFlipsToWin++;
} else{
cout<<"tails"<<endl;
countFlipsToWin=0;
}
countFlips++;
}
cout<<"It took "<<countFlips<<" flips to get 3 consecutive heads."<<endl;
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
47 changes: 47 additions & 0 deletions 2-Obenglobish/src/Obenglobish.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,54 @@
#include "strlib.h"
using namespace std;

//Function checks if a given character a vowel
//Param letter - a symbol that you want to analyze
//return - true if the character is a vowel
bool isVowel(char letter){
char vowelSymbols[] = "AEIOUYaeiouy";

for(int i = 0; vowelSymbols[i] != '\0'; i++){
if(letter == vowelSymbols[i])
return true;
}

return false;
}

//Function converts the string in obengoblish form
//Param line - the string to be translated
//return string line in form obenglobish
string obengoblish(string line){
if (line == "") return line;
string result;
string modifier = "ob";
char cheklastLetter = 'e';
int lineLastLetterIndex = line.length()-1;

for (int i=0; line[i] != '\0'; i++){

if (isVowel(line[i]) & !isVowel(line[i+1])) {

if ((line[i] == cheklastLetter) & (i == lineLastLetterIndex) || ( isVowel(line[i-1]))){
result += line[i];
continue;
}
result += modifier + line[i];

} else result += line[i];

}
return result;
}

int main() {
// TODO: fill in the code
while (true) {
string line = getLine("Enter a word: ");
if (line == "") break;

cout << line << " -> " << obengoblish(line)<< 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
73 changes: 73 additions & 0 deletions 3-NumericConversion/src/NumericConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,80 @@ string intToString(int n);
int stringToInt(string str);



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

int tests[] = {
0, 100, -5, 10, 5, 1729
};
string tests2[] = {"0", "100", "-5", "123456", "-123456", "733"};
const int B = 6;
for (int i=0; i<B; i++)
{
cout << "Converting the integer "<< tests[i] <<" to string: ";
cout << intToString(tests[i]) << endl;
cout << "Converting the string "<< tests2[i] <<" to integer: ";
cout << stringToInt(tests2[i]) << endl<< endl;
}
// cout << "Converting the string "<< " * -123465 " <<" to integer: " << stringToInt("-123456");

return 0;
}
/*function converts a string to a integer only from the positive numbers
* param str = row in which only digits shall be;
return = converted string into a integer
*/
int positiveStringToInt(string str){
if (str[0] == '\0') return 0;
char lastDigit = str[str.length()-1];
if (str.length()-1 == 0) return (lastDigit - '0');
return stringToInt(str.substr(0,str.length()-1)) * 10 + lastDigit - '0';;

}

/*function converts a string to a integer
* param str = string which should be a digit, the first character could be "-" indicates that the number is less than zero
return = converted string into a integer
*/
int stringToInt(string str){
int resultInt = 0;
if (str[0] == '-'){
str = str.substr(1,str.length()-1);
resultInt = 0 - positiveStringToInt(str);
} else
resultInt = positiveStringToInt(str);
return resultInt;
}


/*function converts a integer to a string
* param number = the number that you want to convert into a string
return = string that contains a specified number
*/

string intToString(int number){
string resultString;
/*
function intToString I brazenly copied from the Internet while
searching for the Board but thoroughly analyzed,
found www.cplusplus.com/forum/beginner/78550/
*/
static bool recursive_call = false; //is this a recursive call?
if(!recursive_call) {
if(!number) return "0"; //deal with zero
else if(number < 0) { //account for negative numbers
number *= -1;
resultString += '-';
}
recursive_call = true; //get ready for recursive calls
}
else if(!number) { //conversion is complete, reset function for future calls
recursive_call = false;
return "";
}

char appendCh = number % 10 + '0'; //convert to a character
return resultString + intToString(number / 10) + appendCh; //append the characters in the correct order
}

Binary file added 4-Flesch-Kincaid/Flesch-Kincaid Demo.exe
Binary file not shown.
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/Hi.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Hi!
fhehyuyke.
123 changes: 123 additions & 0 deletions 4-Flesch-Kincaid/src/FleschKincaid.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,131 @@
#include <iostream>
#include "console.h"
#include <fstream>
#include "tokenscanner.h"
using namespace std;


bool checkIsPunctuation(string token){
string punctuation = ".!?";
for (int i=0; punctuation[i] != '\0'; i++){
if (punctuation[i] == token[0]) return true;
}
return false;
}

//Function checks if a given character a vowel
//Param letter - a symbol that you want to analyze
//return - true if the character is a vowel
bool checkCharIsVowel(char letter){
char vowelSymbols[] = "AEIOUYaeiouy";

for(int i = 0; vowelSymbols[i] != '\0'; i++){
if(letter == vowelSymbols[i])
return true;
}

return false;
}

bool checkLastCharE(char c) {
char leterE = 'e';
if (c == leterE) return true;
return false;
}

/*
* Given a word, estimates the number of syllables in that word according to the
* heuristic specified in the handout.
*
* @param token - A string containing a single word.
* @return An estimate of the number of syllables in that word.
*/
int countSyllables(string token){
int syllablesCounter = 0;

for (int i=0; token[i] != '\0'; i++){

if (checkCharIsVowel(token[i]) &
!checkCharIsVowel(token[i - 1])){

syllablesCounter++;
}

}
if (checkLastCharE(token[token.length()-1]) &
!checkCharIsVowel(token[token.length()-2])){

syllablesCounter--;
}

if (syllablesCounter <= 0) syllablesCounter = 1;

return syllablesCounter;
}

void analiseFileToGradeLevel(ifstream & myFile){
double gradeLevelResult = 0;

double wordCounter = 0;

double syllablesCounter = 0;

double sentencesCounter = 0;

const double cZero = -15.59;
const double cOne = 0.39;
const double cTwo = 11.8;

TokenScanner scanner(myFile);
scanner.ignoreWhitespace();
scanner.addWordCharacters("'");

while (scanner.hasMoreTokens()) {

string token = scanner.nextToken();
// count the number of words and syllables in each
if (isalpha( token[0])) {
wordCounter++;
syllablesCounter +=countSyllables(token);

//cout<<"word: ["<<token<<"] syllables in word: "<<countSyllables(token)<<endl;
} //else cout<<"token: ["<<token<<"]"<<endl;

// counting the number of sentence for punctuation
if (checkIsPunctuation(token)) {
sentencesCounter++;
//cout<<"(end of sentence)"<<" sentencesCounter: "<<sentencesCounter<<endl;
}

}
if (wordCounter == 0) wordCounter++;

if (sentencesCounter == 0) sentencesCounter++;

cout<<"wordCounter: "<<wordCounter<<endl;
cout<<"syllablesCounter: "<<syllablesCounter<<endl;
cout<<"sentencesCounter: "<<sentencesCounter<<endl;
gradeLevelResult = cZero + cOne * ( wordCounter / sentencesCounter) + cTwo * (syllablesCounter / wordCounter);
cout<<"Grade Level: "<<gradeLevelResult<<endl;

}

int main() {
// TODO: fill in the code
string fileName;
ifstream myFile;
while (true) {
cout<<"Enter file name pls:";
cin>>fileName;
myFile.open(fileName);
if (myFile.is_open()){

cout<<"FILE IS OPEN" <<endl;

analiseFileToGradeLevel(myFile);

} else cout<<"File not found :("<<endl;
myFile.close();
}
return 0;
}
Binary file added 4-Flesch-Kincaid/windows.zip
Binary file not shown.
14 changes: 14 additions & 0 deletions 4-Flesch-Kincaid/windows/1984.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
In the low-ceilinged canteen, deep underground, the lunch queue jerked slowly forward. The
room was already very full and deafeningly noisy. From the grille at the counter the steam
of stew came pouring forth, with a sour metallic smell which did not quite overcome the
fumes of Victory Gin. On the far side of the room there was a small bar, a mere hole in the
wall, where gin could be bought at ten cents the large nip.
'Just the man I was looking for,' said a voice at Winston's back.
He turned round. It was his friend Syme, who worked in the Research Department.
Perhaps 'friend' was not exactly the right word. You did not have friends nowadays, you had
comrades: but there were some comrades whose society was pleasanter than that of others.
Syme was a philologist, a specialist in Newspeak. Indeed, he was one of the enormous team
of experts now engaged in compiling the Eleventh Edition of the Newspeak Dictionary. He
was a tiny creature, smaller than Winston, with dark hair and large, protuberant eyes, at
once mournful and derisive, which seemed to search your face closely while he was speaking
to you.
Binary file added 4-Flesch-Kincaid/windows/Flesch-Kincaid Demo.exe
Binary file not shown.
15 changes: 15 additions & 0 deletions 4-Flesch-Kincaid/windows/Flesch-Kincaid Demo.exe.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
</requestedPrivileges>
</security>
</trustInfo>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.VC90.DebugCRT" version="9.0.21022.8" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
</dependentAssembly>
</dependency>
</assembly>
1 change: 1 addition & 0 deletions 4-Flesch-Kincaid/windows/Hi.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hi!
14 changes: 14 additions & 0 deletions 4-Flesch-Kincaid/windows/JFK-Berlin.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
I am proud to come to this city as the guest of your distinguished Mayor, who has symbolized throughout the world the fighting spirit of West Berlin. And I am proud to visit the Federal Republic with your distinguished Chancellor who for so many years has committed Germany to democracy and freedom and progress, and to come here in the company of my fellow American, General Clay, who has been in this city during its great moments of crisis and will come again if ever needed.
Two thousand years ago the proudest boast was "civis Romanus sum." Today, in the world of freedom, the proudest boast is "Ich bin ein Berliner."

I appreciate my interpreter translating my German!

There are many people in the world who really don't understand, or say they don't, what is the great issue between the free world and the Communist world. Let them come to Berlin. There are some who say that communism is the wave of the future. Let them come to Berlin. And there are some who say in Europe and elsewhere we can work with the Communists. Let them come to Berlin. And there are even a few who say that it is true that communism is an evil system, but it permits us to make economic progress. Lasst sie nach Berlin kommen. Let them come to Berlin.

Freedom has many difficulties and democracy is not perfect, but we have never had to put a wall up to keep our people in, to prevent them from leaving us. I want to say, on behalf of my countrymen, who live many miles away on the other side of the Atlantic, who are far distant from you, that they take the greatest pride that they have been able to share with you, even from a distance, the story of the last 18 years. I know of no town, no city, that has been besieged for 18 years that still lives with the vitality and the force, and the hope and the determination of the city of West Berlin. While the wall is the most obvious and vivid demonstration of the failures of the Communist system, for all the world to see, we take no satisfaction in it, for it is, as your Mayor has said, an offense not only against history but an offense against humanity, separating families, dividing husbands and wives and brothers and sisters, and dividing a people who wish to be joined together.

What is true of this city is true of Germany--real, lasting peace in Europe can never be assured as long as one German out of four is denied the elementary right of free men, and that is to make a free choice. In 18 years of peace and good faith, this generation of Germans has earned the right to be free, including the right to unite their families and their nation in lasting peace, with good will to all people. You live in a defended island of freedom, but your life is part of the main. So let me ask you as I close, to lift your eyes beyond the dangers of today, to the hopes of tomorrow, beyond the freedom merely of this city of Berlin, or your country of Germany, to the advance of freedom everywhere, beyond the wall to the day of peace with justice, beyond yourselves and ourselves to all mankind.

Freedom is indivisible, and when one man is enslaved, all are not free. When all are free, then we can look forward to that day when this city will be joined as one and this country and this great Continent of Europe in a peaceful and hopeful globe. When that day finally comes, as it will, the people of West Berlin can take sober satisfaction in the fact that they were in the front lines for almost two decades.

All free men, wherever they may live, are citizens of Berlin, and, therefore, as a free man, I take pride in the words "Ich bin ein Berliner."
Loading