Expo Ingenierías

--Originally published at prgrm.co

So I went to Expo Ingenieria and I felt motivated. People my age are making some amazing things, so I felt the need to do something amazing. I tried to make an engine that would spin at different speeds but I couldn’t make it work. But seeing all of what my classmates are doing made me realize I want to be doing cool things as well. I saw a 3d prosthesis and a lot of robotic arms.


L’ê.

--Originally published at prgrm.co

In this WSQ, we had to calculate the value of e, to a desired lenght.

I watched this video that explains what e is.

#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
    int A, B;
    double E, D;
    
    for (A=1; A<=15; A++ )
    {
        D=1;
        for (B=1; B<=A ; B++ )
        {
            D = D * B;
        }
        E = E + 1 / D;
    }
    cout<<setprecision(10)<<"Estimated Value of e is "<< E + 1 <<endl;
    system("pause");

Final Words.

--Originally published at prgrm.co

Well, the semester is finally over, and what I can say about Ken’s teaching technique?
I enjoy the freedom to work at my rhythm and organize my duties and times as I see fit. The thing that I take with me from this course, apart from programming, is that. I need to start planning and organizing my time and work. Ken is an excellent teacher because most of my other teachers don’t really pay attention to this issue, most of the students are still learning how to organize their time and Ken knows it.

Excellent way of teaching because this is something I’ll take into my professional career.


Mesopotamia

--Originally published at prgrm.co

In this WSQ, we had to find the square root of a number using the Babylonian method.

Here is a video that explains what’s going on, and here is another video showing how another student programmed this.

Once I had this information I could start programming.

#include <iostream>
using namespace std;

long double square(long double X)
{
  long double y=1, c;
  for(int i=0; i<1000; i++)
  {
    c=X/y;
    y=(y+c)/2;
  }
  return y;
}

int main()
{
  int X;
  cout << "Square Root... \n\nNumber: ";
  cin >> N;
  cout << "The square root of "<< N << " is equal to "<<square(X) << endl << endl;
  return 0;
}

Mechanical Sound

--Originally published at prgrm.co

This post is related to the project I’m going to be developing. I’m going to be linking two classes and making programming tangible in a physical way.

My project consist of a record player, but It will a mechanical record player, how does this work? Well is actually really old technology actually from 1887, Thomas Edison actually came up with the idea of a Phonograph. Nowadays vintage is a strong market.

My project is linked with my Computerized Drawing class. And what I will be programming is a step motor which has the ability to rotate at three different speeds, 33, 45 & 78 rpm’s.

I’m looking forward to learning how to program Arduino 1 in order to make this happen.

Featured Image. 


QUIZ09

--Originally published at prgrm.co

In this week’s class, we needed to make a program that given coordinates would give back the distance between them.

#include <iostream>
#include <cmath>

using namespace std;

float distance(float x1, float y1, float x2, float y2){
float a = x2 - x1;
float b = y2 - y1;

return sqrt(pow(a, 2)+ pow(b, 2));
}

int main(){

float x1, y1, x2, y2;

cout << "This program will calculate the distance between coordinates" << endl;
cout << "X1: "; cin >> x1;
cout << "Y1: "; cin >> y1;
cout << "X2: "; cin >> x2;
cout << "Y2: "; cin >> y2;

cout << "The distance between coordinates (" << x1 << "," << y1 << ") & (" << x2 << "," << y2 << ") = " << distance(x1,y1,x2,y2) << endl;

return 0;
}

I made a function that would give back “c”.

Image.

pythagoras-theorem

Here is the function:

float distance(float x1, float y1, float x2, float y2){
float a = x2 - x1;
float b = y2 - y1;

return sqrt(pow(a, 2)+ pow(b, 2));
}

Featured image.


RZArector

--Originally published at prgrm.co

Alright WSQ07.

This one had me smacking my pencil against my head for a while. We needed to make a program that asks the user for values and then it gives back the sum, average and standard deviation, using vectors.

Ok, piece of cake! Yeah right, Ken came along and told me to do it with functions, at this point it got interesting.

This is the main() of the program, let’s check it out by parts:

nt main(){
int i, n, thesum = 0;

cout << "Insert the values you want: ";
cin >> n;

vector <float> values(n);

for (i=0; i<n; i++){

cout << "Insert number: " ;
cin >> values[i];
}


cout << endl << "The sum of the values you have selected is: " << sum(values);
cout << endl << "The average of the values you have selected is: " << average(values);
cout << endl << "The standart deviaton of this set of number is: " << standart(values) << endl;

return 0;

}
  1. First important part: vector <float> values(n). As you can see here the vector is being declared then in between “< >” you determine the type variable and finally the name of the vector and how many numbers it will have.
  2. Then the number of values the user will provide the program with:
 int i, n, thesum = 0;

