WSQ05 – On To Functions!!!!!

--Originally published at blog de Horacio

What to Do:

You will go back and do WSQ01 – Fun with Numbers again.

But this time, write a function for each calculation. Each function should define two parameters (in this example of type int) and return the correct value as an integer as well.

You main program needs to ask the user for the input and then call each function to calculate the answer for each of the parts.

Progress:

fist we need to search wsq01 homework for remind how do this exercise, but now we have to change de variables into a functions.

Then we had to look for reliable sources on the subject of functions so as to know which methodology to carry out this challenge, finally as we did this task previously, we just have to change that part of functions.

CODE:

include <iostream>
using namespace std;

int sum(int x, int y){
return (x+y);
}

int Difference (int x, int y){
return (x-y);
}

int Product (int x, int y){
return (x*y);
}

int Division (int x, int y){
return (x/y);
}

int Remainder (int x, int y){
return (x%y);
}

int main()
{
int x,y;
cout << “este programa tiene una funcionalidad similar al WSQ01 pero ahora todo integrado en funciones” << endl;

cout << “teclea el primer numero a evaluar” << endl;
cin >> x;
cout << “teclea el segundo numero a evaluar” << endl;
cin >> y;

int r1 = sum(x,y);
int r2 = Difference(x,y);
int r3 = Product(x,y);
int r4 = Division(x,y);
int r5 = Remainder(x,y);

cout << “la suma de los dos numeros es: ” << r1 << endl;
cout << “la resta de los dos numeros es: ” << r2 << endl;
cout << “la multiplicacion de los dos numeros es: ” << r3 << endl;
cout << “la

Continue reading "WSQ05 – On To Functions!!!!!"

Quiz Week 8

--Originally published at blog de Horacio

  • Write a function that calculates returns the “nth” Fibonacci number where we define a function over the Fibonacci numbers mapping the naturals (starting with zero) to the Fibonacci series. 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. You should try to implement this with two solutions: one with a loop and one with recursion. Which do you think is “better”, which looks more “elegant”, which is more “efficient”?
  • captura-de-pantalla-2017-03-06-a-las-08-44-58
  • FIBONACCI SERIES :En matemática, la sucesión de Fibonacci (a veces llamada erróneamente serie de Fibonacci) es la siguiente sucesión infinita de números naturales:
    0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597…{\textstyle 0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597\ldots \,}

     

    La espiral de Fibonacci: una aproximación de la espiral áurea generada dibujando arcos circulares conectando las esquinas opuestas de los cuadrados ajustados a los valores de la sucesión;1adosando sucesivamente cuadrados de lado 0, 1, 1, 2, 3, 5, 8, 13, 21 y 34.

    La sucesión comienza con los números 0 y 1,2 y a partir de estos, «cada término es la suma de los dos anteriores», es la relación de recurrencia que la define.

    A los elementos de esta sucesión se les llama números de Fibonacci. Esta sucesión fue descrita en Europa por Leonardo de Pisa, matemático italiano del siglo XIII también conocido como Fibonacci. Tiene numerosas aplicaciones en ciencias de la computaciónmatemática y teoría de juegos. También aparece en configuraciones biológicas, como por ejemplo en las ramas de los árboles, en la disposición de las hojas en el tallo, en las flores de alcachofas y girasoles, en las inflorescencias del brécol romanesco y en la configuración de las piñas de las coníferas. De igual manera, se encuentra en la estructura espiral del caparazón de algunos moluscos, como el nautilus.

    CODE:

  • #include<stdio.
    Continue reading "Quiz Week 8"

about C++

--Originally published at blog de Horacio

Qué es un Lenguaje de Programación

Antes de hablar de C++, es necesario explicar que un lenguaje de programación es una herramienta que nos permite comunicarnos e instruir a la computadora para que realice una tarea específica. Cada lenguaje de programación posee una sintaxis y un léxico particular, es decir, forma de escribirse que es diferente en cada uno por la forma que fue creado y por la forma que trabaja su compilador para revisar, acomodar y reservar el mismo programa en memoria.

Existen muchos lenguajes de programación de entre los que se destacan los siguientes:

  1. c
  2. c++
  3. basic
  4. Ada
  5. Java
  6. Pascal
  7. Python
  8. Fortan
  9. Smalltalk

Quiz 04 “Minimum and Squares”

--Originally published at blog de Horacio

What to do:

You implement these function in your own program in a file quiz4.cpp.

You should make a main routine that asks the user for three numbers and then calls your functions to which should *RETURN* the value and you print in the main program.

Publish your code on your own blog today (during class time is best) and use the tag #Quiz04 so it shows up nicely in our tag cloud.

captura-de-pantalla-2017-02-02-a-las-13-30-43

#include <iostream>
#include <cmath>
using namespace std;
int sumSquares(int x, int y, int z) {
return pow (x,2)+pow(y,2)+pow(z,2);
}
int minimumThree(int x, int y, int z){
int num;
if (x<=y && y<=z) {
num=x;
}
if (y<=x && x<=z) {
num=y;
}
if (z<=y && y<=x) {
num=z;
}
return num;
}
int main()
{
int x,y,z;
std::cout << “give me the x variable” << ‘\n’;
std::cin >> x;
std::cout << “give me the y variable” << ‘\n’;
std::cin >> y;
std::cout << “give me the z variable” << ‘\n’;
std::cin >> z;
std::cout << “the sum of squares are: ” <<sumSquares(x,y,z)<< ‘\n’;
std::cout << “the minimun of the three numbers is: ” <<minimumThree(x,y,z)<< ‘\n’;
return 0;
}

 


WSQ03

--Originally published at blog de Horacio

What to do:

Write a program that picks a random integer in the range of 1 to 100.

There are different ways to make that happen, you choose which one works best for you.

It then prompts the user for a guess of the value, with hints of ’too high’ or ’too low’ from the program.

The program continues to run until the user guesses the integer. You could do something extra here including telling there user how many guesses they had to make to get the right answer.

You might want to check that your program doesn’t always use the same random number is chosen and you should also split your problem solving into parts. Perhaps only generate the random number and print that as a first step.

Progress:

First we looked for the way to create the random number, we found a good post that helped us a lot. Then we started reading a little more about counters and the while function that was the one that made me more suitable for my program. After a bit of analysis finally came out the program but I have a fault in the counter that I did not know how to remove it, I hope Ken can explain to me.

captura-de-pantalla-2017-02-01-a-las-23-39-51

Sources of research:

http://blog.martincruz.me/2012/09/obtener-numeros-aleatorios-en-c-rand.html

http://www.aprenderaprogramar.com/index.php?option=com_content&view=article&id=931:bucles-en-lenguaje-c-estructura-de-repeticion-condicion-contador-ejemplos-tabla-de-multiplicar-cu00533f&catid=82:curso-basico-programacion-lenguaje-c-desde-cero&Itemid=210

Code:

#include <stdlib.h>
#include <time.h>
#include<iostream>
using namespace std;
int main() {
int num,resp,intentos;
srand(time(NULL));
num=1+rand()%(101-1);
do {
std::cout << “ya estoy listo para jugar” << ‘\n’;
std::cout << “¿cual numero crees que tengo para ti?” << ‘\n’;
std::cin >> resp;
intentos++;
if (num<resp) {
std::cout << “lo siento, pero tu numero es muy alto” << ‘\n’;
}
if (num>resp) {
std::cout << “lo siento, pero tu numero es muy bajo” << ‘\n’;
}
}

Continue reading "WSQ03"

QUIZ 3

--Originally published at blog de Horacio

What to Do

You implement this function in your own program in a file quiz3.cpp.

You should make a main routine that asks the user for a number and then calls your functions to calculate the square and cube roots of that number and prints them out.

What should you do if the user enters a negative number?

Publish your code on your own blog today (during class time is best) and use the tag #Quiz03 so it shows up nicely in our tag cloud.

captura-de-pantalla-2017-02-01-a-las-19-17-03

code:

#include <iostream>
#include <math.h>
using namespace std;
double square_root(double x){
double square_root= sqrt(x);
return square_root;
}
double cube_root(double x){
double cube_root= cbrt(x);
return cube_root;
}

int main(){
double x;
std::cout << “introduce un numero” << ‘\n’;
std::cin >> x;
if (x<0) {
std::cout << “error” << ‘\n’;
}else {
std::cout <<square_root(x)<< ‘\n’;
std::cout <<cube_root(x) << ‘\n’;
}
return 0.0;
};


WSQ02 Temperature

--Originally published at blog de Horacio

WHAT TO DO:

Write a program that will prompt the user for a temperature in Fahrenheit and then convert it to Celsius. You may recall that the formula is C = 5 ∗ (F − 32)/9.

Modify the program to state whether or not water would boil at the temperature given. Your output might look like the following.

EXPLANATION:

First we name the variables of f and c for the two types of grades respectively, then we gave the task of assigning the formula of the conversion to the variable c in order to convert the degrees Farhenheit to Celcius, we use a condition statement for when the result of The conversion gave a result greater than 100, write a message to inform us that it is boilingcaptura-de-pantalla-2017-02-01-a-las-18-51-39

CODE:

#include <iostream>
using namespace std;
int main() {
int F,C;
std::cout << “dame la temperatura en grados Farhenheit” << ‘\n’;
std::cin >> F;
C = 5*(F-32)/9;
std::cout << “la temperatura de ” <<F<< “grados Farhenheit en grados celcius es:” <<C<< ‘\n’;
if (C>100) {
std::cout << “el agua esta hirviendo compadre!!!” << ‘\n’;
}else {
std::cout << “el agua no hierve” << ‘\n’;
}
return 0;
};


WSQ01 FUN WITH NUMBERS

--Originally published at blog de Horacio

What to do:

Ask the user for two integer values, then use those two values to calculate and show the following:

  • The sum of the two numbers.
  • The difference of the two numbers.
  • The product of the two numbers.
  • The integer based division of the two numbers (so no decimal point). First divided by second.
  • The remainder of integer division of the two numbers

Progress:

First we name the variables so that we do not mark the program’s error, then we start to create the arithmetic operations with the variables “num1” and “num2”, and in the end we print in the screen.

captura-de-pantalla-2017-01-30-a-las-09-10-26captura-de-pantalla-2017-01-30-a-las-09-10-12

#include <iostream>
using namespace std;
int main() {
int num1,num2,suma,resta,multiplicacion,division,residuo;
std::cout << “este programa pide dos numeros y hace operaciones con ellos” << ‘\n’;
std::cout << “dame el primer numero” << ‘\n’;
std::cin >> num1;
std::cout << “dame el segundo numero” << ‘\n’;
std::cin >> num2;
suma=num1+num2;
resta=num1-num2;
multiplicacion=num1*num2;
division=num1/num2;
residuo=num1%num2;
std::cout << “la suma de los numeros es:” <<suma<< ‘\n’;
std::cout << “la resta de los numeros es:” <<resta<< ‘\n’;
std::cout << “la multiplicacion de los numeros es:” <<multiplicacion<< ‘\n’;
std::cout << “el resultado de l division es:” <<division<< ‘\n’;
std::cout << “el residuo de la division es:” <<residuo<< ‘\n’;
return 0;
};