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

Large diffs are not rendered by default.

59 changes: 58 additions & 1 deletion 1-ConsecutiveHeads/src/ConsecutiveHeads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,66 @@
#include <string>
#include "console.h"
#include "random.h"
#include <simpio.h>
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);
}
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
257 changes: 257 additions & 0 deletions 2-Obenglobish/Obenglobish.pro.user.54c8766

Large diffs are not rendered by default.

87 changes: 86 additions & 1 deletion 2-Obenglobish/src/Obenglobish.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
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
106 changes: 103 additions & 3 deletions 3-NumericConversion/src/NumericConversion.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,114 @@
#include <iostream>
#include <string>
#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);
}
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
Loading