#Quiz of personality

#Quiz of personality

 

I am a leader yei!. I am the protagonist in a new world!!

 

person

Anuncio publicitario

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

#Quiz09 See the struct function explained!

#Quiz09 See the struct function explained!

THIS IS THE #QUIZ9 WHOSE OBJECTIVE IS CREATE AND CALL STRUCK FUNCTIONS TO DO DIFFERENT TASKS AT DIFFERENT TIMES USING RECURSION AND LOOPS. COVERING #MASTERYTOPIC06 #MASTERYTOPIC07 .

In this #QUIZ9 makes a function that receives four parameters: x1, y1, x2, y2 which are all floating point values.

The function is called distance and returns (float) the distance between x1,y1 and x2,y2 on the cartesian coordinate plane. (struct function)

Remember the distance between 2 points:

distance-between-two-points-on-a-plain

Link of picture

First let me show you the pictures of the quiz. At the beginning of the quiz we needed it to do this quiz in two ways one using a struct function and the other not. So let me show you the 2 solutions of this problem.

Solution with the struct function:

quiz9v1

quiz9v2

quiz9v3

FIRST TO DO IN THIS #QUIZ09 with the struct solution is including 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 a library to call all the fuctions of MATH of data in languague
C++ #MasteryTopic01

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

Next, 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 need this 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 «Point».


struct Point { //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 "Point".

float x; //Declarate decimal variable x
float y; //Declarate decimal variable y


};

Inside of the struct function, we need to declarate decimal variable x

float x;  //Declarate decimal variable x

Inside of the struct function, we need to declarate decimal variable y

float y;  //Declarate decimal variable y

Then we have the beginning of the program

