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 ()
}
Anuncio publicitario

9 comentarios en “#WSQ08 Yo soy 196 11/03/17 and WSQ08.cpp

Deja una respuesta

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Salir /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Salir /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Salir /  Cambiar )

Conectando a %s