TC1017 Course Review AND The Learning Pyramid

TC1017 Course Review AND The Learning Pyramid

Link of picture

learning-process

The aim of this post is to summarise the learning path to learn how to code in this course of solving problems with programming. In this course you need to have the values of discipline and creativity with willing to learn new things by yourself before you take this course that it is the model tec21. After that, you can take this course where you can feel satisfied after you do all the steps of the learning pyramid from reading the book of the course to TEACH ORDERS who probably don’t walk through the path either because they don’t have time because they have so many subjects or they do not know how to start learning.

I like that in this course it was flexible for me to have the time to read the book of the course and do the WSQ programs by myself. Sometimes, I liked the teacher’s help in my WSQS. Furthermore, I like that the exam does not have value on the course and I believe that the teacher is there to guide you to the learning pyramid path.

I appreciated that my ideas for the project I did were accepted in order to enhance my learning path. Also, I liked searching and using other similar solutions from videos of the course and learn.

Furthermore, I like having the abolish grade program where all the work you are doing is reflected in the rubric where you give yourself a grade and I believe all the teachers should take their fear out and adapt this abolish grade program.

If you follow the learning pyramid you will feel very good learning how to code 🙂

I learn all about coding in C++ where you can see it here:Post of the weeks #11,12,13,14,15 and 16 what things I learned in these weeks ? And Index of Mastery Topics

Embedded video from the course here: #TC1017 course video review

 

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

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

Picture of author

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

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

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

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

#WSQ13 SciLab 16/04/17

#WSQ13 SciLab 16/04/17

scilabp (1)

Link of picture

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

What I did for this numeric program is using Scilab. Scilab is a great tool that I believe I will find very useful during the rest of my degree programs and beyond. The motivation here is simply to introduce me to the tool. Scilab is open source software and runs on Linux, Mac and Windows

Please download and “play with” SciLab.

The resources I need it to play with Scilab are:

Download the latest version at http://www.scilab.org/download/latest

Please follow the tutorial available on their website under Resources->Documentation. Here is the direct link to the tutorial http://www.scilab.org/content/download/849/7901/file/Scilab_beginners.pdf

Page for SciLab to download at https://www.scilab.org

SciLab is an incredibly useful software used to perform ALL mathematical calculations, plots AND even control Microcontrollers!!. It works using commands from the Matlab software and you can also play with this software . As explained in their introductory document:

As we can see in the next pictures we have the #Mastery23 Data analysis with tools (to be determined which tool, most likely SciLab) and #Mastery24 Visualization of data with tools where we have a command to give a value to a variable and using the command plot for graphics we can see the behaviour of that variable of the graphic. For example, if we have these commands:

>> x=0: pi/100: 2*pi;% son los valores del inicio en cero luego el incremento es pi/100 y despues la tercera la longitud de 2 pi.

>> y=sin(x); %en la funcion del seno de x

plot(x,y)%Dibuja un gráfico y grafica las coordenadas x y

sin x and cos x

The folowing is the basic operations that can calculte SciLab

>> 2+2 % suma de 2 y 2

ans =

4.00

>> sin(3) % valor del seno de 3 en radianes

ans =

0.14

>> cos(3) % valor del coseno de 3 en radianes

ans =

-0.99

>> tan(3) % valor de la tangente de 3 en radianes

ans =

-0.14

>> sqrt(25) % valor de la raiz cuadrada de 25

ans =

5.00

log10(3) % valor del logaritmo de base 10 de 3

ans =

0.48

>> log(3) % valor del logaritmo natural de base e de 3

ans =

1.10

>> abs(-3) % Valor absoluto de 3

ans =

3.00

>> exp(0) % exponente ala cero, para cualquier numero

ans =

1.00

>> pi% valor del numero racional de pi

ans =

3.1416

>> i% la unidad imaginaria que es la sqrt(-1), es la misma que la j

ans =

0 + 1.0000i

>> j% la unidad imaginaria que es la sqrt(-1), es la misma que la i

ans =

0 + 1.0000i

