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.8ad8611

Large diffs are not rendered by default.

259 changes: 259 additions & 0 deletions 1-ConsecutiveHeads/ConsecutiveHeads.pro.user.e083ff4

Large diffs are not rendered by default.

24 changes: 22 additions & 2 deletions 1-ConsecutiveHeads/src/ConsecutiveHeads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,27 @@
#include "random.h"
using namespace std;

/*
* Coin flip simulator. Сauses the random number generator which returns true or false
* until it randomly gives three times in a row the value true that would mean heads.
* At the end it displays a message about the number of flips that are needed to achieve results.
*/
int main() {
// TODO: fill in the code
return 0;
int consecutiveHeads = 3; //the required count of consecutive heads for finishing the game;
int countOfHeads = 0;
int countOfFlips = 0;
while(countOfHeads < consecutiveHeads) {
if(randomBool()){ //if true then we assume that it is heads
cout << "heads" <<endl;
++countOfHeads;
}
else {
cout << "tails" <<endl;
countOfHeads = 0;
}
++countOfFlips;
}
cout << "It took " << countOfFlips << " to get "
<< consecutiveHeads << " 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
259 changes: 259 additions & 0 deletions 2-Obenglobish/Obenglobish.pro.user.e083ff4

Large diffs are not rendered by default.

99 changes: 97 additions & 2 deletions 2-Obenglobish/src/Obenglobish.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,102 @@
#include "strlib.h"
using namespace std;


/*
* Makes translation from english to obenglobish "language" by adding
* "ob" before each spoken vowel (if before vowel is not a vowel,
* exept 'e' at the end of the word excluding words with single syllable).
* Takes a string as a parameter to be translated and returns "translation" of this string.
*/
string obenglobish(string);

/*
* Checks whether there is a vowel before the letter.
* @param string takes the line by reference where checks belonging vowel to one syllable
* by checking a previous letter to belong to vowel.
* @param int takes a position of a letter in the word which is checked.
*/
bool isOneVowel(const string &, int);

/*
* Takes a character as a parameter and checks whether a character is a vowel.
*/
bool isVowel(char);


/*
* Adds subword to the text.
* @ param string& the text passed by reference in which is inserted the subword
* @ param string the subword which is inserted.
* @param int the position where to insert the word
*/
void addSubwordToTheWord(string &, string, int);


/*
* Reads an input line and outputs an entered data with its translation.
*/
int main() {
// TODO: fill in the code
return 0;
while(true){
string text = getLine("Enter a text for translation: ");
if (text == "") {
break;
}
string translation = obenglobish(text);
cout << text << " -> " << translation << endl;
}
return 0;
}

string obenglobish (string text){
text += " "; //add one space to the end of the string for simpler control of the last character
string subword = "ob"; //declare a string that to be inserted before vowels
int countOfSyllables = 0; //declare a variable for counts of syllables
int i = 0;
if(isVowel(text[i])){
addSubwordToTheWord(text, subword, i);
/* iterator moves to the right by the length of the inserted substring plus one for move
* to the next character after vowel*/
i += (subword.length() + 1);
++countOfSyllables;
}
while(i < text.length() - 1){
if(isOneVowel(text, i)){
if((tolower(text[i]) == 'e') && (!isalpha(text[i+1])) && (countOfSyllables > 0)) {
++i;
}
else {
addSubwordToTheWord(text, subword, i);
++countOfSyllables;
i += (subword.length());//iterator moves to the right by the length of the inserted substring
}
}
if(text[i] == ' '){
countOfSyllables = 0; // resets the counter to zero when finds a spase (after the space starts a new word)
}
++i;
}
return text.substr(0, text.length() - 1); // remove the extra space from the end of the line
}


bool isOneVowel(const string &text, int position){
return ((isVowel(tolower(text[position]))) && (!isVowel(tolower(text[position - 1]))));
}

bool isVowel(char letter){
string vowels = "aeiou";
for(char vowel : vowels){
if(letter == vowel){
return true;
}
}
return false;
}


void addSubwordToTheWord(string &text, string subword, int possition){
text = text.insert(possition, subword);
}


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
69 changes: 68 additions & 1 deletion 3-NumericConversion/src/NumericConversion.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,81 @@
#include <iostream>
#include <string>
#include "console.h"
#include <cmath>
using namespace std;

// Function prototypes
/*
* Takes an integer as a parameter and returns a string identical
* to the passed number (takes into account the negative sign).
*/
string intToString(int n);

/*
* Takes a string, which may contain only a sign ('+' or '-') and
* digits of the number, as a parameter and returns an integer identical
* to the passed string (takes into account the negative or positive sign).
*/
int stringToInt(string str);


/*
* Asks the user to enter two numbers that are put into variables
* of type string. Converts strings to integers and displays the result
* of the mathematical addition. After that, converts the integers
* back to strings and displays the result of a string concatenation.
*/
int main() {
// TODO: fill in the code
string firstNumber = "";
string secondNumber = "";
cout << "Enter a first number: ";
cin >> firstNumber;

cout << "Enter a second number: ";
cin >> secondNumber;

int a = stringToInt(firstNumber);
int b = stringToInt(secondNumber);

cout << "Mathematical addition of two entered numbers: "
<< firstNumber << " + " << secondNumber << " = "
<< (a + b) << endl;

cout << "Adding the digits of the first number to the end of the second one: "
<< firstNumber << " and " << secondNumber << " -> "
<< (intToString(a) + intToString(b)) << endl;

return 0;
}

int stringToInt(string digits){
if(digits.length() == 1){
return (digits[0] - '0');
}
if((digits[0] == '-') || (digits[0] == '+')){
char sign = digits[0]; // memorize the sign
digits = digits.substr(1); // and delete the sign
if(sign == '-'){
if (digits.length() == 1){ // conversion for negative single-digit numbers
return -1*(digits[0] - '0');
}
else return -1*((digits[0] - '0')*pow(10, (digits.length()-1)) + stringToInt(digits.substr(1)));
}
else return (digits[0] - '0'); //conversion for positive single-digit numbers
}
return (digits[0] - '0')*pow(10, (digits.length()-1)) + stringToInt(digits.substr(1));
}


string intToString(int number){
string sign = ""; // accept that there is no sign
if (number < 0){
sign = "-"; // if the number is negative then memorize the negative sign
number *= -1; // convert the number into a positive
}
if (number/10 == 0){
return (sign + char(number + '0'));
}
// if the passed number was negative then convert it back into the negative for pass recursively
return intToString((sign == "-" ? -1*number : number)/10) + char(number % 10 + '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
Loading