WSQ07 – Arrays

--Originally published at The Talking Chalk

The Task

Create a program with a function that returns the factorial of the number given in the parameter.

The Process

The Code

#include <iostream>
#include <math.h>
using namespace std;

int main()
{
float number[10], sum, average, variance, sdev;
cout<<“Give ten numbers.”<<endl;
for(int counter = 0; counter<10; counter++)
{
cin>>number[counter];
sum+=number[counter];
average=sum/10;
variance+=pow(number[counter]-average, 2)/10;
sdev=sqrt(variance);
}
cout<<“The sum of the given numbers is: “<<sum<<endl;
cout<<“The average of the given numbers is: “<<average<<endl;
cout<<“The standard deviation of the given numbers is: “<<sdev<<endl;
return 0;
}

The topics

#For

#Arrays/vectors


WSQ06 – Factorials

--Originally published at The Talking Chalk

The Task

Create a program with a function that returns the factorial of the number given in the parameter.

The Process

The Code

 

#include <iostream>
using namespace std;

int factorial (int num)
{
int counter=1, factorial=num;//set a counter, set factorial as the given number
do
{
factorial*=counter; //multiply factorial per all the numbers counter can have that are smaller than num
counter+=1;
}
while(counter<num);//Do while counter is smaller than um
return factorial;
}

int main()
{
cout<<factorial(5)<<endl;
return 0;
}

The topics

#While and do while


review del semestre

--Originally published at Aprendiendo a programar en C++

Durante este semestre, particularmente en esta clase, logre aprender mucho acerca de la responsabilidad y la procrastinación, fue un poco dificil darme cuenta de que no soy an responsable como daba por hecho, y es que si términe con todos mis deberes, pero no fue si no hasta el ultimo mes (mas que nada la ultima semana) que básicamente hice todo, fue pesado, algo apresurado e incluso dificil, pero se logro el objetivo, aunque definitivamente tratare de volverme mas responsable, y sobre todo organizado.

Todo esto es parte de mi critica positiva del semestre, aunque me falta lo que considero mas valioso el haber “aprendido a aprender” que es una habilidad muy valiosa desde mi punto de vista, aunque claro, noto muy poca revisión o exigencia en el curso, cosa que puede perjudicarnos, porque a pesar de que creo que es un buen sistema, la mayoría (por no decir que todos) venimos con el sistema más exigente y poco funcional, el principal problema de esto, es que es un salto muy grande que no todos podemos amortiguar, quizá el cambio debería ser un poco mas paulatino, no en un semestre y en una sola materia, es el unico pero que le pongo al sistema de ken, sin embargo como maestro es excelente, aunque siento que se desperdicia ese potencial de maestro al dejarnos tan libres, pero es lo que mencionaba acerca del gran salto de sistema educacional.


WSQ05 – Redo but in a FUNCTIONal way

--Originally published at The Talking Chalk

The Task

Create a program that asks for two integer values and passes them to functions that return their sum, substractions, multiplication, division and remainder.

The Process

The Code

#include <iostream>
using namespace std;

int sum(int first, int second)
{
return first + second;
}
int subst(int first, int second)
{
return first – second;
}
int mult(int first, int second)
{
return first * second;
}
int div(int first, int second)
{
return first / second;
}
int rem(int first, int second)
{
return first % second;
}
int main()
{
cout<<sum(6,9)<<endl<<subst(6,9)<<endl<<mult(6,9)<<endl<<div(6,9)<<endl<<rem(6,9)<<endl;
return 0;
}

The topics

#Calling functions

#Creating functions


WSQ04 – Sum Between

--Originally published at The Talking Chalk

The Task

Create a program that asks for two integer values and prints the sum of all integer numbers between these values.

The Process

The Code

#include <iostream>
using namespace std;

int main ()
{
int big, low, sum=0;
cout<<“Give a number”<<endl;
cin>>low; //User gives value for low
cout<<“Now give a bigger number”<<endl;
cin>>big; //User gives value for big

do
{
low=low+1; //Sums 1 to low, so this low is a number between the original low and big
sum+=low; //Sums the value of low to sum
}
while(low<big); //the process repeats until low is equal to big, so sum will be the sum of all number between low and big
cout<<“The sum of the numbers between the two given is equal to “<<sum<<endl;
return 0;
}

The topics

#Basic output

#Basic input


videojuegos en c++

--Originally published at Aprendiendo a programar en C++

como parte de mi proyecto final, me puse a investigar acerca de los videojuegos y sus principales plataformas, para esto descubrí que si existen videojuegos hechos con c++ solamente que se utilizan otras herramientas para graficos ajenas a c++ pero compatibles, sin embargo si se pueden hacer juegos “vintage” tales como space invaders, snake (juego legendario de celulares nokia) y una infinidad de juegos mas.

En mi caso yo hice un juego similar al ping pong de atari, basicamente por lo sencillo, puesto que un videojuego mas complejo hubiera requerido de mas tiempo y sobre todo conocimientos, para este videojuego precise de librerias graficas tales como SFML, y use code blocks, esto por que asi venia en un curso que estuvo revisando para creacion de videojuegos en c++.

a continuacion les dejare los links de un par de cursos que encontre y utilice para mi proyecto final:

videojuegos c++

videojuegos en c++ (videos)

Al final lo que mas aprendi sobre este proyecto, fue la utilizacion de librerias graficas, que por cierto no forman parte del curso, y que encontre interesantes aunque un poco “raras” al principio.


WSQ03 – RANDOM

--Originally published at The Talking Chalk

The Task

Create a program that generates a random number within 1 and 100, leaving the user to guess which number it is.

The Process

The Code

#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

int main()
{
srand(time(NULL)); //sets the random seed
int actual= rand() % 100 +1, given, counter=0; //Were actual be equal to “rand() % 100, it would have a value between 0 to 99”
cout<<“Guess the number, it has a value from 1 to 100″<<endl;
cin>>given;
count=count+1;
do
{
if(given>actual) //if given number is bigger than the actual one, the user will try again…
{
cout<<“Too high, give a smaller number…”<<endl;
cin>>given;
count=count+1;
}
else if (given<actual) // if given number is smaller than the actual one, the user will try again…
{
cout<<“Too low, give a bigger number…”<<endl;
cin>>given;
count=count+1;
}
}
(while given!=actual)//The loop will be done until given is equal to the actual number

cout<<“You got the right number!”<<endl<<“It took you “<<counter<<” times to get the right number”<<endl;
return 0;

}

The topics

#Importing and using libraries

#Transversal topic: Ability to create C++ file and run from command line (terminal)

 


WSQ02 – Boiling Water

--Originally published at The Talking Chalk

The Task

Create a program that converts farentheit degrees into celsisus degrees and explains if the conditions are proper for water to boil.

The Process

The Code

#include <iostream>
using namespace std;

int main()
{
int degress;
cout<<“Give me a temperature in Farenheit degrees: “<<endl;
cin>>degrees;
degrres = 5*(degrees − 32)/9; //Conversion from Farenheit to Celcius
cout<<“Your temperature in Celcius degrees is: “<<degrees<<“°C”<<endl;
if(degrees>=100)
{
cout<<“Water does boil at this temperature (under typical conditions)”<<endl;
}
else
{
cout<<“Water does not boil at this temperature (under typical conditions)”<<endl;
}
return 0;
}

The topics

#Use of conditional if

#else