Post of the weeks #11,12,13,14,15 and 16 what things I learned in these weeks ? And Index of Mastery Topics

Post of the weeks #11,12,13,14,15 and 16 what things I learned in these weeks ? And Index of Mastery Topics

Picture of author

First let me tell you that  I learn and achieved all transversal topics and you can see it in the following link: Post of the week #3 what things i learned in this week #3 ? And Index of Mastery Topics

I also explain my project and formed a small team that corresponds of completing this ability to create C++ project in IDE and run inside the IDE and can be explained in my post My Project For the Course TC1017 and Expo Ing. Let’s code!

Futhermore, I am going to present the report of all the Mastery Topics achieved in this week:

  1. #Mastery01 Use of comments, achieved in: Post of the week #2 what things i learned in this week #2 ?
  2. #Mastery02 C++ Good Style coding conventions, achieved in: Post of the week #2 what things i learned in this week #2 ?
  3. #Mastery03 Basic types and their use, achieved in: Post of the week #2 what things i learned in this week #2 ?
  4. #Mastery04 Basic output (print), achieved in: Post of the week #2 what things i learned in this week #2 ?
  5. #Mastery05 Basic user input (text based), achieved in: Post of the week #2 what things i learned in this week #2 ?
  6. #Mastery06 Calling functions, achieved in: #Quiz03. Also here:#WSQ08 Yo soy 196 11/03/17 and WSQ08.cpp
  7. #Mastery07 Creating functions, achieved in: #Quiz03. Also here: #WSQ08 Yo soy 196 11/03/17 and WSQ08.cpp
  8. #Mastery08 Importing and using libraries, achieved in: Post of the week #1 what things i learned in this week #1 ? Also in #WSQ08 Yo soy 196 11/03/17 and WSQ08.cpp
  9. #Mastery09 Creating and using your own libraries (program with multiple files), achieved in: #Quiz03. Furthermore, also in here: #WSQ08 Yo soy 196 11/03/17 and WSQ08.cpp
  10. #Mastery10 Use of the conditional “if”, achieved in: #WSQ02 Post Temperature 23/01/17 and WSQ02.cpp
  11. #Mastery11 Use of “else” with a conditional if, achieved in: #WSQ02 Post Temperature 23/01/17 and WSQ02.cpp
  12. #Mastery12 Nesting of conditional statements (ifs inside ifs): #WSQ02 Post Temperature 23/01/17 and WSQ02.cpp
  13. #Mastery13 Use of loops with “while” and “do while”, achieved in: #WSQ03 Post Pick a Number 23/01/17 and WSQ03.cpp
  14. #Mastery14 Use of loops with “for”, achieved in: #WSQ04 Post Sum of Numbers 23/01/17 and WSQ04.cpp
  15. #Mastery15 Nested loops, achieved in:#WSQ08 Yo soy 196 11/03/17 and WSQ08.cpp
Anuncios

#WSQ12 Estimating e 15/04/17 and WSQ12.cpp

#WSQ12 Estimating e 15/04/17 and WSQ12.cpp

So in this fourteen week class I started with doing this WSQ12 I started reviewing in creating and calling functions in C++.#Mastery06, #Mastery07, #Mastery16 Use of recursion for repetitive algorithms, #Mastery17 When to use what type of repetition in a program, #Mastery18 Creation and use of Arrays/ Vectors in C++. Furthermore, in this stage I have all the topics of the course from 1 to 22.

What I did for this numeric program is solving the problem to the user by creating a program with writing this assignment where I will estimate the mathematical constant e. I should create a function called calculuate_e which receives one parameter called precision that should specify the number of decimal points of accuracy.

I will want to use the infinite series to calculate the value, stopping when the accuracy is reached (previous and current calculation are the same at the specified accuracy).

Hence, the resources I need it to solve this program are here:

For doing this tutorial you need to do the factorial, therefore you need to see my tutorial #WSQ06 Factorial Calculator 12/02/17 and WSQ06.cpp

ken bauer

And the next picture shows us how the number e is calculated with infinite series and I will do this infinite serie in c++

Resultado de imagen para e number

Link of picture

The following photograph shows the solution to this problem:

w1

w2

w3

p666

So at first I wrote the same structure of the program just did the same as what i did in Hello World: Second Class, Second Blog (Blog of the second class 12/01/17) and Hello World.cpp,  #WSQ01 Post Fun with Numbers 16/01/17 and WSQ1.cpp#WSQ02 Post Temperature 23/01/17 and WSQ02.cpp#WSQ03 Post Pick a Number 23/01/17 and WSQ03.cpp#WSQ04 Post Sum of Numbers 23/01/17 and WSQ04.cpp#WSQ05 Six Tutorial On To Functions 12/02/17 and WSQ05.cpp#WSQ06 Factorial Calculator 12/02/17 and WSQ06.cpp#WSQ07 Lists 03/03/17 and WSQ07.cpp, #WSQ08 Yo soy 196 11/03/17 and WSQ08.cpp#WSQ09 Multipart Data and Files 10/03/17 and WSQ09.cpp , #WSQ10 Babylonian Method 21/03/17 and WSQ10.cpp and #WSQ11 Go Bananas 15/04/17 and WSQ11.cpp where i explained the application of the #MasteryTopic01 that it is for comments that could be very useful when debugging and #MasteryTopic04 that is basic output for data. Also I did some other mastery topics.

What i first put in the code was the library to call all the fuctions of inputs and outputs of data in languague C++ #MasteryTopic01.

#include <iostream> //Library to call all the
//fuctions of inputs and outputs of data in languague
//C++ #MasteryTopic01

Then, we need to use a Library to call all the fuctions of math commands in languague C++ #MasteryTopic01


#include <cmath> //Library to call all the
//fuctions of math commands in languague
//C++ #MasteryTopic01

Next, in C++ we need a command that everytime goes with the instructions of input and outputs of data that is call std but with this command helps writing these std out of the main because the machine factorizes them

using namespace std; //In C++ we need a command
// that everytime goes with the instructions of input and outputs
//of data that is call std but with this command helps writing
//these std out of the main because the machine factorizes them

 

Next we have our int main and we declarate float variable precision

float precision; //Declarate float variable precision

Then we need a #Mastery04 command of out data in form of text

cout<<"Specify the number of decimal points of accuracy: "; //#Mastery04 command of out data in form of text

After that, we need a #Mastery05 This command allows enter data for inputs. In this case this enters the value of variable ‘precision’

cin>>precision; //#Mastery05 This command allows enter data for inputs. In this case this enters the
//value of variable 'precision'

“Finally” the program comes back to the int main when I called the function calculate_e with the precision parameter, we need a command of out data in form of text. In this text we show the authentic output of the value entered of precision in the terminal interface #MasteryTopic04

cout<<"The estimation of e with "<<precision<<" decimal points is e = "<<calculuate_e (precision)<<endl; //command of out data in form of text
//In this text we show the authentic output of the value entered of precision in the terminal interface #MasteryTopic04

Next in the calculate_e function. This is the structure of a function where you have subrutines in order to make different tasks, in this case we have a FLOAT function with the name “calculuate_e” and with float parameter precision in order to have float results inside this function.

float calculuate_e (float precision) //This is the structure of a function where you have subrutines in order to make
//different tasks, in this case we have a FLOAT function with the name "calculuate_e" and with float parameter precision
//in order to have float results inside this function.

Furthermore in the function, we need to declarate float variable e initialized in 1

float e = 1; //Declarate float variable e initialized in 1

Furthermore in the function, we need to declarate float variable previuse.

float previuse; //Declarate float variable previuse

Next, we need to declarate an int variable i initialized in 1

int i=1; //Declarate float variable i initialized in 1

Moreover, with this command do is utilized as a loop do execute all the instruccions that has this loop until that does not complete that the variable of the absolute value of the difference between e and previuse abs e-previuse>precision will be less or equal than the numerical value of precision variable while it is increasing one in one in this variable i inicialized from the value 1. This was the condition of the WSQ

do //With this command do is utilized as a loop do execute all the
//instruccions that has this loop until that does not complete that the variable abs e-previuse>precision
// will be less or equal than the numerical value of precision variable while it is increasing one in one in this variable i
//inicialized from the value 1
{
previuse=e;
e = e + 1/(factorial(i)); //This is a math operation between 'e' and
// the value of the float function factorial with the int parameter i and stands for
//do the sum of e and the inverse operation of the factorial function with the i parameter and saved it in the float
//variable 'e', this is the operation of the infinite series thanks to the recursion #Mastery16 Use of recursion for repetitive
//algorithms
cout<<e<<endl;
i++;
} while(abs (e-previuse)>precision);

Then, we need to give the value of e to variable previuse

previuse=e;//Give the value of e to variable previuse

Next, This is a math operation between ‘e’ and the value of the float function factorial with the int parameter i and stands for do the sum of e and the inverse operation of the factorial function with the i parameter and saved it in the float variable ‘e’, this is the operation of the infinite series thanks to the recursion #Mastery16 Use of recursion for repetitive algorithms.

e = e + 1/(factorial(i)); //This is a math operation between 'e' and
// the value of the float function factorial with the int parameter i and stands for
//do the sum of e and the inverse operation of the factorial function with the i parameter and saved it in the float
//variable 'e', this is the operation of the infinite series thanks to the recursion #Mastery16 Use of recursion for repetitive
//algorithms

Moreover, after this last operation the program goes to a function that calculates the factorial. This is the structure of a function where you have subrutines in order to make different tasks, in this case we have a float function with the name “factorial” and with int parameters n in order to have int results inside this function.

float factorial(int n) //This is the structure of a function where you have subrutines in order to make
//different tasks, in this case we have a float function with the name "factorial" and with int parameters n in order to
//have int results inside this function.

In addition, we need the #Mastery10 use of the if statement. This command allows the condition if the value of n is equal to 0 and when this condition will be true, the tasks inside of the statement will execute. In this case if the value of n is equal than 0 this will occur:

if(n==0) //#Mastery10 use of the if statement //This command allows the condition if the value of n
//is equal to 0 and when this condition will be true, the tasks inside of the statement will execute.
// In this case if the value of n is equal than 0 this will occur:
{
return 1; //return the value 1 to the function calculuate_e
}

Inside of the if condition we have a return statement. We need to return the value 1 to the function calculuate_e

return 1; //return the value 1 to the function calculuate_e

Next, we use a #Mastery11 Use of else with a conditional if: // if the condition does not achieve on the other hand you will do this:

else //#Mastery11 Use of else with a conditional if: // if the condition does not achieve on the other hand you will do this:
{

return n*factorial(n-1); //return the recursion value n!=n (n-1)! to the function calculuate_e like we did in the last WSQ6

}

Inside the else, we need to return the recursion value n!=n (n-1)! to the function calculuate_e like we did in the last WSQ6

return n*factorial(n-1); //return the recursion value n!=n (n-1)! to the function calculuate_e like we did in the last WSQ6

Furthermore, the program goes to the calculate_e function and we need a command of out data in form of text. In this text we show the authentic output of the value of e in the terminal interface #MasteryTopic04

cout<<e<<endl; //command of out data in form of text
//In this text we show the authentic output of the value of e in the terminal interface #MasteryTopic04

After that, we need this  math operation between ‘i’ and ‘1’ and stands for adding those values and saved it in int variable ‘i’

i++; //This is a math operation between 'i' and '1' and stands for adding
//those values and saved it in int variable 'i'

Next. we need a return statement. This return statement with this command you return the value of the previus operations of “calculuate_e” function inside of the variable float e in order to call it in THE MAIN FUNCTION

return e; //With this command you return the value of the previus operations of "calculuate_e" function inside of the
//variable float e in order to call it in THE MAIN FUNCTION