>> x=pi% es una igualdad donde x tiene el valor de pi

x =

3.1416

>> format rat % buscar una aproximación racional de un numero

>> pi % por ejemplo el número pi

ans =

355/113

>> format long % expander los numeros racional e irracionales hasta 16 dígitos

>> pi por ejemplo

ans =

3.141592653589793

>> format short e % expander los numeros racionales e irracionales hasta 5 dígitos más exponente

>> pi % para pi por ejemplo

ans =

3.1416e+00

>> format long e % formato numérico de expander los números racionales e irracionales hasta 16 digitos más exponente.

>> pi % para pi por ejemplo

ans =

3.141592653589793e+00

>> format hex % formato de números numericos a sistema hexadecimal

>> pi% para pi por ejemplo

ans =

400921fb54442d18

>> format bank % formato numerico que muestra los numeros en 2 decimales

>> pi como es pi por ejemplo

ans =

3.14

>> x=0: pi/100: 2*pi;% son los valores del inicio en cero luego el incremento es pi/100 y despues la tercera la longitud de 2 pi.

>> y=sin(x); %en la funcion del seno de x

>> plot(x,y)%Dibuja un gráfico y grafica las coordenadas x y

>> x=0: pi/100: 4*pi;% son los valores del inicio en 0 luego el incremento en pi/100 y despues la tercera la longitud en 4 pi

>> y=sin(x); %en la funcion del seno de x

>> plot(x,y)%Dibuja un gráfico y grafica las coordenadas x y

>> x=0: pi/100: 8*pi;% son los valores del inicio en 0 luego el incremento en pi/100 y despues la tercera la longitud en 8 pi

>> y=sin(x); %en la funcion del seno de x

>> plot(x,y)%Dibuja un gráfico y grafica las coordenadas x y

>> x=5: pi/100: 8*pi;% son los valores del inicio de 5 luego el incremento de pi/100 y despues la tercera la longitud en 8 pi

>> y=sin(x); %en la funcion del seno de x

>> plot(x,y)%Dibuja un gráfico y grafica las coordenadas x y

>> x=5: pi/200: 8*pi;% son los valores del inicio de 5 luego el incremento de pi/200 y despues la tercera la longitud en 8 pi

>> y=sin(x); %en la funcion del seno de x

>> plot(x,y)%Dibuja un gráfico y grafica las coordenadas x y

>> x=10: pi/200: 16*pi;% son los valores del inicio de 10 luego el incremento de pi/200 y despues la tercera la longitud en 16 pi

>> y=sin(x); %en la funcion del seno de x

>> plot(x,y)%Dibuja un gráfico y grafica las coordenadas x y

>> xlabel(‘aqui va la x’)% etiqueta a la variable x

>> ylabel(‘aqui va la y’)% etiqueta a la variable y

>> title(‘titulo general’) % agrega un titulo ala grafica actual

>> title(‘titulo general’,’Fontsice’,’36) % agrega un titulo ala grafica actual con su respectivo tamaño

x=0: pi/100: 2*pi;% son los valores del inicio de 0 luego el incremento de pi/100 y despues la tercera la longitud en 2 pi

>> Y1=sin(x); % en la función 1 del seno de x

>> Y2=cos(x); % en la función 2 del coseno

plot(x,Y1,x,Y2); % Dibuja un gráfico y grafica las coordenadas x en función de Y1 y x en función de Y2

legend(‘sin(x)’,’cos(x)’)% leyenda en un grafico

>> a=’Mexico’ % Asignar el valor de una variable de texto a

a =

Mexico

>> b=’Argentina’ % Asignar el valor de una variable de texto b

b =

Argentina

e=’Brazil’ % Asignar el valor de una variable de texto c

e =

Brazil

>>a(3:7)

ans =

x:i

>> a(3:5)

ans =

xic

>> a(1:3)

ans =

Mex

>> X1=[a,b]

X1 =

MexicoArgentina

>> X1=[a,e]

X1 =

MexicoBrazil

>> X1=[b,e]

X1 =

ArgentinaBrazil

