Quiz #4

The instructions: Create a function called euler_calc with a single parameter precision. The value of precision is used to determine when to stop calculating. Your calculation will stop when the two consecutive values estimating e differ by less than precision (remember to use absolute value when calculating the difference between two values here).

The Euler number is very important in the math area and we can calculate it with this formula:

e =  displaystylesumlimits_{n = 0}^{ infty} dfrac{1}{n!} = 1 + frac{1}{1} + frac{1}{1cdot 2} + frac{1}{1cdot 2cdot 3} + cdots

Here you can see my code on Atom

quiz4

quiz41

Also you can check here my code on Github

Quiz 6. Euclid.

Euclid was one of the great ancient greek guys. Among the stuff he invented was the algorithm bearing his own name.

This is a common algorithm used in computing. It is used to find the greatest common denominator of two numbers (GCD). If you want to learn more about this, you should totally check the explanation at Khan academy´s post.

Orlando´s code helped me a lot. You should totally take a look. First I tried to make the code using a do while loop. It was becoming really hard, until I saw Orlando´s code using recursion. It was way easier to code it this way .

Here you can see a picture of the code (anyways you can see it on github Here):

code_euclid

code_euclid

Link to my code on github.

I got it “Yo soy 196” WSQ11 :)))

Que tal, después de dos días sin dormir conseguí terminar la tarea. Enserio q me costo mucho explicarlo pero lo hice lo mas claro posible que pude. Espero les ayude. Esta es las versión 1.0, aunque funciona como me la pidieron. Se agradecen sus comentarios 🙂

Les recomiendo usar audífonos para que escuchen mejor.

El vídeo esta muy largo pero aquí les dejo el código completo (no se olviden de citar si lo quieren utilizar 😉

#include <iostream>
using namespace std;

int reverse(long num){
long numRev=0;
long sum;
int cont=-1;
do{
sum=num;
numRev=0;
while (num!=0){
numRev= numRev*10+(num%10);
num=num/10;

}
cont++;
num=numRev+sum;
}
while(sum!=numRev && cont!=30);

return cont;

}
int main (){
int uBound, lBound, palandrome, vPalandrome=0, vNonLycherels=0, vLycherels=0;

cout << “Give The lower bound of the sequencen”;
cin >> lBound;
cout << “Give The upper bound of the sequencen”;
cin >> uBound;

for(int z=lBound; z<uBound+1; z++){

reverse(z);
palandrome=reverse(z);
if(palandrome==0){
vPalandrome++;
}
else if (palandrome<30){
vNonLycherels++;
}
else if (palandrome==30){
vLycherels++;
}

}
cout <<“Palandrome”<< vPalandrome <<endl;
cout <<“Non-Lycherels”<< vNonLycherels <<endl;
cout <<“Lycherels”<< vLycherels <<endl;
return 0;
}

Standard deviation calculator

THIS BLOGPOST IS  NOT DONE YET, BUT STILL YOU CAN ALREADY TAKE A LOOK AT THE CODE, WHICH IS AT THE END. For the task number ten of the semester, we were asked to create program that asks the user for 10 numbers. We were required to store those numbers in a list and to show the user the total, average and standard deviation of those numbers.

The easiest way to this was to create an array for those numbers. An array is just a group of numbers saved by the computer. You can acces any of those numbers WSQ10_functions1WSQ10_STDFfunctionsWSQ10_main

#include <iostream>
#include <cmath>

using namespace std;

int y;
char answer;

float SumaTotal(float arre [], int numNumeros){

float sum = 0;

for (int i = 0; i < numNumeros; i++){

sum += arre[i];
}
return sum;
}
float Average (float arra[], int numas){

float aver, suma = 0;

for (int c = 0; c < numas; c++){

suma = suma + arra[c];
}

aver = suma / numas;

return aver;
}
float STDF (float arre[], int numdenum){

float aver, sumaII, sumaIII = 0,sumaI = 0;
double stdfi;
for (int c = 0; c < numdenum; c++){

sumaI += arre[c];
}

aver = sumaI / numdenum;

for (int i = 0; i < numdenum; i++){

sumaII = arre[i] – aver;
sumaIII += pow((sumaII), 2);
}

stdfi = sqrt((sumaIII / numdenum ));

return stdfi;
}
int main (){

do{

cout << “Type the number of numbers that you want to have: “;
cin >> y;

const int numNumbers = y;

float x [numNumbers];

for (int i = 0; i < numNumbers; i = i + 1){
cout << “Provide the number ” << i + 1 << ” number: “;
cin >> x [i];
}
cout << “The total of your numbers is:

Continue reading “Standard deviation calculator”

On to Functions

This program is like one in the WSQ03 but this time we have to add functions to each one.

Had a little problems because I didnt know how to add functions but I read in cplusplus.com something about functions and then I look for a youtube video so taht I can make it rigth, below I attacht the links to the cplusplus webpage of functions and the youtube video for your need.

http://www.cplusplus.com/doc/tutorial/functions/

So here I have my Atom for you to see how it looks

functions

functions1

Then I show you the terminal page to you to see how the program works

functions2

Check my code here on Github.

Factorial calculator

The image above is what my computer outputs when I run this program, a factorial calculator. 

It is a basic factorial calculator. The factorial of a number, lets say of number 5 (written 5!) is the multiplication of 5*4*3*2*1. The result of that operation would be 120.

In order to do this operation in C++, you have to use a loop or recursion. On my first try of this program I decided to use a For Loop. I´ll try to do it this weekend with recursion.

For this program to work, I created a function called “facto” with one parameter. The parameter is the number you want to get the factorial from.

So I declared an int variable called op and initialized it to 1. The operation inside the for loop is op = op * n, which is a number between 1 and a number less or equal to the required by the user, as you can see in my for loop.

int f, n, op =1;
char answer = ‘y’;

int facto(int x){

for (n = 1; n <= x; n++){

op = op * n;
}

return op;
}

A cool thing about this program is that it asks the user if he wants to repeat the process with another number, or if he wnats to end the program. I achieved this doing a do while loop.

Here you can have a look at my program:

WSQ09

And here is the code:

#include <iostream>
using namespace std;

int f, n, op =1;
char answer = ‘y’;

int facto(int x){

for (n = 1; n <= x; n++){

op = op * n;
}

return op;
}

int main(){

do {
cout << “Enter the number that you want to obtain the factorial from: ” << endl;

Continue reading “Factorial calculator”

Project! 2 DOF Robot Arm

So! I finally decided what my project for the semester wll be…

A two degrees of freedom robotic arm. I chose this project since the arm will require a lot of porgramming to work, an I´ll do it on C++. This project will be worked together with the project in Computer Drawing class.

A two degrees of freedom robotic arm is a machine simulating a human arm, but with only two “joints” or  places where it can bend or rotate.

The objective of the project, besides learnig A LOT will be the next one, as I stated it on my computer drawing document.

  • create an easy to use and easy to understand two degrees of freedom robotic arm, capable of lifting a maximum weight of one kilogram from a distance of 60 centimeters. An easy to replicate arm, with all its information free to use for everyone and after my first design is released, the code will be open sourced., as well as the design.

Here you can have a look at my first sketch of the project:sketch2

 

I did two toher sketches, have a look:

sketch1
sketch3

I chose the first one, since I think it´ll work better.

Since this is a blog about programming, about that is what I will keep you most updated on.

What I know is that I´ll program the servomotors with C++, through a Freedom by Freescale develpment platform (which I already have, thanks TEC) on the online tool Mbed. I did some similar programming last semester on a little line-following cart. 

I´ll keep you updated, now my project has to be approved by my proffesor- Thanks for reading.