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.3bfad9d

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

34 changes: 32 additions & 2 deletions 1-ConsecutiveHeads/src/ConsecutiveHeads.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,40 @@
/*File ConsecutiveHeads.cpp
* ------------------------------------------------------
*
* This program simulates a coin toss until heads fall three
* consecutive times.
*/

#include <iostream>
#include <string>
#include "console.h"
#include "random.h"

using namespace std;


/* Main program*/
int main() {
// TODO: fill in the code
return 0;

const int NUM_OF_HEADS = 3;

int counter = 0;
int counterFlips = 0;

while (counter < NUM_OF_HEADS){
if(randomBool()){
counter++;
counterFlips++;
cout << "heads" << endl;
}
else {
counter = 0;
counterFlips++;
cout << "tails" << endl;
}
}
cout << endl << "It took " << counterFlips << " flips to get " << NUM_OF_HEADS << " consecutive heads.";
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.3bfad9d

Large diffs are not rendered by default.

259 changes: 259 additions & 0 deletions 2-Obenglobish/Obenglobish.pro.user.7e432c6

Large diffs are not rendered by default.

149 changes: 148 additions & 1 deletion 2-Obenglobish/src/Obenglobish.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,158 @@

/* File: Obenglobish.cpp
* ---------------------------------------------------------
*
* This program asks the user for word in English and translate
* it to Obenglobish dialect by folowing rule:
*
* Add text "od" before every vowel in the English word except
* vowels that follow other vowels and "e" character that occurs
* at the end of the word.
*
*/


#include <iostream>
#include <string>
#include "console.h"
#include "simpio.h"
#include "strlib.h"
using namespace std;

/* Functions prototypes */
string obenglobish(string word);
bool isVowel(char ch);
string filterString(string word);
void capitalizeWord(string &word);

/* Main program*/
int main() {
// TODO: fill in the code
while (true) {
string word = getLine("Enter a word: ");
if (word != "") {
word = filterString(word);
cout << word << " -> " << obenglobish(word) << endl;
}
}
return 0;
}

/* Function: obenglobish
* Usage: cout << word << " -> " << obenglobish(word) << endl;
* -----------------------------------------------------------
*
* Translates received word to Obenglobish using specified rules.
* Check if the first letter if vowel and add's to result text "ob"
* and this letter. Than check other letters and if current letter is
* vowel and before this letter is not vowel add's text "ob" and this letter
* to the result. Otherwise add's only current letter. Also check last letter
* and if it "E" dont add's "ob" before it.
*
* @param word The word to translate into Obenglobish
* @return Translated word
*/

string obenglobish(string word){

const string OB = "ob"; //text to add before vowels

string result = "";

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

if(i == 0 ){ //for the first letter in word
if(isVowel(word.at(i))){
result += OB + word.at(i);
}
else {
result += word.at(i);
}

} else if (i == word.length() - 1) { //for the last letter in word
if (isVowel(word.at(i)) && word.at(i) != 'E' && word.at(i) != 'e' ){
result += OB + word.at(i);
} else {
result += word.at(i);
}

} else { // for other letters
if (isVowel(word.at(i)) && !isVowel(word.at(i - 1))){
result += OB + word.at(i);
} else {
result += word.at(i);
}
}


}

capitalizeWord(result);
return result;
}


/* Function: filterString
* Usage: word = filterString(word);
* -----------------------------------------------------
*
* Return received string without non alphabetic symbols
*
* @param word The text for filtering
* @return Filtered text
*/
string filterString(string word){
string result = "";

for (int i = 0; i < word.length(); i++ ){
if(isalpha( word.at(i))){
result += word.at(i);
}

}

return result;
}

/* Function: isVowel
* Usage: if(isVowel(word.at(i)))...
* ----------------------------------------------------
*
* Return TRUE if received charecter is vowel
* and FALSE if no.
*
* @param ch Character that will be checked
* @return Boolean result of the check
*/
bool isVowel(char ch){

switch (ch) {
case 'a': case 'e': case 'i': case 'o': case 'u':
case 'A': case 'E': case 'I': case 'O': case 'U':
return true;


default:
return false;
}
}

/* Function: capitalizeWord
* Usage: capitalizeWord(result);
* ---------------------------------------------------
*
* Change text received in link transforming first letter to uppercase
* and other letters to lowercase
*
* @param word Link to string class object that will be capitalized
*/
void capitalizeWord(string &word){

for(int i = 0; i < word.length(); i++){
if(i == 0){
word.at(i) = toupper(word.at(i));
} else {
word.at(i) = tolower(word.at(i));
}
}

}
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
Loading