And i also resolved it by doing this video tutorial that i made reafirming these parts at this link :#WSQ12 Tutorial 13 16/04/17 Estimating e and WSQ12.cpp

Finally with the command ./a.out and WSQ12.cpp  and tells the terminal to run the C++ file:

eular

This code for solution will be here and in Github:

Link in Github: WSQ12.cpp

If you do not want the WSQ12.cpp there is it in here with comments. The comments are very useful to detect errors and create new things #Mastery01 #Masterytopic01 #MasteryTopic01 #MASTERY01 #MASTERYTOPIC01 :

Also in the last class I learned how to present my C++ in a better ‘readable’ way after doing it #Mastery02 #Masterytopic02 #MasteryTopic02 #MASTERY02 #MASTERYTOPIC02:

#include <iostream> //Library to call all the
//fuctions of inputs and outputs of data in languague
//C++ #MasteryTopic01

#include <cmath> //Library to call all the
//fuctions of math commands in languague
//C++ #MasteryTopic01

using namespace std; //In C++ we need a command
// that everytime goes with the instructions of input and outputs
//of data that is call std but with this command helps writing
//these std out of the main because the machine factorizes them

float factorial(int n) //This is the structure of a function where you have subrutines in order to make
//different tasks, in this case we have a float function with the name "factorial" and with int parameters n in order to
//have int results inside this function.
{
if(n==0) //#Mastery10 use of the if statement //This command allows the condition if the value of n
//is equal to 0 and when this condition will be true, the tasks inside of the statement will execute.
// In this case if the value of n is equal than 0 this will occur:
{

return 1; //return the value 1 to the function calculuate_e

}

else //#Mastery11 Use of else with a conditional if: // if the condition does not achieve on the other hand you will do this:
{

return n*factorial(n-1); //return the recursion value n!=n (n-1)! to the function calculuate_e like we did in the last WSQ6

}

}

float calculuate_e (float precision) //This is the structure of a function where you have subrutines in order to make
//different tasks, in this case we have a FLOAT function with the name "calculuate_e" and with float parameter precision
//in order to have float results inside this function.

{

float e = 1; //Declarate float variable e initialized in 1
float previuse; //Declarate float variable previuse
int i=1; //Declarate float variable i initialized in 1

do //With this command do is utilized as a loop do execute all the
//instruccions that has this loop until that does not complete that the variable abs e-previuse>precision
// will be less or equal than the numerical value of precision variable while it is increasing one in one in this variable i
//inicialized from the value 1
{
previuse=e;//Give the value of e to variable previuse
e = e + 1/(factorial(i)); //This is a math operation between 'e' and
// the value of the float function factorial with the int parameter i and stands for
//do the sum of e and the inverse operation of the factorial function with the i parameter and saved it in the float
//variable 'e', this is the operation of the infinite series thanks to the recursion #Mastery16 Use of recursion for repetitive
//algorithms
cout<<e<<endl; //command of out data in form of text
//In this text we show the authentic output of the value of e in the terminal interface #MasteryTopic04
i++; //This is a math operation between 'i' and '1' and stands for adding
//those values and saved it in int variable 'i'
} while(abs (e-previuse)>precision);

return e; //With this command you return the value of the previus operations of "calculuate_e" function inside of the
//variable float e in order to call it in THE MAIN FUNCTION

//cout<< fixed <<setprecision(precision)<<endl; //float notation for manipulator of significant figures or decimal points after
//the decimal point. Hence, for example of precision=5 then the value will be setprecision(5) and with fixed after the decimal point
//this shows for the number of decimal places that the user wants. In consequence the value of variable e wil suffer after this operation
//cout<<e<<endl;

}

int main()

{
float precision; //Declarate float variable precision

cout<<"Specify the number of decimal points of accuracy: "; //#Mastery04 command of out data in form of text
cin>>precision; //#Mastery05 This command allows enter data for inputs. In this case this enters the
//value of variable 'precision'

cout<<"The estimation of e with "<<precision<<" decimal points is e = "<<calculuate_e (precision)<<endl; //command of out data in form of text
//In this text we show the authentic output of the value entered of precision in the terminal interface #MasteryTopic04

return 0; // This command allows label the final of the function main ()
}

#WSQ11 Go Bananas 15/04/17 and WSQ11.cpp

#WSQ11 Go Bananas 15/04/17 and WSQ11.cpp

So in this fourteen week class I started with doing this WSQ11 I started reviewing in creating and calling functions in C++.#Mastery06, #Mastery07, #Mastery16 Use of recursion for repetitive algorithms, #Mastery17 When to use what type of repetition in a program, #Mastery18 Creation and use of Arrays/ Vectors in C++. Furthermore, in this stage I have all the topics of the course from 1 to 22 including #Mastery22 Matrixes and vectors because in this code I use a matrix with a dimension of 1.

What I did for this numeric program is solving the problem to the user by creating a program with writing a function called find_bananas which receives a single parameter called filename (a string) and returns a positive integer which is the number of times the word (string) “banana”  (or “BANANA” ) is found in the file. The banana can be any case (‘BaNana’ or ‘BANANA’ or ‘banana’, etc) and they can be “stuck together” like “banAnaBANANA” (that counts as two). Create your own test file (plain text) to check your work.

Hence, the resources I need it to solve this program are here:

ken bauer

Video to convert higher to lower cases from the .txt file

The following photograph shows the solution to this problem:

wsq11v1

wsq11v2wsq11v3wsq11v4a1

a2

a3a4

So at first I wrote the same structure of the program just did the same as what i did in Hello World: Second Class, Second Blog (Blog of the second class 12/01/17) and Hello World.cpp,  #WSQ01 Post Fun with Numbers 16/01/17 and WSQ1.cpp#WSQ02 Post Temperature 23/01/17 and WSQ02.cpp#WSQ03 Post Pick a Number 23/01/17 and WSQ03.cpp#WSQ04 Post Sum of Numbers 23/01/17 and WSQ04.cpp#WSQ05 Six Tutorial On To Functions 12/02/17 and WSQ05.cpp#WSQ06 Factorial Calculator 12/02/17 and WSQ06.cpp#WSQ07 Lists 03/03/17 and WSQ07.cpp, #WSQ08 Yo soy 196 11/03/17 and WSQ08.cpp#WSQ09 Multipart Data and Files 10/03/17 and WSQ09.cpp and #WSQ10 Babylonian Method 21/03/17 and WSQ10.cpp where i explained the application of the #MasteryTopic01 that it is for comments that could be very useful when debugging and #MasteryTopic04 that is basic output for data. Also I did some other mastery topics.

What i first put in the code was the library to call all the fuctions of inputs and outputs of data in languague C++ #MasteryTopic01

#include <iostream> //Library to call all the
//fuctions of inputs and outputs of data in languague
//C++ #MasteryTopic01

Next, we use a Library to call all the fuctions of reading AND writing files in languague C++ #MasteryTopic21

#include <fstream> //Library to call all the
//fuctions of reading AND writing files in languague
//C++ #MasteryTopic21

Furthermore, in C++ we need a command that everytime goes with the instructions of input and outputs of data that is call std but with this command helps writing these std out of the main because the machine factorizes them.

using namespace std; //In C++ we need a command
// that everytime goes with the instructions of input and outputs
//of data that is call std but with this command helps writing
//these std out of the main because the machine factorizes them

In addition, we need to begin our program and declarate string varible filename and initialized it to “banana.txt” #Mastery19 and #Mastery20

