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”

Quiz 03

Today we had to do Quiz number 3. Problem number one was about the distance between two points on a cartesian plane. Number two was way harder. We had to make a program that would calculate the Fibonacci series of numbers till the number that the user inputs.

Problem number one was easy for me. I just used the equation of the distance between two points, which is the Pitagorean Theorem applied.

distance-between-two-points-formula

My translation to C++ language was:  d = sqrt(pow((c-a),2)+ pow((d-b),2)), a, b, c and d being parameters of my function, input by the user.

The second problem was the one that troubled me. The most important thing while solving any kind of problem, be it C++ or physics is to really understand what you are being asked. So, that was my frst step, to understand what a Fibonnacci series is. It is the sum of a number plus the next one, starting on 0. So the series would look like this:

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

0+1 = 1, 1+1 = 2, 2+1 = 3, 3+2 = 5, 5+3 = 8, 8+5 = 13, 13+8 = 21;

To translate this to a command in C++ was hard for me. But I did it the next way:

#include <iostream>

using namespace std;

int n, fI = 0, fII = 1, f;

int fibonacci(int n){
for (int t = 1; t < n ; t++){
f = fI + fII ;
fI = fII;
fII = f;
}
return f;
}
int main(){
cout << “Provide the nth number of the Fibonacci list that you want to print: “<< endl;
cin >> n;
cout << “Your number is: ” << fibonacci(n);
}

I created a function called fibonacci, with 1 parameter (the number of the series that the user wanted to output). Inside the

Quiz03.jpg

Continue reading “Quiz 03”

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.

 

On to functions

So this has been the easiest task and blogpost so far! They say that if you work hard at the beggining it will help you at the end, and it sure is paying off.

I mentioned all that because this program is exactly the same I had to do on #WSQ03, but now using functions. The cool thing is, when I did #WSQ03 I used functions in order to practice! So basically you´ll see the same program here. BTW, the image above is how this program looks when you run it.

Functions are really cool tools that you can use in order to put your program together in a more organized way. In order to use them, you have to build them first. You usually build them before the code inside main that “calls” the funtion, and before the main, which is a function as well actually.

To call the function, you just have to write the function name with a parenteses. Inside the parenteses you have to write the parameters, which are the values or information that the function is going to work with.

Here you can have a look at my code:

#include <iostream>

using namespace std;

int x, y;

int multiplication(int z, int p){

int operation = z * p;

return operation;
}

int divition (int z, int p){

int operation = z / p;

return operation;

}

int sum (int z, int p){

int operation = z + p;

return operation;

}

int subs (int z, int p){

int operation = z – p;

return operation;

}

int remainder (int z, int p){

int operation = z % p;

return operation;

}

int main(){

cout << “This program will do some basic operations with two numbers. Please provide the first number” << endl;
cin >> x;

code2#WSQ03
code1#WSQ03

Continue reading “On to functions”

Sum of numbers

The next task we were asked to perform was a program capable of adding the numbers inside a user specified range. The user provides the first value of the range and the last value of the range. We were asked to preferably use loops to solve this task.

This program was a bigger challenge for me. It helped me to really understand the way a counter works. It is kind of strange and hard to undestand how a variable is initializaed under the value of another one, and then inside the loop you initialize it to the value of itself plus one.

First I thought I had to use a for loop to run this program. But it was getting to hard for me and I could not do it. My fellow classmate and friend Alberto Rodriguez gave me a general idea of how it should work, using a do while loop.

So how this basically works is that the sum varable is initialized to the value of the first number of the range, before the for loop starts working. Inside the for loop, you intialize the sum funtcion again to the value of itself (which is now the value of the first number of the range) plus one. Then you make the actual operation, which is to add the value of the first number of the range plus the variable sum.

The program will keep on doing the operation while the value of sum is less than the last value of the range.

#include <iostream>

using namespace std;

int x, y, sum;

int main (){

cout << “Provide the first number of the range: ” << endl;
cin >> x;

cout << “Provide the last number of the range: ” << endl;
cin >> y;

sum = x;

do{

Continue reading “Sum of numbers”

Random number generator

Our next task was to build a random number generator wth a C++ program. This was the first time I ever did something like that. I tried unsuccesfully to do it by myself at first, but I just couldn´t figure out what to do. So I decided to check what the Oracle of Google had for me. I came up with this information, basically the first webpage on the list. I also checked out a video from my  Yankee tutor on Youtube, thenewboston. 

The program basically works with a do while loop, so you can keep guessing until you hit the correct number. Also, I you miss, it is programmed to tell you wether you gave a higher number or a lower number. I did this with an If cycle.

  • About the random number, it works with the function rand, contained in the header #include <stdlib.h>
  • In order fot the numbers to never be predictive, I used the function time, as a paramater of srand. As a paramater of time  I used 0, as thenewboston explained, this would make the time to use he number of seconds since it was developed, probably in the 70´s. PEACE.
  • So, now the numbers should be really hard to predict.
  • In order to only get random numbers between 0 and 100, we had to use the modulus 100 + 1 of the function rand()

So no more talking, the code can tell a thousend words

“Dead men tell no tales” ARGGGHH

Sorry Blackbeard, go back to the XVII century bro.

Have a look at my code:
#include <stdlib.h>
#include <time.h>
#include <iostream>

using namespace std;

int main ()
{
int x, y;
srand (time(0));

x = rand() % 100 + 1;

do {
cout << “Guess a

Continue reading “Random number generator”