>> Y1=[a(1:3),b(1:4),e(5)]

Y1 =

MexicoArgentina

>> length(a) % largo de un vector a

ans =

6.00

>> length(b) % largo de un vector b

ans =

9.00

>> length(c) % largo de un vector c

ans =

6.00

>> stromp(a,c)

ans =

0.00

>> Mex=’Mexico’

Mex =

Mexico

>> stromp(a,Mex)

ans =

1.00

>> h=upper(a)

h =

MEXICO

>> lower(h)

ans =

mexico

If you want a plot in 3d you need the command mesh or surf and we need these commands:

–> x=-1:0.1:3;

–> y=1:0.1:4;

–> [X,Y]=meshgrid(x,y);

–> surf(Y)

surf

Furthermore, we can do pie charts:

x=[1 2 3 4.5 %e]; //Remember %e is e=2.71…..

–> pie(x)

pieee

You can also do it for control microcontrollers that made me love more this open source software:

Using Scilab for microcontrollers

And i also resolved it by doing this video tutorial that i made reafirming these parts at this link :#WSQ13 Tutorial 14 SciLab 15/04/17 SciLab codes Mastery 23 and 24

Link of the resources to play with Scilab in Github:

Commands in Github

Commands in Github

Graphic commands

More commands

Some commands that appear with Matlab

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

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

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

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

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

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

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

ken bauer

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

Resultado de imagen para e number

Link of picture

The following photograph shows the solution to this problem:

w1

w2

w3

p666

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

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

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

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


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

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

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

 

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

float precision; //Declarate float variable precision

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

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

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

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

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

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

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

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

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

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

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

float previuse; //Declarate float variable previuse

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

}

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

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

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

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

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

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

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

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

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

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

eular

This code for solution will be here and in Github:

Link in Github: WSQ12.cpp

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

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

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

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

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

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

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

}

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

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

}

}

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

{

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

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

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

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

}

int main()

{
float precision; //Declarate float variable precision

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

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

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

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

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

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

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

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

ken bauer

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

The following photograph shows the solution to this problem:

wsq11v1

wsq11v2wsq11v3wsq11v4a1

a2

a3a4

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

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

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

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

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

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

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

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

int main ()
{

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

Next we need to Declarate int variable cfinal

int cfinal; //Declarate int variable cfinal

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

}

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

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

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

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

Declarate int variable i initialized in 0.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

vvvv

This code for solution will be here and in Github:

Link in Github: WSQ11.cpp

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

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

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

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

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

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

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

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

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

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

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

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

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

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

}

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

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

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

}

} //END OF WHILE

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

}

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

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

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

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

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

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

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

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

}

} //END OF IF

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

}

int main ()
{

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

int cfinal; //Declarate int variable cfinal

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

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

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

}

For the subjects that don’t apply the abolishgrade program at least they should have apps for aboiling grades and cherish the process of learning

For the subjects that don’t apply the abolishgrade program at least they should have apps for aboiling grades and cherish the process of learning

This short post regarding solving problems with programming is just to give the message of we need to increase the model of abolishgrades program for each subject and some teachers are horrofied for this change. Therefore, at least with having apps for each subject, the students will cherish the process of learning and this will provoque an increase of creativity among the students and not just “pass” with just the requirements of the subject.

For example, I have the subject of Chemistry that doesn’t have the abolishgrade program that this course of solving problems with programming has nonetheless we have an app for this subject and I found it more motivating to keep learning chemistry by playing with the app and abolish percentages of grades. Hence, I believe we need to have in each subject an app in order to exploit the creativity of each person who is studying.

Imagine each course you take has an app to learn more.

The next are images of the app I use to learn and master chemistry, the app is called Elever App. Let’s learn by playing with subject apps!!!

Screenshot_2017-04-16-12-41-23

Screenshot_2017-04-11-20-50-13Screenshot_2017-03-21-20-02-12Screenshot_2017-03-24-19-36-39Screenshot_2017-03-24-19-37-15Screenshot_2017-03-08-18-39-58

Screenshot_2017-03-04-13-45-47