int main ()
{

string filename = "banana.txt";
//Declarate string varible filename and initialized it to "banana.txt" #Mastery19 and #Mastery20

Next we need to Declarate int variable cfinal

int cfinal; //Declarate int variable cfinal

Then, we need to use THIS ASSIGNATION HELPS TO CALL THE FUNCTION OF “find_bananas” TO MAKE THE TASK OF COUNT THE NUMBER OF TIMES THAT THE WORD banana is found WITH THE HELP OF THE VARIABLE int ‘cfinal’ with the parameter filename.c_str() IN ORDER to convert string to char as a parameter #Mastery06 and #Mastery07

cfinal=find_bananas(filename.c_str()); //THIS ASSIGNATION HELPS TO CALL THE FUNCTION OF "find_bananas" TO MAKE THE TASK OF
//COUNT THE NUMBER OF TIMES THAT THE WORD banana is found WITH THE HELP OF THE VARIABLE int 'cfinal' with the parameter filename.c_str()
//IN ORDER to convert string to char as a parameter #Mastery06 and #Mastery07

Moreover, This is the structure of a function where you have subrutines in order to make different tasks, in this case we have an int function with the name “find_bananas” and with const char parameter filename that has the value of “banana.txt” in order to have int results inside this function.

int find_bananas (const char *filename) //This is the structure of a function where you have subrutines in order to make
//different tasks, in this case we have an int function with the name "find_bananas" and with const char parameter filename
// that has the value of "banana.txt" in order to
//have int results inside this function.

Furthermore, we have a text name of the file .txt “banana.txt”

cout<<filename<<endl; //text name of the file .txt "banana.txt"

After that, we need to declarate a ifstream variable called “file” in order to write or read #Mastery21 Reading and writing of text files. Therefore, this is a variable called file where you also make the function of giving the value of filename to file that in this case is banana.txt

ifstream file(filename); ///Declarate a ifstream variable called "file" in order to write or read #Mastery21 Reading and writing of text files
//Therefore, this is a variable called file where you also make the function of giving the value of filename to file that in this case
//is banana.txt

Next, we need a command of data in form of text space

cout<<endl; //command of data in form of text space

Moreover, we need to declarate int variable counteralllines initialized in 0 in order to count all the words of banana in banana.txt

int counteralllines=0; //Declarate int variable counteralllines initialized in 0 in order to count all the words of banana in banana.txt

Next, Declarate string variable lines in order to save all the characters of the banana.txt file

string lines; //Declarate string variable lines in order to save all the characters of the banana.txt file

Then we use a #Mastery10 use of the if statement. This command allows the condition if the file is open and when this condition will be true, the tasks inside of the statement will execute. In this case if the value file is open this will occur:

if(file.is_open()) //#Mastery10 use of the if statement //This command allows the condition if the file is open and when this
//condition will be true, the tasks inside of the statement will execute. In this case if the value file is open
//this will occur:

After that we need a loop. With this command while is utilized as a loop WHILE execute all the instruccions that has this loop until that does not complete that we get all the characters of lines in the file

while(getline(file,lines)) //With this command while is utilized as a loop WHILE execute all the
//instruccions that has this loop until that does not complete that we get all the characters of lines in the file
{

counteralllines = counteralllines + linebanana(lines); //This is a math operation between 'counteralllines' and
// the value of the int function linebanana with the string parameter 'lines' and stands for
//do the sum between those values and saved it in the int variable 'counteralllines'

cout<<"COUNTER THIS LINE= "<<counteralllines<<endl; //In
//this text we show the authentic output of the value entered of counteralllines in the terminal interface #Mastery20 Validated user
//input (ensure correct / expected data entry) I used it to tell me all the words banana appeared

}

Next, This is a math operation between ‘counteralllines’ and the value of the int function linebanana with the string parameter ‘lines’ and stands for do the sum between those values and saved it in the int variable ‘counteralllines’

counteralllines = counteralllines + linebanana(lines); //This is a math operation between 'counteralllines' and
// the value of the int function linebanana with the string parameter 'lines' and stands for
//do the sum between those values and saved it in the int variable 'counteralllines'

Next, this function escapes to another function and this is the structure of a function where you have subrutines in order to make different tasks, in this case we have an int function with the name “linebanana” and with string parameter lines that has just the value of all the words bananas in string of the file in order to have int results inside this function.

int linebanana (string lines) //This is the structure of a function where you have subrutines in order to make
//different tasks, in this case we have an int function with the name "linebanana" and with string parameter lines
// that has just the value of all the words bananas in string of the file in order to have int results inside this function.

Declarate int variable i initialized in 0.

int i=0; //Declarate int variable i initialized in 0.

int counterbananaeachline=0; //Declarate int variable counterbananaeachline initialized in 0.

int counterbananaeachline=0; //Declarate int variable counterbananaeachline initialized in 0.

With this command for is utilized as a loop FOR execute all the instruccions that has this loop until that does not complete that the variable j will be less than the numerical value of the lines variable while it is increasing one in one in this variable i inicialized from the value 0 #Mastery22 Matrixes and vectors because in this code I use a matrix with a dimension of 1.

for(int j=0; j		<lines.length(); j++) //With this command for is utilized as a loop FOR execute all the
//instruccions that has this loop until that does not complete that the variable j
// will be less than the numerical value of the lines variable while it is increasing one in one in this variable i
//inicialized from the value 0 #Mastery22 Matrixes and vectors because in this code I use a matrix with a dimension of 1.

Next, This is a string operation between ‘lines’ and ‘lines[j where this j is the space of each string value per each line bananas from line 1 to the last line, I am using the #Mastery18 Creation and use of Arrays/Vectors in C++]’ and the similar functions like vectors in#Mastery22 Matrixes and vectors, stands for transform all the character of the banana.txt file to lower case between those values and saved it in string variable ‘lines’. Hence, by doing this all the characters from the file banana.txt will be in lower cases in order to count next just the condition of “banana” all in lower cases.

lines[j]=tolower(lines[j]); //This is a string operation between 'lines' and
//'lines[j where this j is the space of each string value per each line bananas from line 1 to the last line, I am
//using the #Mastery18 Creation and use of Arrays/Vectors in C++]' and stands for transform all the character of the banana.txt file
//to lower case between those values and saved it in string variable 'lines'. Hence, by doing this all the characters from the file
//banana.txt will be in lower cases in order to count next just the condition of "banana" all in lower cases.

After that, we need this command while is utilized as a loop WHILE to execute all the instruccions that has this loop until that INSIDE of this loop has a break statement to break this infinite loop.

while (1) //With this command while is utilized as a loop WHILE execute all the
//instruccions that has this loop until that INSIDE of this loop has a break statement to break this infinite loop

Next, we need to Declarate int variable foundtop. Then we have an assignation operation between ‘foundtop’ and ‘the string value lines’ and stands for find the numeric position everytime when the word “banana” appears inside the variable lines and save this new value of the int position to int variable ‘foundtop’ (position 0 is the begining of the file .txt)

int foundtop = lines.find("banana", i); //Declarate int variable foundtop. Then we have an assignation operation between
//'foundtop' and 'the string value lines' and stands for find the numeric position everytime when the word "banana" appears
//inside the variable lines and save this new value of the int position to int variable 'foundtop' (position 0 is the begining
// of the file .txt)

Next, we need a math operation between ‘i’ and ‘foundtop’ and stands for adding those values and saved it in int variable ‘i’

i=foundtop+1; //This is a math operation between 'i' and 'foundtop' and stands for adding
//those values and saved it in int variable 'i'

Then, we need a #Mastery10 use of the if statement //This command allows the condition if the value of foundtop NOOT BE equal to -1 and when this condition will be true, the tasks inside of the statement will execute. In this case the if executes because the variable foundtop is not finishing in counting all the characters of each line and has the value different of -1. In this case if the value is not equal than -1 this will occur:

if(foundtop!=-1) //#Mastery10 use of the if statement //This command allows the condition if the value of foundtop
//NOOT BE equal to -1 and when this condition will be true, the tasks inside of the statement will execute.
//In this case the if executes because the variable foundtop is not finishing in counting all the characters of each line
//and has the value different of -1
// In this case if the value is not equal than -1 this will occur:

Then, This is a math operation between ‘counterbananaeachline’ and ‘1’ and stands for adding those values and saved it in int variable ‘counterbananaeachline’

counterbananaeachline++; //This is a math operation between 'counterbananaeachline' and '1' and stands for adding
//those values and saved it in int variable 'counterbananaeachline'

After that, we need a #Mastery11 Use of else with a conditional if: // if the condition does not achieve on the other hand you will do this:

else //#Mastery11 Use of else with a conditional if: // if the condition does not achieve on the other hand you will do this:
{

cout<<"COUNTER= "<<counterbananaeachline<<endl; //In
//this text we show the authentic output of the value entered of counteralllines in the terminal interface #Mastery20 Validated user
//input (ensure correct / expected data entry) I used it to tell me all the words banana appeared in each line

break; //This command helps to end the infinite while (1) and allow the program to go back to the next function

}

Next, in this text we show the authentic output of the value entered of counteralllines in the terminal interface #Mastery20 Validated user input (ensure correct / expected data entry) I used it to tell me all the words banana appeared in each line

cout<<"COUNTER= "<<counterbananaeachline<<endl; //In
//this text we show the authentic output of the value entered of counteralllines in the terminal interface #Mastery20 Validated user
//input (ensure correct / expected data entry) I used it to tell me all the words banana appeared in each line

After that, this command helps to end the infinite while (1) and allow the program to go back to the next function.

break; //This command helps to end the infinite while (1) and allow the program to go back to the next function

Next, With this command you return the value of the previus operations of “linebanana” function inside of the variable int counterbananaeachline in order to call it in THE FIND_BANANA FUNCTION

return counterbananaeachline; //With this command you return the value of the previus operations of "linebanana" function inside of the
//variable int counterbananaeachline in order to call it in THE MAIN FUNCTION

Then, the program goes to the main function and in this text we show the authentic output of the value entered of counteralllines in the terminal interface #Mastery20 Validated user input (ensure correct / expected data entry) I used it to tell me all the words banana appeared

cout<<"COUNTER THIS LINE= "<<counteralllines<<endl; //In
//this text we show the authentic output of the value entered of counteralllines in the terminal interface #Mastery20 Validated user
//input (ensure correct / expected data entry) I used it to tell me all the words banana appeared

After that, we need this command you return the value of the previus operations of “find_bananas” function inside of the variable int counteralllines in order to call it in THE MAIN FUNCTION

return counteralllines; //With this command you return the value of the previus operations of "find_bananas" function inside of the
//variable int counteralllines in order to call it in THE MAIN FUNCTION

Finally, the program goes back to the main function and in this text we show the authentic output of the value entered of cfinal in the terminal interface #Mastery20 Validated user input (ensure correct / expected data entry)

cout<<"TIMES THE WORD banana FOUND="<<cfinal<<endl; //In
//this text we show the authentic output of the value entered of cfinal in the terminal interface #Mastery20 Validated user
//input (ensure correct / expected data entry)

Finally we have a return statement. This command allows label the final of the function main ()

return 0; // This command allows label the final of the function main ()

And i also resolved it by doing this video tutorial that i made reafirming these parts at this link :#WSQ11 Tutorial 12 Go Bananas 15/04/17 and WSQ11.cpp

Finally with the command ./a.out and WSQ11.cpp  and tells the terminal to run the C++ file:

vvvv

This code for solution will be here and in Github:

Link in Github: WSQ11.cpp

If you do not want the WSQ11.cpp there is it in here with comments. The comments are very useful to detect errors and create new things #Mastery01 #Masterytopic01 #MasteryTopic01 #MASTERY01 #MASTERYTOPIC01 :

Also in the last class I learned how to present my C++ in a better ‘readable’ way after doing it #Mastery02 #Masterytopic02 #MasteryTopic02 #MASTERY02 #MASTERYTOPIC02:

#include <iostream> //Library to call all the
//fuctions of inputs and outputs of data in languague
//C++ #MasteryTopic01

#include <fstream> //Library to call all the
//fuctions of reading AND writing files in languague
//C++ #MasteryTopic21

using namespace std; //In C++ we need a command
// that everytime goes with the instructions of input and outputs
//of data that is call std but with this command helps writing
//these std out of the main because the machine factorizes them

int linebanana (string lines) //This is the structure of a function where you have subrutines in order to make
//different tasks, in this case we have an int function with the name "linebanana" and with string parameter lines
// that has just the value of all the words bananas in string of the file in order to have int results inside this function.
{

int i=0; //Declarate int variable i initialized in 0.
int counterbananaeachline=0; //Declarate int variable counterbananaeachline initialized in 0.

for(int j=0; j<lines.length(); j++) //With this command for is utilized as a loop FOR execute all the
//instruccions that has this loop until that does not complete that the variable j
// will be less than the numerical value of the lines variable while it is increasing one in one in this variable i
//inicialized from the value 0 #Mastery22 Matrixes and vectors because in this code I use a matrix with a dimension of 1.
{

lines[j]=tolower(lines[j]); //This is a string operation between 'lines' and
//'lines[j where this j is the space of each string value per each line bananas from line 1 to the last line, I am
//using the #Mastery18 Creation and use of Arrays/Vectors in C++]' and stands for transform all the character of the banana.txt file
//to lower case between those values and saved it in string variable 'lines'. Hence, by doing this all the characters from the file
//banana.txt will be in lower cases in order to count next just the condition of "banana" all in lower cases.

}
cout<<lines<<endl; //In
//this text we show the authentic output of the value entered of counteralllines in the terminal interface #Mastery20 Validated user
//input (ensure correct / expected data entry) I used it to tell me all the words banana appeared

while (1) //With this command while is utilized as a loop WHILE execute all the
//instruccions that has this loop until that INSIDE of this loop has a break statement to break this infinite loop
{
int foundtop = lines.find("banana", i); //Declarate int variable foundtop. Then we have an assignation operation between
//'foundtop' and 'the string value lines' and stands for find the numeric position everytime when the word "banana" appears
//inside the variable lines and save this new value of the int position to int variable 'foundtop' (position 0 is the begining
// of the file .txt)

i=foundtop+1; //This is a math operation between 'i' and 'foundtop' and stands for adding
//those values and saved it in int variable 'i'

if(foundtop!=-1) //#Mastery10 use of the if statement //This command allows the condition if the value of foundtop
//NOOT BE equal to -1 and when this condition will be true, the tasks inside of the statement will execute.
//In this case the if executes because the variable foundtop is not finishing in counting all the characters of each line
//and has the value different of -1
// In this case if the value is not equal than -1 this will occur:
{

counterbananaeachline++; //This is a math operation between 'counterbananaeachline' and '1' and stands for adding
//those values and saved it in int variable 'counterbananaeachline'

}

else //#Mastery11 Use of else with a conditional if: // if the condition does not achieve on the other hand you will do this:
{

cout<<"COUNTER= "<<counterbananaeachline<<endl; //In
//this text we show the authentic output of the value entered of counteralllines in the terminal interface #Mastery20 Validated user
//input (ensure correct / expected data entry) I used it to tell me all the words banana appeared in each line

break; //This command helps to end the infinite while (1) and allow the program to go back to the next function

}

} //END OF WHILE

return counterbananaeachline; //With this command you return the value of the previus operations of "linebanana" function inside of the
//variable int counterbananaeachline in order to call it in THE MAIN FUNCTION

}

int find_bananas (const char *filename) //This is the structure of a function where you have subrutines in order to make
//different tasks, in this case we have an int function with the name "find_bananas" and with const char parameter filename
// that has the value of "banana.txt" in order to
//have int results inside this function.
{
cout<<filename<<endl; //text name of the file .txt "banana.txt"

ifstream file(filename); ///Declarate a ifstream variable called "file" in order to write or read #Mastery21 Reading and writing of text files
//Therefore, this is a variable called file where you also make the function of giving the value of filename to file that in this case
//is banana.txt

cout<<endl; //command of data in form of text space

int counteralllines=0; //Declarate int variable counteralllines initialized in 0 in order to count all the words of banana in banana.txt

string lines; //Declarate string variable lines in order to save all the characters of the banana.txt file

if(file.is_open()) //#Mastery10 use of the if statement //This command allows the condition if the file is open and when this
//condition will be true, the tasks inside of the statement will execute. In this case if the value file is open
//this will occur:
{
while(getline(file,lines)) //With this command while is utilized as a loop WHILE execute all the
//instruccions that has this loop until that does not complete that we get all the characters of lines in the file
{

counteralllines = counteralllines + linebanana(lines); //This is a math operation between 'counteralllines' and
// the value of the int function linebanana with the string parameter 'lines' and stands for
//do the sum between those values and saved it in the int variable 'counteralllines'

cout<<"COUNTER THIS LINE= "<<counteralllines<<endl; //In
//this text we show the authentic output of the value entered of counteralllines in the terminal interface #Mastery20 Validated user
//input (ensure correct / expected data entry) I used it to tell me all the words banana appeared

}

} //END OF IF

return counteralllines; //With this command you return the value of the previus operations of "find_bananas" function inside of the
//variable int counteralllines in order to call it in THE MAIN FUNCTION

}

int main ()
{

string filename = "banana.txt"; //Declarate string varible filename and initialized it to "banana.txt" #Mastery19 and #Mastery20

int cfinal; //Declarate int variable cfinal

cfinal=find_bananas(filename.c_str()); //THIS ASSIGNATION HELPS TO CALL THE FUNCTION OF "find_bananas" TO MAKE THE TASK OF
//COUNT THE NUMBER OF TIMES THAT THE WORD banana is found WITH THE HELP OF THE VARIABLE int 'cfinal' with the parameter filename.c_str()
//IN ORDER to convert string to char as a parameter #Mastery06 and #Mastery07

cout<<"TIMES THE WORD banana FOUND="<<cfinal<<endl; //In
//this text we show the authentic output of the value entered of cfinal in the terminal interface #Mastery20 Validated user
//input (ensure correct / expected data entry)

return 0; // This command allows label the final of the function main ()

}

#WSQ10 Babylonian Method 21/03/17 and WSQ10.cpp

#WSQ10 Babylonian Method 21/03/17 and WSQ10.cpp

So in this twelve week class I started with doing this WSQ10 I started reviewing in creating and calling functions in C++.#Mastery06, #Mastery07, #Mastery16 Use of recursion for repetitive algorithms, #Mastery17 When to use what type of repetition in a program, #Mastery18 Creation and use of Arrays/ Vectors in C++. Futhermore, in this stage I have all the topics of the course from 1 to 20.

What I did for this numeric program is solving the problem to the user by creating a program with writing a function to calculate the square root of a number using the Babylonian method. You can search for that method, it will be easy to find. Hence, you can have it here in the survey that we did last week:

bab

Then, we need that this the function should receive a number and return floating point number. Obviously you should test your function, so create a main program that asks the user a value, calculates the square root and displays that.

Hence, the resources I need it to solve this program are here:

ken bauer

Similar code provided by Xochitl96

The following photograph shows the solution to this problem:

ba1

ba2

ba3

So at first I wrote the same structure of the program just did the same as what i did in Hello World: Second Class, Second Blog (Blog of the second class 12/01/17) and Hello World.cpp,  #WSQ01 Post Fun with Numbers 16/01/17 and WSQ1.cpp#WSQ02 Post Temperature 23/01/17 and WSQ02.cpp#WSQ03 Post Pick a Number 23/01/17 and WSQ03.cpp#WSQ04 Post Sum of Numbers 23/01/17 and WSQ04.cpp#WSQ05 Six Tutorial On To Functions 12/02/17 and WSQ05.cpp#WSQ06 Factorial Calculator 12/02/17 and WSQ06.cpp#WSQ07 Lists 03/03/17 and WSQ07.cpp, #WSQ08 Yo soy 196 11/03/17 and WSQ08.cpp and #WSQ09 Multipart Data and Files 10/03/17 and WSQ09.cpp where i explained the application of the #MasteryTopic01 that it is for comments that could be very useful when debugging and #MasteryTopic04 that is basic output for data. Also I did some other mastery topics.

What i first put in the code was the library to call all the fuctions <iostream> of inputs and outputs of data in languague C++ #MasteryTopic06 Calling Functions and #MasteryTopic08 Importing and using libraries.

#include <iostream> //Library to call all the
//fuctions of inputs and outputs of data in languague
//C++ #MasteryTopic01

Next, we need to use a Library to call all the functions of MATH of data in languague C++ #MasteryTopic01

#include <cmath> //Library to call all the
//fuctions of MATH of data in languague
//C++ #MasteryTopic01

After that, in C++ we need a command that everytime goes with the instructions of input and outputs of data that is call std but with this command helps writing these std out of the main because the machine factorizes them

using namespace std; //In C++ we need a command
// that everytime goes with the instructions of input and outputs
//of data that is call std but with this command helps writing
//these std out of the main because the machine factorizes them

Then we have the Begin of the program

int main() //Begin of the program

Next, we need the #Mastery04 command of out data in form of numeric value. With this command we give the value 16.23654 to square_root function.

cout<<square_root(16.23654); //#Mastery04 command of out data in form of numeric value. with this command we give the value 16.23654 to
//square_root function.

After that, the main program escapes from the main function, goes to a new function and we need to use this structure of a function where you have subrutines in order to make different tasks, in this case we have a FLOAT function with the name “square_root” and with float parameter x in order to have float results inside this function.

float square_root(float x) //This is the structure of a function where you have subrutines in order to make
//different tasks, in this case we have a FLOAT function with the name "square_root" and with float parameter x
//in order to have float results inside this function.

Next, we need to Declarate decimal float variable resp

float resp; //Declarate decimal float variable resp

After that, we need to declarate decimal float variable a initialized in 0

float a=0; //Declarate decimal float variable a initialized in 0

After that, we need to use this math operation between ‘resp’ and ‘x’ and stands for do the division between those values and saved it in float variable ‘resp’

resp=x/2; //This is a math operation between 'resp' and 'x' and stands for do the division between
//those values and saved it in float variable 'resp'

Next we use the #Mastery13 Use of loops with “while” and “do while”. This command is the loop do-while that allows you in doing at least once of the instruccions in this loop and while this case of abs(a-resp) don´t be higher than 0.0001, it will execute forever every instructions of the loop label in this loop.

do
{
cout<<resp<<endl; //command of out data in form of text
//In this text we show the authentic output of the value of resp in the terminal interface #MasteryTopic04
a=resp; // This command allows giving the value of the declared decimal variable 'resp' to
//the declared decimal variable 'a'.
resp=(resp+x/resp)/2;//This is a math operation between 'resp' and 'x' and stands for do the babylonian method between
//those values and saved it in float variable 'resp'


}while( abs(a-resp) > 0.0001);

After that, we need a command of out data in form of text. In this text we show the authentic output of the value of resp in the terminal interface #MasteryTopic04

cout<<resp<<endl; //command of out data in form of text
//In this text we show the authentic output of the value of resp in the terminal interface #MasteryTopic04

Next, we need this command allows giving the value of the declared decimal variable ‘resp’ to the declared decimal variable ‘a’.

a=resp; // This command allows giving the value of the declared decimal variable 'resp' to
//the declared decimal variable 'a'.

Furthermore, this is a math operation between ‘resp’ and ‘x’ and stands for do the babylonian method between those values and saved it in float variable ‘resp’

resp=(resp+x/resp)/2;//This is a math operation between 'resp' and 'x' and stands for do the babylonian method between
//those values and saved it in float variable 'resp'

Moreover, this command is the loop do-while that allows in doing at least 1 time of the instructions written in this loop and while in this case The value of abs(a-resp) don’t be higher to the value of 0.0001, it will execute forever all of the instrucccions lable in this loop.

while( abs(a-resp) > 0.0001); // This command is the loop do-while that allows in doing
//at least 1 time of the instructions written in this loop and while in this case
//The value of abs(a-resp) don't be higher to the value of 0.0001, it will execute forever
//all of the instrucccions lable in this loop.

Finally we have a return statement. With this command you return the value of the previus operations of “square_root” function inside of the in order to call it in THE MAIN FUNCTION.

return resp; //With this command you return the value of the previus operations of "square_root" function inside of the
//in order to call it in THE MAIN FUNCTION.

And i also resolved it by doing this video tutorial that i made reafirming these parts at this link :#WSQ10 Tutorial 11 Babylonian method 21/03/17 and WSQ10.cpp

Finally with the command ./a.out and WSQ10.cpp  and tells the terminal to run the C++ file:

444

This code for solution will be here and in Github:

Link in Github:WSQ10.cpp

If you do not want the WSQ10.cpp there is it in here with comments. The comments are very useful to detect errors and create new things #Mastery01 #Masterytopic01 #MasteryTopic01 #MASTERY01 #MASTERYTOPIC01 :

Also in the last class I learned how to present my C++ in a better ‘readable’ way after doing it #Mastery02 #Masterytopic02 #MasteryTopic02 #MASTERY02 #MASTERYTOPIC02:

#include <iostream> //Library to call all the
//fuctions of inputs and outputs of data in languague
//C++ #MasteryTopic01

#include <cmath> //Library to call all the
//fuctions of MATH of data in languague
//C++ #MasteryTopic01

using namespace std; //In C++ we need a command
// that everytime goes with the instructions of input and outputs
//of data that is call std but with this command helps writing
//these std out of the main because the machine factorizes them


float square_root(float x) //This is the structure of a function where you have subrutines in order to make
//different tasks, in this case we have a FLOAT function with the name "square_root" and with float parameter x
//in order to have float results inside this function.

{

float resp; //Declarate decimal float variable resp
float a=0; //Declarate decimal float variable a initialized in 0

resp=x/2; //This is a math operation between 'resp' and 'x' and stands for do the division between
//those values and saved it in float variable 'resp'

//Next we use the #Mastery13 Use of loops with "while" and "do while"
// This command is the loop do-while that allows you in doing at least once of
//the instruccions in this loop and while this case of
//abs(a-resp) don´t be higher than 0.0001, it will execute forever every instructions of the loop
//label in this loop.
do
{
cout<<resp<<endl; //command of out data in form of text
//In this text we show the authentic output of the value of resp in the terminal interface #MasteryTopic04
a=resp; // This command allows giving the value of the declared decimal variable 'resp' to
//the declared decimal variable 'a'.
resp=(resp+x/resp)/2;//This is a math operation between 'resp' and 'x' and stands for do the babylonian method between
//those values and saved it in float variable 'resp'


}while( abs(a-resp) > 0.0001); // This command is the loop do-while that allows in doing
//at least 1 time of the instructions written in this loop and while in this case
//The value of abs(a-resp) don't be higher to the value of 0.0001, it will execute forever
//all of the instrucccions lable in this loop.

return resp; //With this command you return the value of the previus operations of "square_root" function inside of the
//in order to call it in THE MAIN FUNCTION.

}



int main() //Begin of the program
{
cout<<square_root(16.23654); //#Mastery04 command of out data in form of numeric value. with this command we give the value 16.23654 to
//square_root function.

}

Post of the weeks #6,7,8,9 and 10 what things I learned in these weeks ? And Index of Mastery Topics

Post of the weeks #6,7,8,9 and 10 what things I learned in these weeks ? And Index of Mastery Topics

Picture of author

First let me tell you that  I learn and achieved all transversal topics and you can see it in the following link: Post of the week #3 what things i learned in this week #3 ? And Index of Mastery Topics

I also explain my project and formed a small team that corresponds of completing this ability to create C++ project in IDE and run inside the IDE and can be explained in my post My Project For the Course TC1017 and Expo Ing. Let’s code!

Futhermore, I am going to present the report of all the Mastery Topics achieved in this week:

  1. #Mastery01 Use of comments, achieved in: Post of the week #2 what things i learned in this week #2 ?
  2. #Mastery02 C++ Good Style coding conventions, achieved in: Post of the week #2 what things i learned in this week #2 ?
  3. #Mastery03 Basic types and their use, achieved in: Post of the week #2 what things i learned in this week #2 ?
  4. #Mastery04 Basic output (print), achieved in: Post of the week #2 what things i learned in this week #2 ?
  5. #Mastery05 Basic user input (text based), achieved in: Post of the week #2 what things i learned in this week #2 ?
  6. #Mastery06 Calling functions, achieved in: #Quiz03. Also here:#WSQ08 Yo soy 196 11/03/17 and WSQ08.cpp
  7. #Mastery07 Creating functions, achieved in: #Quiz03. Also here: #WSQ08 Yo soy 196 11/03/17 and WSQ08.cpp
  8. #Mastery08 Importing and using libraries, achieved in: Post of the week #1 what things i learned in this week #1 ? Also in #WSQ08 Yo soy 196 11/03/17 and WSQ08.cpp
  9. #Mastery09 Creating and using your own libraries (program with multiple files), achieved in: #Quiz03. Furthermore, also in here: #WSQ08 Yo soy 196 11/03/17 and WSQ08.cpp
  10. #Mastery10 Use of the conditional “if”, achieved in: #WSQ02 Post Temperature 23/01/17 and WSQ02.cpp
  11. #Mastery11 Use of “else” with a conditional if, achieved in: #WSQ02 Post Temperature 23/01/17 and WSQ02.cpp
  12. #Mastery12 Nesting of conditional statements (ifs inside ifs): #WSQ02 Post Temperature 23/01/17 and WSQ02.cpp
  13. #Mastery13 Use of loops with “while” and “do while”, achieved in: #WSQ03 Post Pick a Number 23/01/17 and WSQ03.cpp
  14. #Mastery14 Use of loops with “for”, achieved in: #WSQ04 Post Sum of Numbers 23/01/17 and WSQ04.cpp
  15. #Mastery15 Nested loops, achieved in:#WSQ08 Yo soy 196 11/03/17 and WSQ08.cpp

#WSQ08 Yo soy 196 11/03/17 and WSQ08.cpp

#WSQ08 Yo soy 196 11/03/17 and WSQ08.cpp

PICTURE OF ACTOR

So in this nine week class I started with doing this WSQ09. I started reviewing in creating and calling functions in C++.#Mastery06, #Mastery07, #Mastery16 Use of recursion for repetitive algorithms, #Mastery17 When to use what type of repetition in a program, #Mastery18 Creation and use of Arrays/ Vectors in C++. Futhermore, in this WSQ assignment we have mostly all the topics of the course from 1 to 20.

What I did for this numeric program is solving the problem to the user by creating a program that asks the user for two pieces of data:

  • The lower bound of the sequence
  • The upper bound of the sequence
Then you check the values from the lower bound (inclusive) to the upper bound (inclusive) and make a report of them. During the analysis of each number, if a Lychrel number is found it should be reported immediately with something like “Found a Lychrel number: 196”
The report must show:
  • The range of numbers analysed (lower to upper bound)
  • The number of natural palindromes (no addition to inverse needed)
  • The number of non-Lycherels encountered (become palindromes)
  • The number of Lycherel number candidates (that did not converge to palindrome)

Since you will not be able to prove that a number is Lycherel (since you cannot computer forever to check), our definition for a Lycherel candidate will be if a number does not converge after 30 iterations of applying the addition to the inverse.

To get this working well, you will need support for Big Integers. So I need to use that library that my teacher  ken bauer has given to me, here you go:

This link is for Library of Big Integer provided by ken bauer

Hence, the resources I need it to solve this program are here:

ken bauer

Similar code provided for Gonzalomata22

C++ – How To Reverse A String

Yo soy 196 from Ken bauer

The following photograph shows the solution to this problem:

wsq8v2

wsq8v3

wsq8v4

wsq8v5

wsq8v6

wsq8v7

wsq8v8

Picture of author

So at first I wrote the same structure of the program just did the same as what i did in Hello World: Second Class, Second Blog (Blog of the second class 12/01/17) and Hello World.cpp,  #WSQ01 Post Fun with Numbers 16/01/17 and WSQ1.cpp#WSQ02 Post Temperature 23/01/17 and WSQ02.cpp#WSQ03 Post Pick a Number 23/01/17 and WSQ03.cpp#WSQ04 Post Sum of Numbers 23/01/17 and WSQ04.cpp#WSQ05 Six Tutorial On To Functions 12/02/17 and WSQ05.cpp#WSQ06 Factorial Calculator 12/02/17 and WSQ06.cpp#WSQ07 Lists 03/03/17 and WSQ07.cpp and #WSQ09 Multipart Data and Files 10/03/17 and WSQ09.cpp where i explained the application of the #MasteryTopic01 that it is for comments that could be very useful when debugging and #MasteryTopic04 that is basic output for data. Also I did some other mastery topics.

This WSQ8 Yo soy 196 has the mastery topics from 1 to 20 which I am going to explain in the code. We have the #MasteryTopic 9 creation and using your own libraries (program with multiple files) that would be the library for using new big intergers and we need to use the quoutes “” in the program to include it. Furthermore, we have the #MasteryTopic20 Validated user input (ensure correct / expected data entry ) when we show to the user the numbers as a report.

What i first put in the code was the library to call all the fuctions <iostream> of inputs and outputs of data in languague C++ #MasteryTopic06 Calling Functions and #MasteryTopic08 Importing and using libraries.


#include <iostream>//Library to call all the
//fuctions of inputs and outputs of data in languague
//C++ #MasteryTopic01

Next, I need the Library to call all the fuctions of strings of data in languague
C++ #MasteryTopic19 Use of strings.


#include <string>//Library to call all the
//fuctions of strings of data in languague
//C++ #MasteryTopic19

Next, In C++ we need a command that everytime goes with the instructions of input and outputs of data that is call std but with this command helps writing these std out of the main because the machine factorizes them


using namespace std;//In C++ we need a command
// that everytime goes with the instructions of input and outputs
//of data that is call std but with this command helps writing
//these std out of the main because the machine factorizes them

Next, we need a Library to call all the fuctions big numbers of data and convert numbers to strings and viceversa in languague C++ #MasteryTopic01 and #MasteryTopic09 Creating and using your own libraries (program with multiple files).


#include "BigIntegerLibrary.hh" //Library to call all the
//fuctions big numbers of data and convert numbers to strings and viceversa in languague
//C++ #MasteryTopic01 and #MasteryTopic09 Creating and using your own libraries (program with multiple files)

Then, you declarate integers variables lower for the lower bound,higher for the upper bound, counterpalindrome initialized in 0 for being the counter of how many natural palindromes are,becomepalindrome initialized in 0 for being the counter of how many non-lychrels that could become palindrome with the reverse are Lychrelcounter initialized in 0 for being the counter of how many Lychrel candidates are.


int lower, higher, counterpalindrome = 0, becomepalindrome = 0, Lychrelcounter = 0; //Declarate integers variables lower for the lower
 //bound,higher for the upper bound, counterpalindrome initialized in 0 for being the counter of how many natural palindromes are,
 //becomepalindrome initialized in 0 for being the counter of how many non-lychrels that could become palindrome with the reverse are,
 //Lychrelcounter initialized in 0 for being the counter of how many Lychrel candidates are.

After that, I need to declarate a BigInteger candidate. Declarate BigInteger variable ‘candidate’ with a huge value

BigInteger candidate; //Declarate BigInteger variable 'candidate' with a huge value

Next, we have command of out data in form of text. This is for tell the user to give us the lower bound of the sequence.


  cout << "Give me the lower bound of numbers to consider:"; //command of out data in form of text

Then, we need to use an input command. This command allows enter data for inputs. In this case this enters the value of variable ‘lower’


  cin >> lower;// This command allows enter data for inputs. In this case this enters the
//value of variable 'lower'

Next, we have a command of out data in form of text. This is to tell the user to give the upper bound of numbers to consider.

cout << "Give me the upper bound of numbers to consider:"; //command of out data in form of text

Then, we need a command of input. This command allows enter data for inputs. In this case this enters the value of variable ‘higher’


 cin >> higher;// This command allows enter data for inputs. In this case this enters the
//value of variable 'higher'

Next, we need a command of out data in form of text and text spaces


  cout<<endl<<"Calculating whether each value is one of: palindrome, non-lychrel or Lychrel candidate"<<endl<<endl;
//command of out data in form of text and text spaces

Next, we need to use a loop statement. With this command for is utilized as a loop FOR execute all the instruccions that has this loop until that does not complete that the variable i will be less or equal than the variable higher while it is increasing one in one in this variable i inicialized from the value of the variable lower


 for(int i=lower; i<=higher; i++) //With this command for is utilized as a loop FOR execute all the
 //instruccions that has this loop until that does not complete that the variable i
 // will be less or equal than the variable higher while it is increasing one in one in this variable i
 //inicialized from the value of the variable lower

After that, we use the #Mastery10 use of the if statement. This command allows the condition if the value of the bool function ispalindrome with the parameter the value of i is true and when this condition will be true, the tasks inside of the statement will execute. In this case if the value is true this will occur:


if(ispalindrome(i) == true) //#Mastery10 use of the if statement. This command allows the condition if the value of
 //the bool function ispalindrome with the parameter the value of i is true and when this condition will be true, the tasks
 //inside of the statement will execute.
 // In this case if the value is true this will occur:

Then, the program escapes from the main function to the bool function in order to make the task of the total value of the numbers with the help of the string variable converted to a char variable. This is the structure of a function where you have subrutines in order to make different tasks, in this case we have a bool function with the name “ispalindrome” and with Biginteger parameter n in order to have bool results inside this function that are false (0) or true (1).

bool ispalindrome(BigInteger n) //This is the structure of a function where you have subrutines in order to make
//different tasks, in this case we have a bool function with the name "ispalindrome" and with Biginteger parameter n in order to
//have bool results inside this function that are false (0) or true (1).

Next, we  need to Declarate a string variable x. Then we have an assignation operation between ‘n’ and ‘x’ and stands for convert the numeric value of the parameter n to string and save this new value of string to string variable ‘x’.

string x = bigIntegerToString (n); //Declarate string variable x. Then we have an assignation operation between 'n' and 'x' and stands for
//convert the numeric value of the parameter n to string and save this new value of string to string variable 'x'

After that, This assignation helps to make the operation of reverse the string value from the beginning (x.rbegin()) to the end (x.rend()). Therefore all that string will be reverse and that reverse value wil have it the string variable x

x= string (x.rbegin(),x.rend()); //This assignation helps to make the operation of reverse the string value from the beginning
//(x.rbegin()) to the end (x.rend()). Therefore all that string will be reverse and that reverse value wil have it the string variable x

Then, we need to Declarate BigInteger variable y. Then we have an assignation operation between ‘y’ and ‘x’ and stands for convert the reverse string value of x to reverse and numeric BigInteger value and save this new value of BigInteger to BigInteger variable ‘y’

BigInteger y = stringToBigInteger(x); //Declarate BigInteger variable y. Then we have an assignation operation between 'y' and 'x' and
//stands for convert the reverse string value of x to reverse and numeric BigInteger value and save this new value of BigInteger to
//BigInteger variable 'y'

After that, we have a return statement. The bool function ispalindrome sends to the main program the value true, Otherwise false

return (n == y);//The bool function ispalindrome sends to the main program the value true, Otherwise false

Next, the program comes back to the main program and we need to use a math statement. This is a math operation between ‘counterpalindrome’ and ‘1’ and stands for do the sum between those values and saved it in the integer variable ‘counterpalindrome’.


counterpalindrome = counterpalindrome + 1; //This is a math operation between 'counterpalindrome' and '1' and stands for
 //do the sum between those values and saved it in the integer variable 'counterpalindrome'

 

Next, we use #Mastery11 Use of else with a conditional if. if the condition does not achieve on the other hand you will do this:

else //#Mastery11 Use of else with a conditional if: // if the condition does not achieve on the other hand you will do this:

{

candidate = i; // This command allows giving the value of the declared decimal variable 'i' to
//the declared int variable 'candidate'.
int counter = 1; //Declarate an int variable called counter to be the counter of the 30 iterations of applying the addition
//to the inverse.

while(ispalindrome(candidate)==false && counter <= 30) //With this command while is utilized as a loop WHILE execute all the
//instruccions that has this loop until that does not complete that the value of the bool function ispalindrome with the parameter
// of the value of variable candidate will be equal to false and the counter will be less or equal than 30.
{
candidate = becomepalindrom(candidate); //THIS ASSIGNATION HELPS TO CALL THE FUNCTION OF "becomepalindrom" TO MAKE THE TASK OF THE SUM
//VALUE OF THE NUMBERS WITH THE HELP OF THE VARIABLE int'candidate' and with the parameter of the variable candidate
// #Mastery06 and #Mastery07

counter++; //This is a math operation between 'counter' and '1' and stands for
//do the sum between those values and saved it in variable 'counter'

if (ispalindrome(candidate) == true) //#Mastery10 use of the if statement. This command allows the condition if the value of
//the bool function ispalindrome with the parameter the value of candidate is true and when this condition will be true, the tasks
//inside of the statement will execute.
// In this case if the value is true this will occur:
{
becomepalindrome++; //This is a math operation between 'becomepalindrome' and '1' and stands for
//do the sum between those values and saved it in variable 'becomepalindrome'
}

}//end of while

}//end of else

Next, we need this command allows giving the value of the declared decimal variable ‘i’ to the declared int variable ‘candidate’.

candidate = i; // This command allows giving the value of the declared decimal variable 'i' to
//the declared int variable 'candidate'.

Then, we need to declarate an int variable called counter to be the counter of the 30 iterations of applying the addition to the inverse.

int counter = 1; //Declarate an int variable called counter to be the counter of the 30 iterations of applying the addition
//to the inverse.

Next, With this command while is utilized as a loop WHILE execute all the instruccions that has this loop until that does not complete that the value of the bool function ispalindrome with the parameter of the value of variable candidate will be equal to false and the counter will be less or equal than 30.

while(ispalindrome(candidate)==false && counter <= 30) //With this command while is utilized as a loop WHILE execute all the
//instruccions that has this loop until that does not complete that the value of the bool function ispalindrome with the parameter
// of the value of variable candidate will be equal to false and the counter will be less or equal than 30.

Then, we need to do THIS ASSIGNATION HELPS TO CALL THE FUNCTION OF “becomepalindrom” TO MAKE THE TASK OF THE SUM VALUE OF THE NUMBERS WITH THE HELP OF THE VARIABLE int’candidate’ and with the parameter of the variable candidate #Mastery06 and #Mastery07

Then, the program escapes from the main function to the bool function in order to make the task of the total value of the numbers with the help of the string variable converted to a char variable. This is the structure of a function where you have subrutines in order to make different tasks, in this case we have a bool function with the name “ispalindrome” and with Biginteger parameter n in order to have bool results inside this function that are false (0) or true (1).


bool ispalindrome(BigInteger n) //This is the structure of a function where you have subrutines in order to make
//different tasks, in this case we have a bool function with the name "ispalindrome" and with Biginteger parameter n in order to
//have bool results inside this function that are false (0) or true (1).

Next, we  need to Declarate a string variable x. Then we have an assignation operation between ‘n’ and ‘x’ and stands for convert the numeric value of the parameter n to string and save this new value of string to string variable ‘x’.


 string x = bigIntegerToString (n); //Declarate string variable x. Then we have an assignation operation between 'n' and 'x' and stands for
 //convert the numeric value of the parameter n to string and save this new value of string to string variable 'x'

After that, This assignation helps to make the operation of reverse the string value from the beginning (x.rbegin()) to the end (x.rend()). Therefore all that string will be reverse and that reverse value wil have it the string variable x


x= string (x.rbegin(),x.rend()); //This assignation helps to make the operation of reverse the string value from the beginning
 //(x.rbegin()) to the end (x.rend()). Therefore all that string will be reverse and that reverse value wil have it the string variable x

Then, we need to Declarate BigInteger variable y. Then we have an assignation operation between ‘y’ and ‘x’ and stands for convert the reverse string value of x to reverse and numeric BigInteger value and save this new value of BigInteger to BigInteger variable ‘y’

After that, we have a return statement. The bool function ispalindrome sends to the main program the value true, Otherwise false


return (n == y);//The bool function ispalindrome sends to the main program the value true, Otherwise false

Then, THIS ASSIGNATION HELPS TO CALL THE FUNCTION OF “becomepalindrom” TO MAKE THE TASK OF THE SUM VALUE OF THE NUMBERS WITH THE HELP OF THE VARIABLE int’candidate’ and with the parameter of the variable candidate #Mastery06 and #Mastery07

candidate = becomepalindrom(candidate); //THIS ASSIGNATION HELPS TO CALL THE FUNCTION OF "becomepalindrom" TO MAKE THE TASK OF THE SUM
//VALUE OF THE NUMBERS WITH THE HELP OF THE VARIABLE int'candidate' and with the parameter of the variable candidate
// #Mastery06 and #Mastery07

Then, the program escapes from the main function to the BigInteger function in order to make the task of the total value of the numbers with the help of the string variable converted to a char variable. This is the structure of a function where you have subrutines in order to make different tasks, in this case we have a Biginteger function with the name “becomepalindrom” and with Biginteger parameter n in order to have BigInteger results inside this function that are big.

BigInteger becomepalindrom(BigInteger n) //This is the structure of a function where you have subrutines in order to make
//different tasks, in this case we have a Biginteger function with the name "becomepalindrom" and with Biginteger parameter n in order to
//have BigInteger results inside this function that are big.

After that, we need to Declarate BigInteger variable pizzacandidate.

BigInteger pizzacandidate; //Declarate BigInteger variable pizzacandidate.

Then, we need to Declarate string variable x. Then we have an assignation operation between ‘n’ and ‘x’ and stands for convert the numeric value of the parameter n to string and save this new value of string to string variable ‘x’

string x = bigIntegerToString (n); //Declarate string variable x. Then we have an assignation operation between 'n' and 'x' and stands for
//convert the numeric value of the parameter n to string and save this new value of string to string variable 'x'

After that, we need to do this assignation helps to make the operation of reverse the string value from the beginning (x.rbegin()) to the end (x.rend()). Therefore all that string will be reverse and that reverse value wil have it the string variable x


x=string(x.rbegin(),x.rend()); //This assignation helps to make the operation of reverse the string value from the beginning
//(x.rbegin()) to the end (x.rend()). Therefore all that string will be reverse and that reverse value wil have it the string variable x

After that, we need to Declarate BigInteger variable y. Then we have an assignation operation between ‘y’ and ‘x’ and stands for convert the reverse string value of x to reverse and numeric BigInteger value and save this new value of BigInteger to BigInteger variable ‘y’.

BigInteger y = stringToBigInteger(x); //Declarate BigInteger variable y. Then we have an assignation operation between 'y' and 'x' and
//stands for convert the reverse string value of x to reverse and numeric BigInteger value and save this new value of BigInteger to
//BigInteger variable 'y'

Then,  we need this as a math operation between ‘y’ and ‘n’ and stands for adding those values and saved it in BigInteger variable ‘pizzacandidate’

pizzacandidate = y + n; //This is a math operation between 'y' and 'n' and stands for adding
//those values and saved it in BigInteger variable 'pizzacandidate'

Then, The BigInteger function becomepalindrom sends to the main program the BigInteger value of pizzacandidate

return pizzacandidate; //The BigInteger function becomepalindrom sends to the main program the BigInteger value of pizzacandidate

Next, the program comes back to the main program with an operation. This is a math operation between ‘counter’ and ‘1’ and stands for do the sum between those values and saved it in variable ‘counter’

counter++; //This is a math operation between 'counter' and '1' and stands for
//do the sum between those values and saved it in variable 'counter'

After that, we need #Mastery10 use of the if statement. This command allows the condition if the value of the bool function ispalindrome with the parameter the value of candidate is true and when this condition will be true, the tasks inside of the statement will execute. In this case if the value is true this will occur:

if (ispalindrome(candidate) == true) //#Mastery10 use of the if statement. This command allows the condition if the value of
//the bool function ispalindrome with the parameter the value of candidate is true and when this condition will be true, the tasks
//inside of the statement will execute.
// In this case if the value is true this will occur:

Next, we need this math operation between ‘becomepalindrome’ and ‘1’ and stands for do the sum between those values and saved it in variable ‘becomepalindrome’

becomepalindrome++; //This is a math operation between 'becomepalindrome' and '1' and stands for
//do the sum between those values and saved it in variable 'becomepalindrome'

After that, ends the else and the while.

}//end of while

}//end of else