cout << "Insert the values you want: ";
cin >> n;

vector <float> values(n);

for (i=0; i<n; i++){

cout << "Insert number: " ;
cin >> values[i];
}

As you can see here, the program ask the user for the values wanted and then a for loop will store this values in the vector <float> values (n); 

That was the easy part now let’s move on to the functions, the first one will add up all

Continue reading "RZArector"

Coming back to life.

--Originally published at prgrm.co

This is the blog related to WSQ05, in this program, we were asked to go back in time, to when we were just starting the course.

The original code looked like this:

#include <iostream> /* This will include the library to call functions like
cout, cin */

using namespace std; /* This allows me to avoid writing std:: before
every function */

//Declare a whole variable
int none, ntwo;

//This is the beggining of the program.
int main (){

cout << "Insert a number: "; //Here I'm asking the user to insert a number cin >> none; //The answer of the user is stored in the previously declared variable "none"
cout << "Insert another number: "; //Here I ask the user to insert another number cin >> ntwo;

/* In this part, the program will add, subtract, multiply, divide and give back the remainder */
cout << "The sum of: " << none << " + " << ntwo << " is: " << none + ntwo << endl;
cout << "The difference of: " << none << " - " << ntwo << " is: " << none - ntwo << endl;
cout << "The product of: " << none << " * " << ntwo << " is: " << none * ntwo << endl;
cout << "The division of: " << none << " / " << ntwo << " is: " << none / ntwo << endl;
cout << "The remainder of: " << none << " / " << ntwo << " is: " << none % ntwo << endl;

}

As you can see, everything is in the main(), as Ken told me last class, we need to make functions because they are like lego blocks and they can be placed in different programs

Continue reading "Coming back to life."

Quiz 04

--Originally published at prgrm.co

In this week’s quiz, the goal was to ask the user for three different numbers and then make two functions. The first function was to display the lowest of the three numbers, and the second one was to add the squares of the three numbers.

In order to accomplish this, I needed to include three different libraries.

  • iostream
  • cmath
  • algorithm

Then the making of the functions, the first one which is to find the lowest number looks like this:

int min3(int x, int y, int z){
 return min(min(x, y), z);
 }

Notice the way the “return min(min(x , y), z)” is written, this is due the fact that the “min” function works only for two integers, so by repeating the “min” function first it chooses between “x” & “y” and then between the result from this later & “z”.

The second function is to add the squares of the three numbers, this one is relatively easier as the only thing you need to do is multiply and add, like so:

int sumofsquares(int x, int y, int z){
 return ((x*x) + (y*y) + (z*z));
 }

Here’s the full code:

#include &lt;iostream&gt;
#include &lt;algorithm&gt;
#include &lt;cmath&gt;

using namespace std;

int min3(int x, int y, int z){
 return min(min(x, y), z);
 }

int sumofsquares(int x, int y, int z){
 return ((x*x) + (y*y) + (z*z));
 }

int main(){

 int no1, no2, no3;

 cout &lt;&lt; "This program will give you the lowest number and the sum of squares of the three numbers asked." &lt;&lt; endl;
 cout &lt;&lt; "First: ";
 cin &gt;&gt; no1;
 cout &lt;&lt;"Second: ";
 cin &gt;&gt; no2;
 cout &lt;&lt; "Third: ";
 cin &gt;&gt; no3;

 cout &lt;&lt; "The smallest of the three numbers is " &lt;&lt; min3(no1, no2, no3) &lt;&lt; " ,the sum of the squares is " &lt;&lt; sumofsquares(no1, no2, no3) &lt;&lt; 
Continue reading "Quiz 04"

For sigma like Σ

--Originally published at prgrm.co

This assignment was focused on a different kind of loop, previously I used a “do while” loop, check it out here,  but this time I’ll be using a “for” loop.

Ok, so… the “for” loop consist of 4 parts:

  • Initialization: here is where you will declare how the loop starts.
  • Condition: in this part, the program will evaluate if the loop is true or false.
  • Increment: the initialization that you started at first will either increase or decrease.
  • Statement: What happens every time a loop is completed.

If you need further information check this out.

Ok check the code:

#include <iostream>

using namespace std;

int main(){

int i, low, high, sum = 0;

cout << "Give me the lower number: ";
cin >> low;
cout << "Give me the higher number: ";
cin >> high;

for (i = low; i <= high; i++){
sum = sum + i;
}

cout << "The sum of numbers between " << low << " & " << high << " is: " << sum << endl;

return 0;
}

Featured image.