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
39 changes: 37 additions & 2 deletions 1-ConsecutiveHeads/src/ConsecutiveHeads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,42 @@
#include "random.h"
using namespace std;

//initialization function prototype
int coinToss(int &numberOfMatches,int &count);


int main() {
// TODO: fill in the code
return 0;
//Initialization of variables: the number of matches
//and a variable number of attempts
int numberOfMatches = 0;
int count = 0;
coinToss(numberOfMatches,count);
cout<<"It took "<<count<<" flips to get "<<numberOfMatches<<" consecuteve heads"<<endl;
return 0;
}

//The function receives the variable references are
//responsible for the number of matches and the number of attempts.
//At the beginning of the function is increased count++(Number of attempts).
//And then, depending on the function randomBool() result is an increase in the variable
//numberOfMatches or reset, and a recursive call to the original function until
//the variable numberOfMatches is not equal to three.

int coinToss(int &numberOfMatches,int &count){
bool sideCoin = randomBool();
count++;
if(sideCoin == true){
numberOfMatches++;
cout<<"heads"<<endl;
if(numberOfMatches==3){
return 0;
}
coinToss(numberOfMatches,count);
}
else{
cout<<"tails"<<endl;
numberOfMatches=0;
coinToss(numberOfMatches,count);
}
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
51 changes: 50 additions & 1 deletion 2-Obenglobish/src/Obenglobish.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,56 @@
#include "strlib.h"
using namespace std;

bool isVowel(char letter);
string obenglobish(string word);

int main() {
// TODO: fill in the code
while(true){
string word = getLine("Enter a word: ");
if(word == "")break;
string translation = obenglobish(word);
cout<< word<<" -> "<<translation<<endl;
}

return 0;
}

/*Check whether it is a vowel letters.
* If so it returns true if not returns false*/
bool isVowel(char letter){
if(letter =='a'||letter =='u'||letter =='i'||letter =='o'|| letter == 'e')
return true;
else return false;
}


/***Implementing functions using recursion***/
//Each subsequent recursive call function divides
//the string that the user enters and performs
//actions with each individual Elements line.
string obenglobish(string wordLine){
string str;
string word = toLowerCase(wordLine);
if(word.length()>0){
if(word[0]=='e'&& word.length()==1){
str +=word[0];
}
else if(isVowel(word[0])&&isVowel(word[1])){
str = str+string("ob")+word[0] + word[1] + obenglobish(word.substr(2,word.length()-2));
}
else if(isVowel(word[0])&&!isVowel(word[1])){
str = str+string("ob")+ word[0] + obenglobish(word.substr(1,word.length()-1));
}

else if(!isVowel(word[0])&& word.length() != 1){
str +=word[0] + obenglobish(word.substr(1,word.length()-1));
}
else{
str +=word[0];
}
}
else{
str="";
}
return str;
}
83 changes: 83 additions & 0 deletions 2-Obenglobish/src/Obenglobish.cpp.autosave
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include <iostream>
#include <string>
#include "console.h"
#include "simpio.h"
#include "strlib.h"
using namespace std;

bool isVowel(char letter);
string obenglobish(string word);

int main() {
while(true){
string word = getLine("Enter a word: ");
if(word == "")break;
string translation = obenglobish(word);
cout<< word<<" -> "<<translation<<endl;
}

return 0;
}

/*Check whether it is a vowel letters.
* If so it returns true if not returns false*/
bool isVowel(char letter){
if(letter =='a'||letter =='u'||letter =='i'||letter =='o'|| letter == 'e')
return true;
else return false;
}
/*****Implementing functions using a loop****/
//Function in a loop to iterate over all the
//letters of the string and if it finds a vowel,
//and in front of it is not worth another vowel confronts her line "ob".
//string obenglobish(string wordLine){
// string str;
// string word = toLowerCase(wordLine);
// for(int i = 0;i<word.length();i++){
// if(word[i]=='e'){
// if((i != word.length()-1)&&(!isVowel(word[i-1]))){
// str = str+string("ob")+word[i];
// }
// else{
// str +=word[i];
// }
// }
// else{
// if(isVowel(word[i]) && !isVowel(word[i-1])){
// str = str+string("ob")+word[i];
// }
// else{
// str +=word[i];
// }
// }
// }
// return str;
//}

/***Implementing functions using recursion***/
string obenglobish(string wordLine){
string str;
string word = toLowerCase(wordLine);
if(word.length()>0){
if(word[0]=='e'&& word.length()==1){
str +=word[0];
}
else if(isVowel(word[0])&&isVowel(word[1])){
str = str+string("ob")+word[0] + word[1] + obenglobish(word.substr(2,word.length()-2));
}
else if(isVowel(word[0])&&!isVowel(word[1])){
str = str+string("ob")+ word[0] + obenglobish(word.substr(1,word.length()-1));
}

else if(!isVowel(word[0])&& word.length() != 1){
str +=word[0] + obenglobish(word.substr(1,word.length()-1));
}
else{
str +=word[0];
}
}
else{
str="";
}
return str;
}
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
79 changes: 78 additions & 1 deletion 3-NumericConversion/src/NumericConversion.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <iostream>
#include <string>
#include "console.h"
#include <ctype.h>
using namespace std;

// Function prototypes
Expand All @@ -9,6 +10,82 @@ int stringToInt(string str);


int main() {
// TODO: fill in the code
/****Testing functions intToString****/
const int N = 10;
int numTest[N] = {2565,-2565,505,-505,50,-50,1,-1,0,0};
for(int i=0;i<N;i++){
string res = intToString(numTest[i]);
cout<<res<<endl;
}
/****Testing functions stringToInt****/
string stringTest[6]={"1234","-1234","234","-234","0","0"};
for(int i=0;i<6;i++){
cout<<stringToInt(stringTest[i])<<endl;
}
return 0;
}


/*The function takes a number and divides it with the help of recursion into tenths hundredths,
and so on. And hildren number converted to a string with one character
and adds them to the result string.And thus returns the number of characters in a string.*/
string intToString(int n){
string res;
if(n == 0){
return "0";
}
if(n<0){
n = -n;
res +=(string()+ '-');
}
if(n/10 == 0){
return res += string()+char(n%10 + '0') ;
}
res +=intToString(n/10)+(string()+char(n%10 + '0'));
return res;
}

/* The function receives the string.It takes the last character of
a string and converts it to a number and adds to it the result
of recursively caused by the same function multiplied by the parameter 10.
Recursive function gets the input string but less than one character.*/
int stringToInt(string str){
int res = 0;
if(str[0]=='-'){
res = -1*(stringToInt(str.substr(1,str.length()-1)));
return res;
}
int lastNumbe = char(str[str.length()-1]-'0');
if(str.length()==1){
return lastNumbe;
}
res = lastNumbe+10*stringToInt(str.substr(0,str.length()-1));
return res;
}

// *****Implementation of the function to convert a string to a number using the cycle*****

/* int stringToInt(string str){
int s=0;
int iMin=0;
int al=str.length();
if(str[0]=='-'){
al--;
iMin = 1;
}
int k=1;
for(int i=0;i<al-1;i++)
{
k*=10;
}
for(int i=iMin;i<str.length();i++)
{
s+=(str[i]-'0')*k;
k/=10;
}
if(iMin == 1){
return -s;
}
return s;
}
*/
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