Next, why out? palindrome or counter 30+. And we a #Mastery10 use of the if statement. This command allows the condition if the value of the bool function ispalindrome with the parameter the value of candidate is false and when this condition will be true, the tasks inside of the statement will execute.

if (ispalindrome(candidate) == false) //#Mastery10 use of the if statement. This command allows the condition if the value of
//the bool function ispalindrome with the parameter the value of candidate is false and when this condition will be true, the tasks
//inside of the statement will execute.

After that, we need a math operation. This is a math operation between ‘Lychrelcounter’ and ‘1’ and stands for do the sum between those values and saved it in variable ‘Lychrelcounter’

Lychrelcounter++; //This is a math operation between 'Lychrelcounter' and '1' and stands for
//do the sum between those values and saved it in variable 'Lychrelcounter'

Next, in this text we show the authentic output of the value entered of i in the terminal interface #Mastery20 Validated user input (ensure correct / expected data entry)

cout << "Found Lychrel number: " << i << endl; //In
//this text we show the authentic output of the value entered of i in the terminal interface #Mastery20 Validated user
//input (ensure correct / expected data entry)

Then, we have in this text we show the authentic output of the value entered of lower and higher in the terminal interface #Mastery20 Validated user input (ensure correct / expected data entry)

cout << "And the results are for the range "<<lower<<" to "<<higher<<endl; //In
//this text we show the authentic output of the value entered of lower and higher in the terminal interface #Mastery20 Validated user
//input (ensure correct / expected data entry)