int main() {

Next we need to declarate decimal float variable result in order to show the float value of the distance function

float result; //Declarate decimal float variable result

Next, we need to declarate Point varible p1 from the struct function. This definition indicates that there are two elements in this structure, named x and y. These elements are called instance variables and with this math operation sends the value of 0 and 0
to variable x and y inside the variable p1

Point p1={0,0}; //Declarate Point varible p1 from the struct function. This definition indicates that there are two elements
//in this structure, named x and y. These elements are called instance variables and with this math operation sends the value of 0 and 0
//to variable x and y inside the variable p1

Then we have to call a function with an assignation.THIS ASSIGNATION HELPS TO CALL THE FUNCTION OF «distance» TO MAKE THE TASK OF DISTANCE VALUE OF THE TWO POINTS WITH THE HELP OF VARIABLE struct ‘p1’ #Mastery06 and #Mastery07

result=distance(p1); //THIS ASSIGNATION HELPS TO CALL THE FUNCTION OF "distance" TO MAKE THE TASK OF DISTANCE VALUE OF
//THE TWO POINTS WITH THE HELP OF VARIABLE struct 'p1' #Mastery06 and #Mastery07

After this last action, the program escapes from the main function to the float ‘distance’ in order to make the task of the distance of the two points with the help of the struct variable. 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 «distance» and with struct parameter Point& p1 where I am using the parameters in order to have float results inside this function.

float distance (Point& p1) //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 "distance" and with struct parameter Point& p1
//where I am using the parameters in order to have float results inside this function.

Then, we need This definition that indicates there are two elements in this structure, named x and y. These elements are called instance variables and with this math operation sends the value of 3 and 4 to variable x and y inside the variable p2

Point p2={3,4}; //This definition indicates that there are two elements in this structure, named
//x and y. These elements are called instance variables and with this math operation sends the value of 3 and 4 to variable x and y inside
// the variable p2

Next, we need a command of out data in form of text. In this text we show the authentic output of the value entered of p1.x in the terminal interface #MasteryTopic04

cout<<"Point P1=("<<p1.x; //command of out data in form of text
//In this text we show the authentic output of the value entered of p1.x in the terminal interface #MasteryTopic04

Next, we use a command of out data in form of text. In this text we show the authentic output of the value entered of p1.y in the terminal interface #MasteryTopic04

cout<<","<<p1.y<<")"<<endl;//command of out data in form of text
//In this text we show the authentic output of the value entered of p1.y in the terminal interface #MasteryTopic04

Then, we need a command of out data in form of text. In this text we show the authentic output of the value entered of p2.x in the terminal interface #MasteryTopic04

cout<<"Point P2=("<<p2.x; //command of out data in form of text
//In this text we show the authentic output of the value entered of p2.x in the terminal interface #MasteryTopic04

Next, we use a command of out data in form of text. In this text we show the authentic output of the value entered of p2.y in the terminal interface #MasteryTopic04

cout<<","<<p2.y<<")"<<endl;//command of out data in form of text
//In this text we show the authentic output of the value entered of p2.y in the terminal interface #MasteryTopic04

Then, we need to declarate decimal float variable dx

float dx; //Declarate decimal float variable dx

After that, we need to declarate decimal float variable dy

float dy; //Declarate decimal float variable dy

Next, we have a statement. This is a math operation between ‘p2.x’ and ‘p1.x’ and stands for take the difference between those values and saved it in float variable ‘dx’

dx = p2.x - p1.x; //This is a math operation between 'p2.x' and 'p1.x' and stands for take
//the difference between those values and saved it in float variable 'dx'

Next, we have a statement. This is a math operation between ‘p2.y’ and ‘p1.y’ and stands for take the difference between those values and saved it in float variable ‘dy’

dy= p2.y - p1.y; //This is a math operation between 'p2.y' and 'p1.y' and stands for take
//the difference between those values and saved it in float variable 'dy'

Finally, we have a return statement. This returns the value of the square root of the sum of squares of dx, dy in order to be called in the main function

return sqrt(dx*dx + dy*dy); // returns the value of the square root of the sum of squares of dx, dy in order to be called in the main
//function

Then, the program goes back to the main program and we need a command of out data in form of text. In this text we show the authentic output of the value entered of result in the terminal interface #MasteryTopic04. This is to tell the user that the distance between p1 and p2 is the float result returned from the float function

cout<<"distance between p1 and p2="<<result<<endl; //command of out data in form of text
//In this text we show the authentic output of the value entered of result in the terminal interface #MasteryTopic04
//This is to tell the user that the distance between p1 and p2 is the float result returned from the float function

Next, This command allows label the final of the function main ()

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

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

distance

This code for solution will be here and in Github:

Link in Github:quiz9v2.cpp

If you do not want the quiz9v2.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

struct Point { //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 "Point".

float x; //Declarate decimal variable x
float y; //Declarate decimal variable y


};


float distance (Point& p1) //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 "distance" and with struct parameter Point& p1
//where I am using the parameters in order to have float results inside this function.

{
Point p2={3,4}; //This definition indicates that there are two elements in this structure, named
//x and y. These elements are called instance variables and with this math operation sends the value of 3 and 4 to variable x and y inside
// the variable p2

cout<<"Point P1=("<<p1.x; //command of out data in form of text
//In this text we show the authentic output of the value entered of p1.x in the terminal interface #MasteryTopic04
cout<<","<<p1.y<<")"<<endl;//command of out data in form of text
//In this text we show the authentic output of the value entered of p1.y in the terminal interface #MasteryTopic04

cout<<"Point P2=("<<p2.x; //command of out data in form of text
//In this text we show the authentic output of the value entered of p2.x in the terminal interface #MasteryTopic04
cout<<","<<p2.y<<")"<<endl;//command of out data in form of text
//In this text we show the authentic output of the value entered of p2.y in the terminal interface #MasteryTopic04

float dx; //Declarate decimal float variable dx
float dy; //Declarate decimal float variable dy

dx = p2.x - p1.x; //This is a math operation between 'p2.x' and 'p1.x' and stands for take
//the difference between those values and saved it in float variable 'dx'
dy= p2.y - p1.y; //This is a math operation between 'p2.y' and 'p1.y' and stands for take
//the difference between those values and saved it in float variable 'dy'



return sqrt(dx*dx + dy*dy); // returns the value of the square root of the sum of squares of dx, dy in order to be called in the main
//function




}

int main() {


float result; //Declarate decimal float variable result
Point p1={0,0}; //Declarate Point varible p1 from the struct function. This definition indicates that there are two elements
//in this structure, named x and y. These elements are called instance variables and with this math operation sends the value of 0 and 0
//to variable x and y inside the variable p1

result=distance(p1); //THIS ASSIGNATION HELPS TO CALL THE FUNCTION OF "distance" TO MAKE THE TASK OF DISTANCE VALUE OF
//THE TWO POINTS WITH THE HELP OF VARIABLE struct 'p1' #Mastery06 and #Mastery07

cout<<"distance between p1 and p2="<<result<<endl; //command of out data in form of text
//In this text we show the authentic output of the value entered of result in the terminal interface #MasteryTopic04
//This is to tell the user that the distance between p1 and p2 is the float result returned from the float function


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

}

Solution without the struct function:

quiz9

quiz91

FIRST TO DO IN THIS #QUIZ09 with the struct solution is including 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 need this library to call all the fuctions of MATH of data in languague C++ #MasteryTopic01

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

Then, 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 beginning of the program

int main() {

After that, we have to declarate decimal float variables x1, y1, x2, y2 in order to send the values in the distance function

float x1,y1,x2,y2; //Declarate decimal float variables x1, y1, x2, y2 in order to send the values in the distance function

Then, we need this operation that stands for an output of the values 0 0 4 3 to each parameter of the distance function.

cout<<distance(0,0,4,3)<<endl;//This operation stands for an output of the values 0 0 4 3 to each parameter of the distance function

After this last action, the program escapes from the main function to the float ‘distance’ in order to make the task of the distance of the two points with the help of the struct variable. 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 «distance» and with float parameters x1,y1,x2,y2 in order to have float results inside this function.

float distance (float x1, float y1,float x2, float y2) //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 "distance" and with float parameters a,b,c in order to
//have float results inside this function.

Then inside of the float distance function, we need to declarate decimal float variable dx. This is a math operation between ‘x2’ and ‘x1’ and stands for take the difference between those values and saved it in float variable ‘dx’

float dx=x2-x1; //Declarate decimal float variable dx. This is a math operation between 'x2' and 'x1' and stands for take
//the difference between those values and saved it in float variable 'dx'

Next inside of the float distance function, we need to declarate decimal float variable dy. This is a math operation between ‘y2’ and ‘y1’ and stands for take the difference between those values and saved it in float variable ‘dy’

float dy=y2-y1; //Declarate decimal float variable dy. This is a math operation between 'y2' and 'y1' and stands for take
//the difference between those values and saved it in float variable 'dy'

After that, we need to declarate decimal float variable dsquare. This is a math operation between ‘dx’ and ‘dx’ and stands for take the summa between those square values and saved it in float variable ‘dsquare’

float dsquare=dx*dx+dy*dy; //Declarate decimal float variable dsquare. This is a math operation between 'dx' and 'dx' and stands for take
//the summa between those square values and saved it in float variable 'dsquare'

Next, we need to declarate decimal float variable result. This is a math operation between ‘dsquare’ and ‘result’ and stands for take the square root of dsquare and saved it in float variable ‘result’

float result=sqrt(dsquare); //Declarate decimal float variable result. This is a math operation between 'dsquare' and 'result' and
//stands for take the square root of dsquare and saved it in float variable 'result'

After that, With this command you return the value of the previus operations of «distance» function inside of the variable float total in order to call it in THE MAIN FUNCTION.

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

Finally, we the program comes back to the main function and 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 ()

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

5

This code for solution will be here and in Github:

Link in Github:quiz9.cpp

If you do not want the quiz9.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 distance (float x1, float y1,float x2, float y2) //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 "distance" and with float parameters a,b,c in order to
//have float results inside this function.
{

float dx=x2-x1; //Declarate decimal float variable dx. This is a math operation between 'x2' and 'x1' and stands for take
//the difference between those values and saved it in float variable 'dx'

float dy=y2-y1; //Declarate decimal float variable dy. This is a math operation between 'y2' and 'y1' and stands for take
//the difference between those values and saved it in float variable 'dy'

float dsquare=dx*dx+dy*dy; //Declarate decimal float variable dsquare. This is a math operation between 'dx' and 'dx' and stands for take
//the summa between those square values and saved it in float variable 'dsquare'

float result=sqrt(dsquare); //Declarate decimal float variable result. This is a math operation between 'dsquare' and 'result' and
//stands for take the square root of dsquare and saved it in float variable 'result'

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


}
int main() {



float x1,y1,x2,y2; //Declarate decimal float variables x1, y1, x2, y2 in order to send the values in the distance function


cout<<distance(0,0,4,3)<<endl;//This operation stands for an output of the values 0 0 4 3 to each parameter of the distance function


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 ()

}

#WSQ07 Lists 03/03/17 and WSQ07.cpp

#WSQ07 Lists 03/03/17 and WSQ07.cpp

PICTURE OF ACTOR

So in this eight week class I started with doing the survey of mid semester where I gave ideas in order to improve this course and this and this WSQ07. 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 and #Mastery18 Creation and use of Arrays/ Vectors in C++.

What I did for this numeric program is solving the problem to the user by writing a program that asks the user for 10 numbers  (floating point). Store those numbers in a list. Show to the user the total, average and standard deviation of those numbers.Futhermore, Once you have this working, change it so that users keep giving you values until they signal “no more values”. How would you implement this and in particular for the C++ group, how to you deal with an unknown size to your array during compilation?

The quantity of the value depends of the quantity of the type float variable that has only 32 bits of leght, therefore you need a new library in order to increase the value of numbers called Biginteger.hh but I am going to add it in the next WSQ08 called Yo soy 196. Next, to deal with an unknown size of my array during compilation we need to ask the user the number of that size and save it in a variable n.

The resources I need it to solve this program are here:

ken bauer

Similar code made by Eduardo Torres

C Programming Tutorial: Functions (Call By Value, Reference,passing Arrays to function)

The following photograph shows the solution to this problem:

wsq7v2

wsq7v3

wsq7v4wsq7v5

wsq7v6

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 and #WSQ06 Factorial Calculator 12/02/17 and WSQ06.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.

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.

#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

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


int main() //Begin of the program

After that I had to declarate int variables n and tam. Futhermore, I declarated a decimal variable called summa, averagefinal, standardfinal and list[tam]. This is where I am using the #Mastery18 Creation and use of Arrays/Vectors where I am declarating a float variable list as an array with a size of the variable tam because in an array you need to have a size in the variable. Futhermore, where you have to pass the array as a parameter, you have to write in this case float *list.

int n; //Declarate int variable n
int tam; //Declarate int variable tam
float summa; //Declarate decimal float variable summa
float averagefinal; //Declarate decimal float variable averagefinal
float standardfinal; //Declarate decimal float variable standardfinal
float list[tam]; //Declarate decimal float variable list[tam]. This is where I am using the #Mastery18 Creation and use of Arrays/Vectors
//where I am declarating a float variable list as an array with a size of the variable tam because in an array you need to have a size in
//the variable. Futhermore, where you have to pass the array as a parameter, you have to write in this case float *list .

Next, I use the #WSQ7 command of out data in form of text. This is to ask the user to give
for the number of the elements in the array. Therefore, this is the unknown size

cout<<"Give me the number of the elements in the array:"; //#WSQ5 command of out data in form of text. This is to ask the user to give
//for the number of the elements in the array.

After that I need this command allows enter data for inputs. In this case this enters the value of variable ‘n’

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

After that, I need THIS ASSIGNATION HELPS TO CALL THE FUNCTION OF «numbertotal» TO MAKE THE TASK OF THE total VALUE OF THE NUMBER WITH THE HELP OF THE VARIABLE float ‘summa’ with the parameters n and list (array) #Mastery06 and #Mastery07.

summa=numbertotal(n,list);//THIS ASSIGNATION HELPS TO CALL THE FUNCTION OF "numbertotal" TO MAKE THE TASK OF
//THE total VALUE OF THE NUMBER WITH THE HELP OF THE VARIABLE float 'summa' with the parameters n and list (array) #Mastery06 and
//#Mastery07

After this last action, the program escapes from the main function to the float numbertotal in order to make the task of the total value of the numbers with the help of the float and int variable where one is an array. 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 «numbertotal» and with int parameter n,and float parameter *list where I am using the #Mastery18 Creation and use of Arrays/Vectors in C++ in order to have float results inside this function. Therefore, I am using the array in order to save each number entered by the user with combining it with a loop.


float numbertotal(int n, float *list) //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 "numbertotal" and with int parameter n,and float parameter
//*list where I am using the #Mastery18 Creation and use of Arrays/Vectors in C++ in order to have float results inside this function.
//Therefore, I am using the array in order to save each number entered by the user with combining it with a loop.

Next, Inside of the float function ‘numbertotal’ I have to declarate decimal variable total initialized in 0. (This is a local variable).

float total=0; //Declarate decimal variable total initialized in 0.

Futhermore, I need a #Mastery14 use of loops with for. 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 n while it is increasing one in one in this variable i inicialized from the value 1. This is FOR repiting all the statements n times.

for(int i=1; i<=n; 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 n while it is increasing one in one in this variable i
//inicialized from the value 1

Moreover, you need a command of out data in form of text. In this text we show the authentic output of the value entered of i in the terminal interface #MasteryTopic04 and we show the user each numer given depending on n.

cout<<"Give me "<< i <<" float number:"; //command of out data in form of text
//In this text we show the authentic output of the value entered of i in the terminal interface #MasteryTopic04

Next, Inside of this function we need this command that allows enter data for inputs. In this case this enters the value of variable list[i where this i is the space of each value entered by the user from 1 to n I am using the #Mastery18 Creation and use of Arrays/Vectors in C++ ]

cin>>list[i]; // This command allows enter data for inputs. In this case this enters the
//value of variable list[i where this i is the space of each value entered by the user from 1 to n I am using the #Mastery18
//Creation and use of Arrays/Vectors in C++ ]

Then, In this instruction of the for loop, it tells we have an accumulator that tells the value of the variable total plus the variable list[i where this i is the space of each value entered by the user from 1 to n I am using the #Mastery18 Creation and use of Arrays/Vectors in C++ ] is given to the variable total. In this case we have a variable whose function is save the value of the operation list until the loop for finishes with all the total of integers in the range you provide saved in variable total.

total=total+list[i];//In this instruction of the for loop, it tells we have an accumulator that tells the value of
//the variable total plus the variable list[i where this i is the space of each value entered by the user from 1 to n I am
//using the #Mastery18 Creation and use of Arrays/Vectors in C++ ] is given to the variable total. In this case we
//have a variable whose function is save the value of the operation list until the loop
//for finishes with all the total of integers in the range you provide saved in variable total

After that we have a return statement. With this command you return the value of the previus operations of «numbertotal» function inside of the variable float total in order to call it in THE MAIN FUNCTION.

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

Next, the program goes back to the main function and I need a command of out data in form of text. In this text we show the authentic output of the value entered of summa in the terminal interface #MasteryTopic04.

cout<<"The total of the numbers is: "<<summa<<endl; //command of out data in form of text
//In this text we show the authentic output of the value entered of summa in the terminal interface #MasteryTopic04

After that, we need THIS ASSIGNATION that HELPS TO CALL THE FUNCTION OF «averageofnumbers» TO MAKE THE TASK OF THE average VALUE OF THE NUMBER WITH THE HELP OF THE VARIABLE float ‘averagefinal’ with the parameters n and summa #Mastery06 and #Mastery07.

After this last action, the program escapes from the main function to the float ‘averageofnumbers’ in order to make the task of the average value of the numbers with the help of the float and int variable. 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 «averageofnumbers» and with float parameter summa and int parameter n in order to have float results inside this function.

float averageofnumbers(float summa, 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 "averageofnumbers" and with float parameter summa and int parameter
//n in order to have float results inside this function.

Inside of the float function ‘averageofnumbers’ I have to declarate a decimal variable average. (This is a local variable).

float average; //Declarate decimal variable average

Next, we need to use this math operation between ‘summa’ and ‘n’ and stands for do the division between those values and saved it in float variable ‘average’

average=(summa)/n; //This is a math operation between 'summa' and 'n' and stands for do the division between
//those values and saved it in float variable 'average'

After that, we have a return statement. With this command you return the value of the previus operations of «averageofnumbers» function inside of the variable float average in order to call it in THE MAIN FUNCTION.

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

Next, the program goes back to the main function and I need a command of out data in form of text. In this text we show the authentic output of the value entered of averagefinal in the terminal interface #MasteryTopic04

cout<<"The average of the numbers is: "<<averagefinal<<endl; //command of out data in form of text
//In this text we show the authentic output of the value entered of averagefinal in the terminal interface #MasteryTopic04

Then, we have THIS ASSIGNATION HELPS TO CALL THE FUNCTION OF «standarddop» TO MAKE THE TASK OF THE standard deviation VALUE OF THE NUMBER WITH THE HELP OF THE VARIABLE float ‘standardfinal’ with the parameters list (array) averagefinal and n #Mastery06 and #Mastery07.

 standardfinal=standardop(list,averagefinal,n); //THIS ASSIGNATION HELPS TO CALL THE FUNCTION OF "standarddop" TO MAKE THE TASK OF
//THE standard deviation VALUE OF THE NUMBER WITH THE HELP OF THE VARIABLE float 'standardfinal' with the parameters list (array)
// averagefinal and n #Mastery06 and #Mastery07

After this last action, the program escapes from the main function to the float numbertotal in order to make the task of the total value of the numbers with the help of the float and int variable where one is an array.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 «standardop» and with int parameter n,and float parameter *list where I am using the #Mastery18 Creation and use of Arrays/Vectors in C++ in order to have float results inside this function. Therefore, I am using the array in order to save each number entered by the user with combining it with a loop.

float standardop(float *list,float averagefinal, 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 "standardop" and with int parameter n,and float parameter
//*list where I am using the #Mastery18 Creation and use of Arrays/Vectors in C++ in order to have float results inside this function.
//Therefore, I am using the array in order to save each number entered by the user with combining it with a loop.

Inside of the float function ‘standardop’ I have to declarate decimal variable prevariance initialized in 0. (This is a local variable).

Next, Inside of the float function ‘standardop’ I have to declarate decimal variable variance. (This is a local variable).

Next, Inside of the float function ‘standardop’ I have to declarate decimal variable standard. (This is a local variable).

float standardop(float *list,float averagefinal, 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 "standardop" and with int parameter n,and float parameter
//*list where I am using the #Mastery18 Creation and use of Arrays/Vectors in C++ in order to have float results inside this function.
//Therefore, I am using the array in order to save each number entered by the user with combining it with a loop.
{
float prevariance=0; //Declarate decimal variable prevariance initialized in 0.
float variance; //Declarate decimal variable variance
float standard; //Declarate decimal variable standard

Futhermore, I need a #Mastery14 use of loops with for. 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 n while it is increasing one in one in this variable i inicialized from the value 0. This is for repeting all the statements n times.

for(int i=1; i<=n; 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 n while it is increasing one in one in this variable i
//inicialized from the value 0

Inside of the for loop we nees This math operation between ‘prevariance’ and ‘list[i where this i is the space of each value entered by the user from 1 to n I am using the #Mastery18 Creation and use of Arrays/Vectors in C++]’ and stands for do the summa between those values where in the part of the list[i] you have to make de difference with the average final and elevated to power 2 and saved it in float variable ‘prevariance’. This is part of the formula to calculate the standar deviation formula that I saw in this link.

s1

s2

s3

s4

Link of the page


prevariance =prevariance + ((list[i]-averagefinal))*((list[i]-averagefinal)); //This is a math operation between 'prevariance' and
//'list[i where this i is the space of each value entered by the user from 1 to n I am
//using the #Mastery18 Creation and use of Arrays/Vectors in C++]' and stands for do the summa between
//those values and saved it in float variable 'prevariance'


After that, we need this is math operation between ‘prevariance’ and ‘n’ and stands for do the division between those values and saved it in float variable ‘variance’

variance=(prevariance)/n; //This is a math operation between 'prevariance' and 'n' and stands for do the division between
//those values and saved it in float variable 'variance'

Then, we nees this  math operation between ‘standard’ and ‘variance’ and stands for do the square root between those values and saved it in float variable ‘standard’

standard=sqrt(variance); //This is a math operation between 'standard' and 'variance' and stands for do the square root between
//those values and saved it in float variable 'standard'

Finally, we have a return statement. With this command you return the value of the previus operations of «standardop» function inside of the variable float standard in order to call it in THE MAIN FUNCTION.

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

Next, the program goes back to the main function and I need a command of out data in form of text. In this text we show the authentic output of the value entered of standardfinal in the terminal interface #MasteryTopic04

cout<<"The standard deviation of those numbers is: "<<standardfinal<<endl; //command of out data in form of text
//In this text we show the authentic output of the value entered of standardfinal in the terminal interface #MasteryTopic04

And i also resolved it by doing this video tutorial that i made reafirming these parts at this link :#WSQ07 Eight Tutorial Lists 03/03/17 and WSQ07.cpp

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

s5

This code for solution will be here and in Github:

Link in Github:WSQ07.cpp

If you do not want the WSQ07.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 numbertotal(int n, float *list) //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 "numbertotal" and with int parameter n,and float parameter
//*list where I am using the #Mastery18 Creation and use of Arrays/Vectors in C++ in order to have float results inside this function.
//Therefore, I am using the array in order to save each number entered by the user with combining it with a loop.
{
float total=0; //Declarate decimal variable total initialized in 0.

for(int i=1; i<=n; 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 n while it is increasing one in one in this variable i
//inicialized from the value 1
{
cout<<"Give me "<< i <<" float number:"; //command of out data in form of text
//In this text we show the authentic output of the value entered of i in the terminal interface #MasteryTopic04
cin>>list[i]; // This command allows enter data for inputs. In this case this enters the
//value of variable list[i where this i is the space of each value entered by the user from 1 to n I am using the #Mastery18
//Creation and use of Arrays/Vectors in C++ ]

total=total+list[i];//In this instruction of the for loop, it tells we have an accumulator that tells the value of
//the variable total plus the variable list[i where this i is the space of each value entered by the user from 1 to n I am
//using the #Mastery18 Creation and use of Arrays/Vectors in C++ ] is given to the variable total. In this case we
//have a variable whose function is save the value of the operation list until the loop
//for finishes with all the total of integers in the range you provide saved in variable total
}

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

}


float averageofnumbers(float summa, 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 "averageofnumbers" and with float parameter summa and int parameter
//n in order to have float results inside this function.

{
float average; //Declarate decimal variable average
average=(summa)/n; //This is a math operation between 'summa' and 'n' and stands for do the division between
//those values and saved it in float variable 'average'

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


}

float standardop(float *list,float averagefinal, 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 "standardop" and with int parameter n,and float parameter
//*list where I am using the #Mastery18 Creation and use of Arrays/Vectors in C++ in order to have float results inside this function.
//Therefore, I am using the array in order to save each number entered by the user with combining it with a loop.
{
float prevariance=0; //Declarate decimal variable prevariance initialized in 0.
float variance; //Declarate decimal variable variance
float standard; //Declarate decimal variable standard

for(int i=1; i<=n; 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 n while it is increasing one in one in this variable i
//inicialized from the value 0
{
prevariance =prevariance + ((list[i]-averagefinal))*((list[i]-averagefinal)); //This is a math operation between 'prevariance' and
//'list[i where this i is the space of each value entered by the user from 1 to n I am
//using the #Mastery18 Creation and use of Arrays/Vectors in C++]' and stands for do the summa between
//those values and saved it in float variable 'prevariance'

}
variance=(prevariance)/n; //This is a math operation between 'prevariance' and 'n' and stands for do the division between
//those values and saved it in float variable 'variance'

standard=sqrt(variance); //This is a math operation between 'standard' and 'variance' and stands for do the square root between
//those values and saved it in float variable 'standard'


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

}


int main() //Begin of the program
{

int n; //Declarate int variable n
int tam; //Declarate int variable tam
float summa; //Declarate decimal float variable summa
float averagefinal; //Declarate decimal float variable averagefinal
float standardfinal; //Declarate decimal float variable standardfinal
float list[tam]; //Declarate decimal float variable list[tam]. This is where I am using the #Mastery18 Creation and use of Arrays/Vectors
//where I am declarating a float variable list as an array with a size of the variable tam because in an array you need to have a size in
//the variable. Futhermore, where you have to pass the array as a parameter, you have to write in this case float *list .


cout<<"Give me the number of the elements in the array:"; //#WSQ5 command of out data in form of text. This is to ask the user to give
//for the number of the elements in the array.
cin>>n; // This command allows enter data for inputs. In this case this enters the
//value of variable 'n'

summa=numbertotal(n,list);//THIS ASSIGNATION HELPS TO CALL THE FUNCTION OF "numbertotal" TO MAKE THE TASK OF
//THE total VALUE OF THE NUMBER WITH THE HELP OF THE VARIABLE float 'summa' with the parameters n and list (array) #Mastery06 and
//#Mastery07
cout<<"The total of the numbers is: "<<summa<<endl; //command of out data in form of text
//In this text we show the authentic output of the value entered of summa in the terminal interface #MasteryTopic04


averagefinal=averageofnumbers(summa,n);//THIS ASSIGNATION HELPS TO CALL THE FUNCTION OF "averageofnumbers" TO MAKE THE TASK OF
//THE average VALUE OF THE NUMBER WITH THE HELP OF THE VARIABLE float 'averagefinal' with the parameters n and summa #Mastery06 and
//#Mastery07
cout<<"The average of the numbers is: "<<averagefinal<<endl; //command of out data in form of text
//In this text we show the authentic output of the value entered of averagefinal in the terminal interface #MasteryTopic04

standardfinal=standardop(list,averagefinal,n); //THIS ASSIGNATION HELPS TO CALL THE FUNCTION OF "standarddop" TO MAKE THE TASK OF
//THE standard deviation VALUE OF THE NUMBER WITH THE HELP OF THE VARIABLE float 'standardfinal' with the parameters list (array)
// averagefinal and n #Mastery06 and #Mastery07
cout<<"The standard deviation of those numbers is: "<<standardfinal<<endl; //command of out data in form of text
//In this text we show the authentic output of the value entered of standardfinal in the terminal interface #MasteryTopic04




}

 

 

#Quiz08 See the algorithm of Fibonacci serie explained!

#Quiz08 See the algorithm of Fibonacci serie explained!

PICTURE OF AUTOR

THIS IS THE #QUIZ8 WHOSE OBJECTIVE IS CREATE AND CALL FUNCTIONS TO DO DIFFERENT TASKS AT DIFFERENT TIMES USING RECURSION AND LOOPS. COVERING #MASTERYTOPIC06 #MASTERYTOPIC07 . This IS ALSO to fulfill the #Mastery12 Use of recursion for repetitive algorithms

This #QUIZ08 makes first a survey where I gave some advice or feedback to ken bauer in how i am learning in this course. Next, in this quiz 8 makes a function that calculates  and returns the “nth” Fibonacci number where we define a function over the Fibonacci numbers mapping the naturals (starting with zero) to the Fibonacci series.

fibo2

Link of the picture:Link of the picture

So fibonacci(0) returns 0, fibonacci(1) returns 1, fibonacci(2) returns 1 and so on. Note that we are using the modern definition where the sequence starts with zero. I tried to implement this with two solutions: one with a loop and one with recursion. Which do I think is “better”, which looks more “elegant”, which is more “efficient”?

First let me show you the pictures of the quiz:

fibo3

fibo4fibo5

FIRST TO DO IN THIS #QUIZ08 with the recursion solution is writing a function called ‘fibonacci(int n)’ with an int parameter called n where this parameter is the value of the list in the serie.

Inside of this function, we have a condition a #Mastery10 use of the if statement. This command allows the condition if the value of n is equal to 0 or 1 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 or 1 this will occur:

return n; //With this command you return the value of the int variable n in order to show it in THE MAIN FUNCTION

return n; //With this command you return the value of the int variable n in order to show it in THE MAIN FUNCTION

After that, 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:

return fibonacci(n-2) + fibonacci(n-1);

With this command you return the value of the previus operations of «fibonacci» function inside the function where is decreasing the value of n by 2, plus the function where is jumping the value of n by 1each time that its called in order to call the fibonacci in THE MAIN FUNCTION .This is to fulfiled the #Mastery12 Use of recursion for repetitive algorithms.

if we assume that the these recursive calls work correctly, then it is clear that we get the right result by adding them together.

Next, The execution of fibonacci  in the main functions begins with n=0, and since n is zero, it outputs the value 0, and then calls itself from the main to increase the values of fibonacci’s serie 10 times with calling the function i times with cout<<fibonacci(i);.

for(int i=0; i<=10;i++)
{
cout<<fibonacci(i); //THIS ASSIGNATION HELPS TO CALL THE FUNCTION OF "fibonacci" TO MAKE THE CALL IN THE TASK OF
//THE fibonacci SERIE OF THE NUMBER WITH THE HELP OF THE COMAND I' #Mastery06 and #Mastery07
cout <<" "<< n;


}

FIRST TO DO IN THIS #QUIZ08 with the LOOP solution is writing a function called ‘fibonacciLoop(int n)’ with an int parameter called n where this parameter is the value of the list in the serie.

Inside of this loop function, we need to declarate 2 int variables in order to show the current value of n and to save in the other variable the last value that took n. So, the variables are n,nbackup and fibolop inialized in 1. First, we show the value of n that starts from zero, then I use my variable nbackup to save the current value of fibolop that is 1, so now nbackup has the value of 1, next I need to change the value of fibolop into fibolop=fibolop+n; plus the value of n, so now fibolop has the value of 1 because right now n=0, next we give n=nbackup; the value of nbackup to n, so n now has the value of n=1, next it shows the value 1 and then I use my variable nbackup to save the current value of fibolop that is 1, so nbackup=1, next we have to change the value of fibolop into fibolop=fibolop+n; plus the value of n, that will be fibolop=2 because right now n=1, then I give the value of n=nbackup, so n is n=1 because right now nbackup=1, next it shows the value 1 in the list, then we use my variable nbackup to save the current value of fibolop that is 2, so nbackup=2;, next  I need to change the value of fibolop into fibolop=fibolop+n; plus the value of n, that would be 2+1=3 because n right now is n=1 so fibolop is fibolop=3. After that, I give the value of nbackup=2 to n, so n now has the value n=2 we would have something like this

0,1,1,2

Next, I give nbackup the value of the current value of fibolop, if at this moment fibolop=3 then nbackup is 3 nbackup=3, then I change the value of fibolop into fibolop=fibolop+n; plus the value of n, that will be fibolop=3+2=5 because at this moment n=2, next I need to give the current value of nbackup=3 to n, so n has the value of n=3 we would have something like this after showing the current value of n=3

0,1,1,2,3

Next, I give the number of the current fibolop to the variable nbackup, nbackup=fibolop, so at this moment now fibolop is fibolop=5 so nbackup has a current value of nbackup=5, next I need to change the value of fibolop into fibolop=fibolop+n; plus the value of n, that will be fibolop=5+3=8 because n is n=3 in this moment, next n now changes because I give the value of nbackup=5 to n, so now n has the value of n=5 we would have something like this after showing the current value of n=5

0,1,1,2,3,5

Next, I give the number of the current value of fibolop to the variable nbackup, nbackup=fibolop, so at this moment now nbackup=8, next I need to change the value of fibolop into fibolop=fibolop+n; plus the value of n, that will be fibolop=8+5=13  because n is n=5 in this moment, next n now changes because I give the value of nbackup=8 to n, so now n is n=8 we would have something like this after showing the current value of n=8

0,1,1,2,3,5,8

Next I give the value of nbackup the value of the greatest value of fibolop=13 to the variable nbakup=13 because nbackup=fibolop, next I need to change the value of fibolop into fibolop=fibolop+n;plus the value of n, that will be fibolop=13+8=21 because n is n=8 in this moment, next n now changes because I give the value of nbackup=13 to n, so now n is n=13 we would have something like this after showing the current value of n=8

0,1,1,2,3,5,8,13

Next I give the value of nbackup the value of the greatest fibolop to the value nbackup because nbackup=fibolop, so now nbackup=21 because currently fibolop is=21, next fibolop will change and I need to change the value of fibolop into fibolop=fibolop+n;plus the value of n,that will be fibolop=21+13=34 because n at this moment is n=13, next n now changes because I give the value of nbackup=21 to n, so now n is n=21, we would have something like this after showing the current value of n=21

0,1,1,2,3,5,8,13,21

So fibolop is always in front of n, fibolop has the greatest value and we need to save this value in another and print it after of showing the last values of the serie.If you change the order of the operations, the serie WILL NOT WORK.

REMEMBER that all these operations will execute the number of times that the loops says And these instructions are happening at the begining of the program until the loop finishes.

Which do you think is “better”, which looks more “elegant”, which is more “efficient”?

I think is “better” the recursive soultion because it saves memory and space rather than using a loop. In the loop solution you need to declarate 3 variables more than the recursive solution. Therefore, the recursive solutions has less operations because you just call the function the number of times to the definition of fibonacci series

fibonacci(0) = 1
fibonacci(1) = 1
fibonacci(n) = fibonacci(n − 1) + fibonacci(n − 2);

Futhermore, the more “elegant” is the recursive solution because it is more elegant to have your main program and just called it to do the task and just printed and in the loop solution you need to declarate more variables which can be more code and does not appear more elegant.

Futhermore, the more “efficient” solution is the recursive solution because it is more efficient to have your main program and just called it to do the task and just printed and in the loop solution you need to declarate more variables which can be more code and does not appear more efficient. Therefore, In this part you need to have in the main function the number of times that the operation is called and in the loop solution you have a more restricted condition in the loop to be repeated.

LINK OF THE CODE IN GITHUB: quiz8.cpp

ALSO THE CODE IS HERE:

#include <iostream>//Library to call all the
//fuctions of inputs and outputs 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

int fibonacciLoop(int n){ //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 "fibonacciLoop" and with int parameter n in order to
//have int results inside this function.
n=0; // This command allows giving the value of the parameter 'n' to 0

int fibolop=1;
int nbackup;
// 0,1,1,2,3,5,8,13,21
for(int i=0; i<=10; 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 10 while it is increasing one in one in this variable i
//inicialized from the value 0
{
cout<<" "; //comand of out data in form of text space
cout<<n; // This command allows enter data for inputs. In this case this enters the
//value of variable 'n'

nbackup=fibolop; //before this operation, the value of fibolop won't increase until this next operation, RIGHT NOW IT stays fibolop=1

fibolop=fibolop+n;

n=nbackup;

}


}

int fibonacci(int n){ //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 "fibonacci" and with int parameter n in order to
//have int results inside this function.
if(n==0||n==1){ //#Mastery10 use of the if statement //This command allows the condition if the value of n
//is equal to 0 or 1 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 or 1 this will occur:
return n; //With this command you return the value of the int variable n in order to show it in THE MAIN FUNCTION

} else { //#Mastery11 Use of else with a conditional if: // if the condition does not achieve on the other hand you will do this:
return fibonacci(n-2) + fibonacci(n-1); //With this command you return the value of the previus operations of "fibonacci" function
//inside the function where is decreasing the value of n by 2, plus the function where is jumping the value of n by 1
// each time that its called in order to callthe fibonacci in THE MAIN FUNCTION .This to fulfiled the #Mastery12 Use of recursion
//for repetitive algorithms
}
}



int main()
{

int n;
int fibolop;

fibolop=fibonacciLoop(n); //THIS ASSIGNATION HELPS TO CALL THE FUNCTION OF "fibonacciLoop" TO MAKE THE TASK OF
//THE fibonacci SERIE OF THE NUMBER WITH THE HELP OF THE VARIABLE int 'fibolop' #Mastery06 and #Mastery07


cout<<endl;

for(int i=0; i<=10;i++)
{
cout<<fibonacci(i); //THIS ASSIGNATION HELPS TO CALL THE FUNCTION OF "fibonacci" TO MAKE THE CALL IN THE TASK OF
//THE fibonacci SERIE OF THE NUMBER WITH THE HELP OF THE COMAND I' #Mastery06 and #Mastery07
cout <<" "<< n;


}

cout<<endl;


return 0;
}

1st Parcial Feedback How Am I doing so far in the course?

1st Parcial Feedback How Am I doing so far in the course?

So far in this partial I am doing fine but I need to mantain all my hard work constant in order to be great in the next months. Therefore, I can mantain my 100.

In the exam in the first exercise I just needed the command return 0; and in the other exercise it wasn’t neccesary to write the main function.

The following images show the exam:

20170223_09112820170223_09112820170223_09113820170223_09121120170223_091242

 

LET’S CODE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

#WSQ06 Factorial Calculator 12/02/17 and WSQ06.cpp

#WSQ06 Factorial Calculator 12/02/17 and WSQ06.cpp

Link of the picture: Link of the picture

So in this seven week class I started with doing the Computing for Social Good!!! and this WSQ06. Therefore, I started reviewing in creating and calling functions in C++. #Mastery06, #Mastery07, #Mastery16 Use of recursion for repetitive algorithms and #Mastery17 When to use what type of repetition in a program

What I did for this numeric program is solving the problem to the user by writing a program that asks the user for a non-negative integer (let’s call that number n) and display for them the value of n! (n factorial).

After showing them the answer, ask them if they would like to try another number (with a simple Y/N response) and either ask again (for Y) or quit the program and wish them a nice day (if they answered N).

Moreover, you need to have  two basic approaches: a loop with an accumulator of the multiplication and a recursive solution. Choose one and implement that. Once that is done, try the other way.

If you used a while loop for the solution with a loop, try structuring this with a for loop (or vice-versa). Therefore, I am going to show you the 2 solutions in order to accomplish the the masteries regarding recursion. #Mastery16 and #Mastery17

The resources I need it to solve this program with the loop algorithm are here:

Similar code made by Xochitl96

The resources I need it to solve this program with the recursion solution and accomplish #Mastery16 Use of recursion for repetitive algorithms an #Mastery17 When to use what type of repetition in a program are here:

Similar code made by Gonzalomata22

The following photograph shows the solution to this problem:

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 and #WSQ05 Six Tutorial On To Functions 12/02/17 and WSQ05.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.

First solution of the program using a loop accumulator:

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.

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.

#include <iostream> //Library to call all the
//fuctions of inputs and outputs 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

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

int main () //Begin of the program

After that I had to declarate int variables n and factorial. Futhermore, I declarated a char variable called res and gave him a value of ‘Y’ because I wanted to make the condition to ask the user to give in the program a letter to still repeating the task of the main program which is giving to the user a new factorial number.

int n,factorial; //Declarate integer variables
char res='Y'; //Declarate char variable in form of letter

Next I use the #Mastery14 use of loops with for. 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 res equals to the value ‘Y’

//#Mastery14 use of loops with for
for(;res=='Y';) //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 res
// will be equal to 'Y'
{
cout<<"Give me a non-negative integer in order to tell you n!:"; //#WSQ5 command of out data in form of text
cin>>n; // This command allows enter data for inputs. In this case this enters the
//value of variable 'n'
if(n>=0) //#Mastery10 use of the if statement //This command allows the condition if the value of n
//is higher or 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 higher or equal than 0 this will occur:
{



factorial=factorialfunction(n,factorial); //THIS ASSIGNATION HELPS TO CALL THE FUNCTION OF "factorialfunction" TO MAKE THE TASK OF
//THE factorial VALUE OF THE NUMBER WITH THE HELP OF THE VARIABLE int 'factorial' #Mastery06 and #Mastery07

cout<<endl; //comand of out data in form of text space
cout<<"The n! of your number is "<<n<<"!="<<factorial<<endl; //command of out data in form of text
//In this text we show the authentic output of the value entered of n and factorial in the terminal interface #MasteryTopic04
cout<<endl; //comand of out data in form of text space

}

cout<<"Would you like to try another number for n! (Y=YES/ N=NO)?:"; //command of out data in form of text, in this case it tells
//the user to give an input in form of text Y or N
cin>>res; // This command allows enter data for inputs. In this case this enters the
//value of variable 'res'


} //END OF FOR

Inside of the FOR I have an instruction of the for loop, it tells a #WSQ6 command of out data in form of text to tell the user to give a non-negative integer in order to tell you the factorial n!

  cout<<"Give me a non-negative integer in order to tell you n!:"; //#WSQ6 command of out data in form of text

Next I need  This command that allows enter data for inputs. In this case this enters the value of variable ‘n’ in order to calculate n!

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

After I use the #Mastery10 use of the if statement. This command allows the condition if the value of nis higher or 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 higher or equal than 0 this will occur (Task of n!):

if(n>=0) //#Mastery10 use of the if statement //This command allows the condition if the value of n
//is higher or 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 higher or equal than 0 this will occur:
{



factorial=factorialfunction(n,factorial); //THIS ASSIGNATION HELPS TO CALL THE FUNCTION OF "factorialfunction" TO MAKE THE TASK OF
//THE factorial VALUE OF THE NUMBER WITH THE HELP OF THE VARIABLE int 'factorial' #Mastery06 and #Mastery07

cout<<endl; //comand of out data in form of text space
cout<<"The n! of your number is "<<n<<"!="<<factorial<<endl; //command of out data in form of text
//In this text we show the authentic output of the value entered of n and factorial in the terminal interface #MasteryTopic04
cout<<endl; //comand of out data in form of text space

}

After that, I need the #Mastery06 and #Mastery07 to create and call the first function of the factorial of the number with writing an assignation. THIS ASSIGNATION HELPS TO CALL THE FUNCTION OF «factorialfunction» TO MAKE THE TASK OF THE factorial VALUE OF THE NUMBER WITH THE HELP OF THE VARIABLE int ‘factorial’ #Mastery06 and #Mastery07

factorial=factorialfunction(n,factorial); //THIS ASSIGNATION HELPS TO CALL THE FUNCTION OF "factorialfunction" TO MAKE THE TASK OF
//THE factorial VALUE OF THE NUMBER WITH THE HELP OF THE VARIABLE int 'factorial' #Mastery06 and #Mastery07

After this last action, the program escapes from the main function to the int factorialfunction in order to make the task of the factorial value of the numbers with the help of the int variables. This is the structure of a function where you have subrutines in order to make different tasks, in this case we have a int function with the name “factorialfunction” and with int parameters ‘n’ and ‘factorial’ in order to have int results inside this function.

int factorialfunction(int n, int factorial) //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 "factorialfunction" and with int parameters n,factorial in order to
//have int results inside this function.

Next, Inside of the int function ‘factorialfunction’ I have a #Mastery14 use of loops with for. 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 n while it is increasing one in one in this variable i inicialized from the value 0

for(int i=0; i<=n; 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 n while it is increasing one in one in this variable i
//inicialized from the value 0

Next in the for I use a #Mastery10 use of the if statement. This command allows the condition if the value of i 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 i is equal than 0 this will occur:

if (i==0) //#Mastery10 use of the if statement //This command allows the condition if the value of i
//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 i is equal than 0 this will occur:
{
factorial=1; //In this instruction of the for loop, it tells that the value 1 is given
//to the variable factorial because this is an accumulator to start the operation of factorial in 0!=1
}

else //#Mastery11 Use of else with a conditional if: // if the condition does not achieve on the other hand you will do this:
{
factorial = (factorial*i); //In this instruction of the for loop, it tells that the value of the variable factorial times i is given
//to the variable factorial

}

Next, in the if a I have this instruction of the for loop, it tells that the value 1 is given to the variable factorial because this is an accumulator to start the operation of factorial in 0!=1

factorial=1; //In this instruction of the for loop, it tells that the value 1 is given
//to the variable factorial because this is an accumulator to start the operation of factorial in 0!=1

After that the if statement finishes and then 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:
{
factorial = (factorial*i); //In this instruction of the for loop, it tells that the value of the variable factorial times i is given
//to the variable factorial

}

Inside the else statement we have a math operation. In this instruction of the for loop, it tells that the value of the variable factorial times i is given to the variable factorial.

factorial = (factorial*i); //In this instruction of the for loop, it tells that the value of the variable factorial times i is given
//to the variable factorial

After that last statement the loop for finishes and inside of the int function I have a return statement. This statement helps the program going back to the main function in order to show the value of the ‘factorialfunction’ function that would be the value of the int variable factorial.With this command you return the value of the previus operations of «factorialfunction» function inside of the variable int factorial in order to call it in THE MAIN FUNCTION

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

Next, the program goes back to the main function and a command of out data in form of text space

cout<<endl; //comand of out data in form of text space

Next, I need to use the command of out data in form of text. In this text we show the authentic output of the value entered of n and factorial in the terminal interface #MasteryTopic04

cout<<"The n! of your number is "<<n<<"!="<<factorial<<endl; //command of out data in form of text
//In this text we show the authentic output of the value entered of n and factorial in the terminal interface #MasteryTopic04

After that I use a comand of out data in form of text space

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

Next In this moment the if condition finishes and I need to use a command of out data in form of text, in this case it tells the user to give an input in form of text Y or N in order to answer the question of trying another number n to calculate n!

cout<<"Would you like to try another number for n! (Y=YES/ N=NO)?:"; //command of out data in form of text, in this case it tells
//the user to give an input in form of text Y or N

After that I need this command that allows enter data for inputs. In this case this enters the value of variable ‘res’. After this statement the for loop asks if the value res was indeed ‘Y’ if its not, the loop breaks and we continue with the other statements of the program.

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

At this time I END the FOR statement and I need a comand of out data in form of text space

cout<<endl; //comand of out data in form of text space

Finally we have a command of out data in form of text, in this case it tells the user to tell the user to have a nice day and make the END OF THE PROGRAM

cout<<"We wish you a nice day!!!!!!"<<endl; //command of out data in form of text, in this case it tells
//the user to tell the user to have a nice day





}//END OF THE PROGRAM

The following pictures shows the code of this first program:

11

12

13

14

And i also resolved it by doing this video tutorial that i made reafirming these parts at this link : #WSQ06 Seven Tutorial Factorial Calculator 12/02/17

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

fact

This code for solutin 1 will be here and in Github:

Link in Github:WSQ6.cpp solution with for loop

If you do not want the  WSQ6.cpp solution with for loop 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

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 factorialfunction(int n, int factorial) //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 "factorialfunction" and with int parameters n,factorial in order to
//have int results inside this function.
{
for(int i=0; i<=n; 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 n while it is increasing one in one in this variable i
//inicialized from the value 0
{
if (i==0) //#Mastery10 use of the if statement //This command allows the condition if the value of i
//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 i is equal than 0 this will occur:
{
factorial=1; //In this instruction of the for loop, it tells that the value 1 is given
//to the variable factorial because this is an accumulator to start the operation of factorial in 0!=1
}

else //#Mastery11 Use of else with a conditional if: // if the condition does not achieve on the other hand you will do this:
{
factorial = (factorial*i); //In this instruction of the for loop, it tells that the value of the variable factorial times i is given
//to the variable factorial

}




}//end of FOR
return factorial; //With this command you return the value of the previus operations of "factorialfunction" function inside of the
//variable int factorial in order to call it in THE MAIN FUNCTION

}



int main () //Begin of the program

{
int n,factorial; //Declarate integer variables
char res='Y'; //Declarate char variable in form of letter

//#Mastery14 use of loops with for
for(;res=='Y';) //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 res
// will be equal to 'Y'
{
cout<<"Give me a non-negative integer in order to tell you n!:"; //#WSQ5 command of out data in form of text
cin>>n; // This command allows enter data for inputs. In this case this enters the
//value of variable 'n'
if(n>=0) //#Mastery10 use of the if statement //This command allows the condition if the value of n
//is higher or 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 higher or equal than 0 this will occur:
{



factorial=factorialfunction(n,factorial); //THIS ASSIGNATION HELPS TO CALL THE FUNCTION OF "factorialfunction" TO MAKE THE TASK OF
//THE factorial VALUE OF THE NUMBER WITH THE HELP OF THE VARIABLE int 'factorial' #Mastery06 and #Mastery07

cout<<endl; //comand of out data in form of text space
cout<<"The n! of your number is "<<n<<"!="<<factorial<<endl; //command of out data in form of text
//In this text we show the authentic output of the value entered of n and factorial in the terminal interface #MasteryTopic04
cout<<endl; //comand of out data in form of text space

}

cout<<"Would you like to try another number for n! (Y=YES/ N=NO)?:"; //command of out data in form of text, in this case it tells
//the user to give an input in form of text Y or N
cin>>res; // This command allows enter data for inputs. In this case this enters the
//value of variable 'res'


} //END OF FOR

cout<<endl; //comand of out data in form of text space
cout<<"We wish you a nice day!!!!!!"<<endl; //command of out data in form of text, in this case it tells
//the user to tell the user to have a nice day





}//END OF THE PROGRAM

Second solution of the program using a solution and fulfilled with #Mastery16 Use of recursion for repetitive algorithms and #Mastery17 When to use what type of repetition in a program because in the needs you have to solve a problem is the type of repetition that I need. If I want to do a task outside of a function, I will use the recursion solution better that the loop solution because I can do other tasks each time that I could called the function and in the loop not. But If in my program I need a value saved in accumulator, the best thing to use will be a loop accumulator:

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.

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.


#include <iostream> //Library to call all the
//fuctions of inputs and outputs 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

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


int main () //Begin of the program

After that I had to declarate int variables n and factorialfinal. Futhermore, I declarated a char variable called res and gave him a value of ‘Y’ because I wanted to make the condition to ask the user to give in the program a letter to still repeating the task of the main program which is giving to the user a new factorial number.

int n,factorialfinal; //Declarate integer variables
char res='Y'; //Declarate char variable in form of letter

Next I use the #Mastery14 use of loops with while. 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 variable res equals to the value ‘Y’

//#Mastery14 use of loops with while
while(res=='Y') //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 variable res
// will be equal to 'Y'
{
cout<<"Give me a non-negative integer in order to tell you n!:"; //#WSQ5 command of out data in form of text
cin>>n; // This command allows enter data for inputs. In this case this enters the
//value of variable 'n'
if(n>=0) //#Mastery10 use of the if statement //This command allows the condition if the value of n
//is higher or 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 higher or equal than 0 this will occur:
{



factorialfinal=factorial(n); //THIS ASSIGNATION HELPS TO CALL THE FUNCTION OF "factorial" TO MAKE THE TASK OF
//THE factorial VALUE OF THE NUMBER WITH THE HELP OF THE VARIABLE int 'factorialfinal' #Mastery06 and #Mastery07

cout<<endl; //comand of out data in form of text space
cout<<"The n! of your number is "<<n<<"!="<<factorialfinal<<endl; //command of out data in form of text
//In this text we show the authentic output of the value entered of n and factorialfinal in the terminal interface #MasteryTopic04
cout<<endl; //comand of out data in form of text space

}

cout<<"Would you like to try another number for n! (Y=YES/ N=NO)?:"; //command of out data in form of text, in this case it tells
//the user to give an input in form of text Y or N
cin>>res; // This command allows enter data for inputs. In this case this enters the
//value of variable 'res'


} //END OF WHILE

Inside of the WHILE I have an instruction of the for loop, it tells a #WSQ6 command of out data in form of text to tell the user to give a non-negative integer in order to tell you the factorial n!

cout<<"Give me a non-negative integer in order to tell you n!:"; //#WSQ6 command of out data in form of text

 

Next I need  This command that allows enter data for inputs. In this case this enters the value of variable ‘n’ in order to calculate n!

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

After I use the #Mastery10 use of the if statement. This command allows the condition if the value of nis higher or 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 higher or equal than 0 this will occur (Task of n!):

if(n>=0) //#Mastery10 use of the if statement //This command allows the condition if the value of n
//is higher or 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 higher or equal than 0 this will occur:
{



factorialfinal=factorial(n); //THIS ASSIGNATION HELPS TO CALL THE FUNCTION OF "factorial" TO MAKE THE TASK OF
//THE factorial VALUE OF THE NUMBER WITH THE HELP OF THE VARIABLE int 'factorialfinal' #Mastery06 and #Mastery07

cout<<endl; //comand of out data in form of text space
cout<<"The n! of your number is "<<n<<"!="<<factorialfinal<<endl; //command of out data in form of text
//In this text we show the authentic output of the value entered of n and factorialfinal in the terminal interface #MasteryTopic04
cout<<endl; //comand of out data in form of text space

}

After that, Inside of the if statement I need the #Mastery06 and #Mastery07 to create and call the first function of the factorial of the number with writing an assignation. THIS ASSIGNATION HELPS TO CALL THE FUNCTION OF «factorialfunction» TO MAKE THE TASK OF THE factorial VALUE OF THE NUMBER WITH THE HELP OF THE VARIABLE int ‘factorial’ #Mastery06 and #Mastery07

factorialfinal=factorial(n); //THIS ASSIGNATION HELPS TO CALL THE FUNCTION OF "factorial" TO MAKE THE TASK OF
//THE factorial VALUE OF THE NUMBER WITH THE HELP OF THE VARIABLE int 'factorialfinal' #Mastery06 and #Mastery07

After this last action, the program escapes from the main function to the int factorialfunction in order to make the task of the factorial value of the number with the help of the int variable. This is the structure of a function where you have subrutines in order to make different tasks, in this case we have a int function with the name “factorial” and with int parameters ‘n’  in order to have int result inside this function.

int 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 aN INT function with the name "factorialfunction" and with int parameters n,factorial in order to
//have int results inside this function.

Next, Inside of the int function ‘factorial’ I have a #Mastery10 use of the if statement. This command allows the condition if the value of i 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 i 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 i
//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 i is equal than 0 this will occur:
{
return 1; //In this instruction of the if statement, it tells that the value 1 is given
//to the variable factorial because this is an accumulator to start the operation of factorial in 0!=1
}

After that, Inside of the if statement I need a RETURN statement. In this instruction of the for loop, it tells that the value 1 is given to the variable factorial because this is an accumulator to start the operation of factorial in 0!=1

return 1; //In this instruction of the for loop, it tells that the value 1 is given
//to the variable factorial because this is an accumulator to start the operation of factorial in 0!=1

Next at this moment the if condition finishes and I have a return statement. This statement helps the program going back to the main function in order to show the value of the ‘factorial’ function that would be the value of the operation n times the current value of the factorial function -1 that would be n!. This is the principle of using recursion to play operations with the functions #Mastery16 and #Mastery17

return n*factorial(n-1); //With this command you return the value of the previus operations of "factorial" function inside of the
//variable int n times the function where is decreasing the value of n by 1 each time that its called in order to call the factorial
// in THE MAIN FUNCTION .This to fulfiled the #Mastery12 Use of recursion for repetitive algorithms

Next, the program goes back to the main function and a command of out data in form of text space

cout<<endl; //comand of out data in form of text space

Next, I need to use the command of out data in form of text. In this text we show the authentic output of the value entered of n and factorial in the terminal interface #MasteryTopic04

cout<<"The n! of your number is "<<n<<"!="<<factorialfinal<<endl; //command of out data in form of text
//In this text we show the authentic output of the value entered of n and factorialfinal in the terminal interface #MasteryTopic04

Next In this moment the if condition finishes and has a command of out of data in form of text.In addition, I need to use a command of out data in form of text, in this case it tells the user to give an input in form of text Y or N in order to answer the question of trying another number n to calculate n!

cout<<"Would you like to try another number for n! (Y=YES/ N=NO)?:"; //command of out data in form of text, in this case it tells
//the user to give an input in form of text Y or N

After that I need this command that allows enter data for inputs. In this case this enters the value of variable ‘res’. After this statement the for loop asks if the value res was indeed ‘Y’ if its not, the loop breaks and we continue with the other statements of the program.

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

At this time I END the FOR statement and I need a comand of out data in form of text space

cout<<endl; //comand of out data in form of text space

Finally we have a command of out data in form of text, in this case it tells the user to tell the user to have a nice day and make the END OF THE PROGRAM

cout<<"We wish you a nice day!!!!!!"<<endl; //command of out data in form of text, in this case it tells
//the user to tell the user to have a nice day





}//END OF THE PROGRAM

The following pictures shows the code of this second program and accomplish #Mastery16 and #Mastery17:

30

31

32

And i also resolved it by doing this video tutorial that i made reafirming these parts at this link : #WSQ06 Seven Tutorial Factorial Calculator 12/02/17

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

33

This code for solution 2 will be here and in Github:

Link in Github:WSQ6.cpp with recursion

If you do not want the WSQ6.cpp with recursion 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

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 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 aN INT function with the name "factorialfunction" and with int parameters n,factorial 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 i
//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 i is equal than 0 this will occur:
{
return 1; //In this instruction of the for loop, it tells that the value 1 is given
//to the variable factorial because this is an accumulator to start the operation of factorial in 0!=1
}
return n*factorial(n-1); //With this command you return the value of the previus operations of "factorial" function inside of the
//variable int n times the function where is decreasing the value of n by 1 each time that its called in order to call the factorial
// in THE MAIN FUNCTION .This to fulfiled the #Mastery12 Use of recursion for repetitive algorithms



}



int main () //Begin of the program

{
int n,factorialfinal; //Declarate integer variables
char res='Y'; //Declarate char variable in form of letter

//#Mastery14 use of loops with while
while(res=='Y') //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 res
// will be equal to 'Y'
{
cout<<"Give me a non-negative integer in order to tell you n!:"; //#WSQ5 command of out data in form of text
cin>>n; // This command allows enter data for inputs. In this case this enters the
//value of variable 'n'
if(n>=0) //#Mastery10 use of the if statement //This command allows the condition if the value of n
//is higher or 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 higher or equal than 0 this will occur:
{



factorialfinal=factorial(n); //THIS ASSIGNATION HELPS TO CALL THE FUNCTION OF "factorial" TO MAKE THE TASK OF
//THE factorial VALUE OF THE NUMBER WITH THE HELP OF THE VARIABLE int 'factorialfinal' #Mastery06 and #Mastery07

cout<<endl; //comand of out data in form of text space
cout<<"The n! of your number is "<<n<<"!="<<factorialfinal<<endl; //command of out data in form of text
//In this text we show the authentic output of the value entered of n and factorialfinal in the terminal interface #MasteryTopic04
cout<<endl; //comand of out data in form of text space

}

cout<<"Would you like to try another number for n! (Y=YES/ N=NO)?:"; //command of out data in form of text, in this case it tells
//the user to give an input in form of text Y or N
cin>>res; // This command allows enter data for inputs. In this case this enters the
//value of variable 'res'


} //END OF FOR

cout<<endl; //comand of out data in form of text space
cout<<"We wish you a nice day!!!!!!"<<endl; //command of out data in form of text, in this case it tells
//the user to tell the user to have a nice day





}//END OF THE PROGRAM

Computing for Social Good!!!

Computing for Social Good!!!

Link of the picture: LINK OF THE PICTURE

Last week I helped this project of computing for social good by doing a first survey based on the presentation that the teacher gave us in the class about how computing can solve real problems that affect every type of community.

4 of the 6 problems I gave in the survey were:

Perhaps, having new apps for each class with games and you are winning points or diamonds in order to exchange those for quizzes or exams or homework or projects and making a decrease of stress among students. Therefore, you will have more healthy students in order to appreciate it more the learning path.

  1. In my family community I have the problem that I know a person that is on a wheel chair and I think computing can help this person by using an app that could control this person’s house such as controlling the lamps, the pump of the water and maybe the gas tank. Therefore you will make this person life easier.

2.In my family community I have the problem that I pay to much for my electricity, so computing can help in developing a software that could increase the power factor near to 1.

  1. In my global community I had the problem that I wasted so much time looking for a manual of CNC machinary where I found it boring and tedious to read all the manual to fix the alarms that the machine was facing. So the computing can help in doing interactive troubleshooting.

In the next part of this project, I will be chating in a video conference with a student from the Grant MacEwan University in order to discuss how computing can benefiate our communities.