After that, In this text we show the authentic output of the value entered of counterpalindrome in the terminal interface #Mastery20 Validated user input (ensure correct / expected data entry)

cout << "Natural Palindromes:" << counterpalindrome<<endl;//In
//this text we show the authentic output of the value entered of counterpalindrome in the terminal interface #Mastery20 Validated user
//input (ensure correct / expected data entry)

Then, we show the authentic output of the value entered of becomepalindrome in the terminal interface #Mastery20 Validated user input (ensure correct / expected data entry)

cout << "Non Lychrels (become palindrome):" << becomepalindrome<<endl; //In
//this text we show the authentic output of the value entered of becomepalindrome in the terminal interface #Mastery20 Validated user
//input (ensure correct / expected data entry)

After that, In this text we show the authentic output of the value entered of Lychrelcounter in the terminal interface #Mastery20 Validated user input (ensure correct / expected data entry)

cout << "Lychrel candidates:" << Lychrelcounter<<endl<<endl; //In
//this text we show the authentic output of the value entered of Lychrelcounter in the terminal interface #Mastery20 Validated user
//input (ensure correct / expected data entry)

Finally we have a return statement.

return 0; // This command allows label the final of the function main ()

And i also resolved it by doing this video tutorial that i made reafirming these parts at this link :#WSQ08 Tutorial 10 Yo soy 196 11/03/17 and WSQ8.cpp

Finally with the command make and ./yosoy196 or ./WSQ8.cpp depending if you change the extension file of the makefile out and tells the terminal to run de C++ file:

yo soy 196

This code for solution will be here and in Github:

Link in Github:WSQ8.cpp

If you do not want the WSQ8.cpp there is it in here with comments. The comments are very useful to detect errors and create new things #Mastery01 #Masterytopic01 #MasteryTopic01 #MASTERY01 #MASTERYTOPIC01 :

Also in the last class I learned how to present my C++ in a better ‘readable’ way after doing it #Mastery02 #Masterytopic02 #MasteryTopic02 #MASTERY02 #MASTERYTOPIC02:

#include <iostream>//Library to call all the
//fuctions of inputs and outputs of data in languague
//C++ #MasteryTopic01

#include <string>//Library to call all the
//fuctions of strings of data in languague
//C++ #MasteryTopic19

using namespace std;//In C++ we need a command
// that everytime goes with the instructions of input and outputs
//of data that is call std but with this command helps writing
//these std out of the main because the machine factorizes them

#include "BigIntegerLibrary.hh" //Library to call all the
//fuctions big numbers of data and convert numbers to strings and viceversa in languague
//C++ #MasteryTopic01 and #MasteryTopic09 Creating and using your own libraries (program with multiple files)

bool ispalindrome(BigInteger n) //This is the structure of a function where you have subrutines in order to make
//different tasks, in this case we have a bool function with the name "ispalindrome" and with Biginteger parameter n in order to
//have bool results inside this function that are false (0) or true (1).
{

string x = bigIntegerToString (n); //Declarate string variable x. Then we have an assignation operation between 'n' and 'x' and stands for
//convert the numeric value of the parameter n to string and save this new value of string to string variable 'x'

x= string (x.rbegin(),x.rend()); //This assignation helps to make the operation of reverse the string value from the beginning
//(x.rbegin()) to the end (x.rend()). Therefore all that string will be reverse and that reverse value wil have it the string variable x

BigInteger y = stringToBigInteger(x); //Declarate BigInteger variable y. Then we have an assignation operation between 'y' and 'x' and
//stands for convert the reverse string value of x to reverse and numeric BigInteger value and save this new value of BigInteger to
//BigInteger variable 'y'

return (n == y);//The bool function ispalindrome sends to the main program the value true, Otherwise false

} //end of bool function

BigInteger becomepalindrom(BigInteger n) //This is the structure of a function where you have subrutines in order to make
//different tasks, in this case we have a Biginteger function with the name "becomepalindrom" and with Biginteger parameter n in order to
//have BigInteger results inside this function that are big.
{
BigInteger pizzacandidate; //Declarate BigInteger variable pizzacandidate.

string x = bigIntegerToString (n); //Declarate string variable x. Then we have an assignation operation between 'n' and 'x' and stands for
//convert the numeric value of the parameter n to string and save this new value of string to string variable 'x'


x=string(x.rbegin(),x.rend()); //This assignation helps to make the operation of reverse the string value from the beginning
//(x.rbegin()) to the end (x.rend()). Therefore all that string will be reverse and that reverse value wil have it the string variable x

BigInteger y = stringToBigInteger(x); //Declarate BigInteger variable y. Then we have an assignation operation between 'y' and 'x' and
//stands for convert the reverse string value of x to reverse and numeric BigInteger value and save this new value of BigInteger to
//BigInteger variable 'y'

pizzacandidate = y + n; //This is a math operation between 'y' and 'n' and stands for adding
//those values and saved it in BigInteger variable 'pizzacandidate'
return pizzacandidate; //The BigInteger function becomepalindrom sends to the main program the BigInteger value of pizzacandidate

}

int main() { //Begin of the program

int lower, higher, counterpalindrome = 0, becomepalindrome = 0, Lychrelcounter = 0; //Declarate integers variables lower for the lower
//bound,higher for the upper bound, counterpalindrome initialized in 0 for being the counter of how many natural palindromes are,
//becomepalindrome initialized in 0 for being the counter of how many non-lychrels that could become palindrome with the reverse are,
//Lychrelcounter initialized in 0 for being the counter of how many Lychrel candidates are.

BigInteger candidate; //Declarate BigInteger variable 'candidate' with a huge value

cout << "Give me the lower bound of numbers to consider:"; //command of out data in form of text
cin >> lower;// This command allows enter data for inputs. In this case this enters the
//value of variable 'lower'

cout << "Give me the upper bound of numbers to consider:"; //command of out data in form of text
cin >> higher;// This command allows enter data for inputs. In this case this enters the
//value of variable 'higher'

cout<<endl<<"Calculating whether each value is one of: palindrome, non-lychrel or Lychrel candidate"<<endl<<endl;
//command of out data in form of text and text spaces

for(int i=lower; i<=higher; i++) //With this command for is utilized as a loop FOR execute all the
//instruccions that has this loop until that does not complete that the variable i
// will be less or equal than the variable higher while it is increasing one in one in this variable i
//inicialized from the value of the variable lower
{


if(ispalindrome(i) == true) //#Mastery10 use of the if statement. This command allows the condition if the value of
//the bool function ispalindrome with the parameter the value of i is true and when this condition will be true, the tasks
//inside of the statement will execute.
// In this case if the value is true this will occur:
{
counterpalindrome = counterpalindrome + 1; //This is a math operation between 'counterpalindrome' and '1' and stands for
//do the sum between those values and saved it in the integer variable 'counterpalindrome'


}


else //#Mastery11 Use of else with a conditional if: // if the condition does not achieve on the other hand you will do this:

{

candidate = i; // This command allows giving the value of the declared decimal variable 'i' to
//the declared int variable 'candidate'.
int counter = 1; //Declarate an int variable called counter to be the counter of the 30 iterations of applying the addition
//to the inverse.

while(ispalindrome(candidate)==false && counter <= 30) //With this command while is utilized as a loop WHILE execute all the
//instruccions that has this loop until that does not complete that the value of the bool function ispalindrome with the parameter
// of the value of variable candidate will be equal to false and the counter will be less or equal than 30.
{
candidate = becomepalindrom(candidate); //THIS ASSIGNATION HELPS TO CALL THE FUNCTION OF "becomepalindrom" TO MAKE THE TASK OF THE SUM
//VALUE OF THE NUMBERS WITH THE HELP OF THE VARIABLE int'candidate' and with the parameter of the variable candidate
// #Mastery06 and #Mastery07

counter++; //This is a math operation between 'counter' and '1' and stands for
//do the sum between those values and saved it in variable 'counter'

if (ispalindrome(candidate) == true) //#Mastery10 use of the if statement. This command allows the condition if the value of
//the bool function ispalindrome with the parameter the value of candidate is true and when this condition will be true, the tasks
//inside of the statement will execute.
// In this case if the value is true this will occur:
{
becomepalindrome++; //This is a math operation between 'becomepalindrome' and '1' and stands for
//do the sum between those values and saved it in variable 'becomepalindrome'
}

}//end of while

}//end of else

// why out? palindrome or counter 30+
if (ispalindrome(candidate) == false) //#Mastery10 use of the if statement. This command allows the condition if the value of
//the bool function ispalindrome with the parameter the value of candidate is false and when this condition will be true, the tasks
//inside of the statement will execute.
{
Lychrelcounter++; //This is a math operation between 'Lychrelcounter' and '1' and stands for
//do the sum between those values and saved it in variable 'Lychrelcounter'
cout << "Found Lychrel number: " << i << endl; //In
//this text we show the authentic output of the value entered of i in the terminal interface #Mastery20 Validated user
//input (ensure correct / expected data entry)
}

}// END OF FOR


cout << "And the results are for the range "<<lower<<" to "<<higher<<endl; //In
//this text we show the authentic output of the value entered of lower and higher in the terminal interface #Mastery20 Validated user
//input (ensure correct / expected data entry)

cout << "Natural Palindromes:" << counterpalindrome<<endl;//In
//this text we show the authentic output of the value entered of counterpalindrome in the terminal interface #Mastery20 Validated user
//input (ensure correct / expected data entry)
cout << "Non Lychrels (become palindrome):" << becomepalindrome<<endl; //In
//this text we show the authentic output of the value entered of becomepalindrome in the terminal interface #Mastery20 Validated user
//input (ensure correct / expected data entry)

cout << "Lychrel candidates:" << Lychrelcounter<<endl<<endl; //In
//this text we show the authentic output of the value entered of Lychrelcounter in the terminal interface #Mastery20 Validated user
//input (ensure correct / expected data entry)

return 0; // This command allows label the final of the function main ()
}

#WSQ09 Multipart Data and Files 10/03/17 and WSQ09.cpp

#WSQ09 Multipart Data and Files 10/03/17 and WSQ09.cpp

PICTURE OF ACTOR

So in this nine week class I started with doing this WSQ09. I started reviewing in creating and calling functions in C++.#Mastery06, #Mastery07, #Mastery16 Use of recursion for repetitive algorithms, #Mastery17 When to use what type of repetition in a program, #Mastery18 Creation and use of Arrays/ Vectors in C++.

Futhermore in this assignment we have two new mastery topics covered #Mastery19 Creation and use of strings and #Mastery21 Reading and writing of text files.

What I did for this numeric program is solving the problem to the user by writing a function that receives as parameter the name of a file (this would be a string value like data.txt) and this function counts the number of lines and the number of characters in the file which it returns as a single value (but with two values). I will want to look at how to create/define and return a struct value from a function and how to open and read text files line by line.

Hence, the resources I need it to solve this program are here:

ken bauer

How to convert string to char

C++ Tutorial for Beginners 43 – How to Read from a .txt file using C++

The following photograph shows the solution to this problem:

wsq9v1

wsq9v2wsq9v3wsq9v4

Picture of author

So at first I wrote the same structure of the program just did the same as what i did in Hello World: Second Class, Second Blog (Blog of the second class 12/01/17) and Hello World.cpp,  #WSQ01 Post Fun with Numbers 16/01/17 and WSQ1.cpp#WSQ02 Post Temperature 23/01/17 and WSQ02.cpp#WSQ03 Post Pick a Number 23/01/17 and WSQ03.cpp#WSQ04 Post Sum of Numbers 23/01/17 and WSQ04.cpp#WSQ05 Six Tutorial On To Functions 12/02/17 and WSQ05.cpp#WSQ06 Factorial Calculator 12/02/17 and WSQ06.cpp and #WSQ07 Lists 03/03/17 and WSQ07.cppwhere i explained the application of the #MasteryTopic01 that it is for comments that could be very useful when debugging and #MasteryTopic04 that is basic output for data. Also I did some other mastery topics.

What i first put in the code was the library to call all the fuctions <iostream> of inputs and outputs of data in languague C++ #MasteryTopic06 Calling Functions and #MasteryTopic08 Importing and using libraries.

#include <iostream> //Library to call all the
//fuctions of inputs and outputs of data in languague
//C++ #MasteryTopic01

Next, I need a Library to call all the fuctions of reading AND writing files in languague
C++ #MasteryTopic21

#include <fstream> //Library to call all the
//fuctions of reading AND writing files in languague
//C++ #MasteryTopic21

Next, I need a Library to call all the fuctions of strings of data in languague C++ #MasteryTopic19

#include <string>//Library to call all the
//fuctions of strings of data in languague
//C++ #MasteryTopic19

Then i had to write a command that everytime goes with the instructions of input and outputs of data that is call std but with this command helps writing these std out of the main because the machine factorizes them. Futhermore, you need a library to use all math expresions.

using namespace std; //In C++ we need a command
// that everytime goes with the instructions of input and outputs
//of data that is call std but with this command helps writing
//these std out of the main because the machine factorizes them

Next I initialize the begin of my program int main()

int main() {

After that I had to declarate a filetype varible STRUCKANS from the struct function

filetype struckans; //Declarate filetype varible STRUCKANS from the struct function

Hence, we need to know what is a struct function that is a new function where you can return or send more compound values to other functions.This is the structure of a function where you have subrutines in order to make different tasks, in this case we have a STRUCT function with the name “filetype”. In addition you need to write outside of the main function and use the ‘;’.

struct filetype {//This is the structure of a function where you have subrutines in order to make
//different tasks, in this case we have a STRUCT function with the name "filetype".

int counter;//Declarate decimal variable counter
int lengthfinal;//Declarate decimal variable lengthfinal
int backup;//Declarate decimal variable backup

}; //end of struct

Futhermore, we need to declarate string varible filename and initialized it to “data.txt” #Mastery19 and #Mastery20

string filename="data.txt"; //Declarate string varible filename and initialized it to "data.txt" #Mastery19 and #Mastery20

Next, THIS ASSIGNATION HELPS TO CALL THE FUNCTION OF “input” TO MAKE THE TASK OF COUNT THE VALUE OF THE NUMBER WITH THE HELP OF THE VARIABLE filetype ‘struckans’ with the parameter filename.c_str() IN ORDER to convert string to char as a parameter #Mastery06 and #Mastery07

struckans = input(filename.c_str()); //THIS ASSIGNATION HELPS TO CALL THE FUNCTION OF "input" TO MAKE THE TASK OF
//COUNT THE VALUE OF THE NUMBER WITH THE HELP OF THE VARIABLE filetype 'struckans' with the parameter filename.c_str()
//IN ORDER to convert string to char as a parameter #Mastery06 and #Mastery07

After this last action, the program escapes from the main function to the filetype input function in order to make the task of the total value of the numbers with the help of the string variable converted to a char variable.This is the structure of a function where you have subrutines in order to make different tasks, in this case we have a STRUCT function with the name “input” and with CHAR parameter*filename where I am using the #Mastery19 Creation and use of strings in C++ in order to have struct results inside this function. Therefore, I am using the char in order to reference the string parameter filename with combining it with a loop.

filetype input(const char *filename) //This is the structure of a function where you have subrutines in order to make
//different tasks, in this case we have a STRUCT function with the name "input" and with CHAR parameter
//*filename where I am using the #Mastery19 Creation and use of strings in C++ in order to have struct results inside this function.
//Therefore, I am using the char in order to reference the string parameter filename with combining it with a loop.

Next, Inside of the struct filetype function ‘input’ I have to declarate filetype varible STRUCKANS from the struct function. (This is a local variable).

filetype struckans; //Declarate filetype varible STRUCKANS from the struct function

Next, we need to declarate a file variable in order to write or read #Mastery21 Reading and writing of text files.Therefore, this is a variable called file where you also make the function of giving the value of filename to file that in this case is data.txt

ifstream file(filename); ///Declarate a file variable in order to write or read #Mastery21 Reading and writing of text files
//Therefore, this is a variable called file where you also make the function of giving the value of filename to file that in this case
//is data.txt

Next, we need to declarate string variable line

string line; //Declarate string variable line

After that, we need to initialize the value of the struct variable counter to 0 #Mastery19 and #Mastery21

struckans.counter=0; //Initialize the value of the struct variable counter to 0 #Mastery19 and #Mastery21

Next, we need to initialize the value of the struct variable backup to 0 #Mastery19 and #Mastery21

struckans.backup=0; //Initialize the value of the struct variable backup to 0 #Mastery19 and #Mastery21

Then we have a command of data in form of text space

cout<<endl; //command of data in form of text space

Next I need to use the #Mastery10 use of the if statement. This command allows the condition if the file is open and when this condition will be true, the tasks inside of the statement will execute. In this case if the value file is open this will occur:

if(file.is_open()) //#Mastery10 use of the if statement //This command allows the condition if the file is open and when this
//condition will be true, the tasks inside of the statement will execute. In this case if the value file is open
//this will occur:

Inside of the condition we have a command, with this command while is utilized as a loop WHILE execute all the instruccions that has this loop until that does not complete that we get all the characters of lines in the file

while(getline(file,line)) //With this command while is utilized as a loop WHILE execute all the
//instruccions that has this loop until that does not complete that we get all the characters of lines in the file

how many characters in this line?. Therefore, we need this is a string operation between ‘line’ and ‘struckans’ and stands for do the length of the file and saved it in struct variable ‘lengthfinal’ #Mastery19 Creation and use of strings

// how many characters in this line?
struckans.lengthfinal = line.length();//This is a string operation between 'line' and 'struckans' and stands for do the length of the
//file and saved it in struct variable 'lengthfinal' #Mastery19 Creation and use of strings

After that, we need this is a math operation between ‘backup’ and ‘lengthfinal’ and stands for do the sum between those values and saved it in struct variable ‘BACKUP’

struckans.backup = struckans.backup + struckans.lengthfinal;//This is a math operation between 'backup' and 'lengthfinal' and stands
//for do the sum between those values and saved it in struct variable 'BACKUP'

Then, we need this math operation between ‘counter’ and ‘1’ and stands for
do the sum between those values and saved it in struct variable ‘counter’. THIS IS FOR HAVE A COUNTER OF THE NUMBER OF LINES THAT THE data.txt FILE HAS.


struckans.counter = struckans.counter + 1;//This is a math operation between 'counter' and '1' and stands for
//do the sum between those values and saved it in struct variable 'counter'

Next, we have a command of data in form of text space

cout<<endl;//command of data in form of text space

After that, we need this text we show the authentic output of the value entered of struckans.counter in the terminal interface #MasteryTopic04. THIS IS TO TELL THE USER THE NUMBER OF THE LINES OF DATA.

cout<<"The number of the lines of data.txt="<<struckans.counter<<endl; //In
//this text we show the authentic output of the value entered of struckans.counter in the terminal interface #MasteryTopic04

Then, we need a command of data in form of text space

cout<<endl;//command of data in form of text space

After that, we need this text where shows the authentic output of the value entered of struckans.BACKUP in the terminal interface #MasteryTopic08

cout<<"The number of the lines of data.txt="<<struckans.counter<<endl; //In
//this text we show the authentic output of the value entered of struckans.counter in the terminal interface #MasteryTopic04

Next, we need a command of data in form of text space

cout<<endl;//command of data in form of text space

Finally, we have a command that makes that the file is close

file.close(); //command that make that the file is close

Next, the program goes back to the main function and I need this command allows label the final of the function main ()

return 0; // This command allows label the final of the function main ()

And i also resolved it by doing this video tutorial that i made reafirming these parts at this link :#WSQ09 Tutorial 9 Multipart Data and Files 10/03/17 and WSQ9.cpp

Finally with the command ./a. out tells the terminal to run de C++ file:

charactes

This code for solution will be here and in Github:

Link in Github:WSQ9.cpp

If you do not want the WSQ9.cpp there is it in here with comments. The comments are very useful to detect errors and create new things #Mastery01 #Masterytopic01 #MasteryTopic01 #MASTERY01 #MASTERYTOPIC01 :

Also in the last class I learned how to present my C++ in a better ‘readable’ way after doing it #Mastery02 #Masterytopic02 #MasteryTopic02 #MASTERY02 #MASTERYTOPIC02:

#include <iostream> //Library to call all the
//fuctions of inputs and outputs of data in languague
//C++ #MasteryTopic01
#include <fstream> //Library to call all the
//fuctions of reading AND writing files in languague
//C++ #MasteryTopic21

#include <string>//Library to call all the
//fuctions of strings of data in languague
//C++ #MasteryTopic19

using namespace std; //In C++ we need a command
// that everytime goes with the instructions of input and outputs
//of data that is call std but with this command helps writing
//these std out of the main because the machine factorizes them

struct filetype {//This is the structure of a function where you have subrutines in order to make
//different tasks, in this case we have a STRUCT function with the name "filetype".

int counter;//Declarate decimal variable counter
int lengthfinal;//Declarate decimal variable lengthfinal
int backup;//Declarate decimal variable backup

}; //end of struct

filetype input(const char *filename) //This is the structure of a function where you have subrutines in order to make
//different tasks, in this case we have a STRUCT function with the name "input" and with CHAR parameter
//*filename where I am using the #Mastery19 Creation and use of strings in C++ in order to have struct results inside this function.
//Therefore, I am using the char in order to reference the string parameter filename with combining it with a loop.
{
filetype struckans; //Declarate filetype varible STRUCKANS from the struct function

ifstream file(filename); ///Declarate a file variable in order to write or read #Mastery21 Reading and writing of text files
//Therefore, this is a variable called file where you also make the function of giving the value of filename to file that in this case
//is data.txt

string line; //Declarate string variable line
struckans.counter=0; //Initialize the value of the struct variable counter to 0 #Mastery19 and #Mastery21
struckans.backup=0; //Initialize the value of the struct variable backup to 0 #Mastery19 and #Mastery21
cout<<endl; //command of data in form of text space

if(file.is_open()) //#Mastery10 use of the if statement //This command allows the condition if the file is open and when this
//condition will be true, the tasks inside of the statement will execute. In this case if the value file is open
//this will occur:
{


while(getline(file,line)) //With this command while is utilized as a loop WHILE execute all the
//instruccions that has this loop until that does not complete that we get all the characters of lines in the file
{

// how many characters in this line?
struckans.lengthfinal = line.length();//This is a string operation between 'line' and 'struckans' and stands for do the length of the
//file and saved it in struct variable 'lengthfinal' #Mastery19 Creation and use of strings

struckans.backup = struckans.backup + struckans.lengthfinal;//This is a math operation between 'backup' and 'lengthfinal' and stands
//for do the sum between those values and saved it in struct variable 'BACKUP'

struckans.counter = struckans.counter + 1;//This is a math operation between 'counter' and '1' and stands for
//do the sum between those values and saved it in struct variable 'counter'


}




cout<<endl;//command of data in form of text space
cout<<"The number of the lines of data.txt="<<struckans.counter<<endl; //In
//this text we show the authentic output of the value entered of struckans.counter in the terminal interface #MasteryTopic04
cout<<endl;//command of data in form of text space


cout<<"The number of the characters of data.txt="<<struckans.backup<<endl;//In
//this text we show the authentic output of the value entered of struckans.BACKUP in the terminal interface #MasteryTopic08
cout<<endl;//command of data in form of text space


file.close(); //command that make that the file is close

}



}

int main() {

filetype struckans; //Declarate filetype varible STRUCKANS from the struct function
string filename="data.txt"; //Declarate string varible filename and initialized it to "data.txt" #Mastery19 and #Mastery20


struckans = input(filename.c_str()); //THIS ASSIGNATION HELPS TO CALL THE FUNCTION OF "input" TO MAKE THE TASK OF
//COUNT THE VALUE OF THE NUMBER WITH THE HELP OF THE VARIABLE filetype 'struckans' with the parameter filename.c_str()
//IN ORDER to convert string to char as a parameter #Mastery06 and #Mastery07


return 0; // This command allows label the final of the function main ()

}