The final boss has been defeated!

--Originally published at Programming Path

At last our final project is finished! It was very interesting to make the code, and to make it run properly. My partner Sergio Iriarte and I decided to program a little game, this was because we both like video games and it sound fun to make a game. It felt more like an achievement.

We came up with the idea of programming the game Battleship. Sergio knows how to program in Java after taking some classes on past years, so we decided to do the game in Java. The reasons were because it is a more simple way of programming, is better organized and much easier to use than C++. And of course he was very patient with me because I am new to this thing they call programming.

After making the decision, I had to install eclipse, it was a total disaster because my computer was very slow, but in the end we could defeat this troublemaker called Battleship.

Here is the code:

Final1final2final3

And here is how we see it when running:

  • * means the user have missed.
  • ~ means the user did not hit that coordinate.
  • X means the user has hit a ship.

Every round, the game gives the user a hint about where could a ship be.

final4

So this is it. We finally finished the project. Just in time for this post ?

 


Lots of Problems (Quiz week 9)

--Originally published at Programming Path

This quiz was veeeery long. There were 10 problems, but we only had to do 8 problems.

1. Escribe el función distancia cual recibe 4 números (x1, y1, x2, y2) cuales representan dos puntos en espacio (x1,y1) y (x2,y2). El método debe regresar la distancia entre los dos puntos. Recuerda que el valor cuadrada del hipotenusa del triangulo es igual que la suma de las cuadradas de los otro dos lados del triangulo (the hypotenuse squared is equal to the sum of the squares of the other two sides).

Quiz9

2. (5 puntos) Escribe un función que se llama triangulo cual recibe un parámetro size y imprime un triangulo derecho como el siguiente. El renglón mas grande debe llevar size numero de “T”. SOLO imprime los “T”s y los endlines. Nota que no hay characteres (espacios) a la derecha de los T’s. Debe usar un ciclo “for” para controlar el repetición.

PQ2

 

3. Escribe la función factorial cual recibe un entero “x” y regresa el valor de x! Recuerda que 0! = 1, 1! = 1, 2! = 2, 3!= 6, 4! = 24, etc. Para los de Python: NO PUEDES usar el factorial como parte del module “math”

PQ3

4. Escribe una función que se llama promedio_lista que recibe un parámetro (una lista (Python) o arreglo/Vector de C++) de valores float y regresa como float el promedio de los números en la lista.

PQ4

5. Escribe una función que se llama smallest_of_four cual recibe cuatro valores float como parametros y regresa el minimo (más pequeño) de los valores. Ojo: puede recibir unos valores iguales.

Click to view slideshow.

6. Escribe una función que se llama fibonacci cual recibe un número n (puedes dar por cuenta que valor mayor o igual que cero) y regresa y valor correspondiente del serie de fibonacci,

PQ6
PQ7.png
PQ10
?
Continue reading "Lots of Problems (Quiz week 9)"

Distance (Quiz week 9)

--Originally published at Programming Path

The assignment of the quiz was to ask for two coordinates and calculate the distance between them. It needed to have floats and a function as well.

This problem was very easy, because in school they made me calculate the distance a lot of times. I only add the math library (<cmath>) because I elevate to the power and resolve a square root.

Here is the code:

Quiz9

Thanks for reading.


THE List -.-‘! (WSQ07)

--Originally published at Programming Path

What a way to give me stress! This task gave me a lot of problems, because it was the first time for me to use arrays, and I looked it in the textbook of the course but didn’t help that much. Then I looked for arrays in the net. I found a tutorial of arrays that explains what are they for and how to use them.

Anyway, the task was this:

Create a program that asks the user for 10 numbers  (floating point). Store those numbers in a list. Show to the user the total, average and standard deviation of those numbers.

We could use arrays or vectors. I didn’t know neither of those, but is never too late to try learn something new. After I understood a little about how do the arrays work I started writing my code. Everything was fine until I needed the standard deviation. To be honest, I did not know what was the standard deviation until this task, I don’t even remember seeing it in elementary school, or middle school, so I had to look for the formula. Here is the formula:

formula
by Kaela Parkhouse

After finding the formula, it gave me a lot more trouble because I had to assign more variables. And that is how I ended up with this code. Not vary proud of this:

#include <iostream>
#include <cmath>
using namespace std;

float total, av, stde, s;
float StandardD (float,float,float,float,float,float,float,float,float,float);

int main () {
float a, b, c, d, e, f, g, h, i, j;
float foo [] = {a, b, c, d, e, f, g, h, i, j};
cout << “Enter 10 numbers. I will give you the total, average and stadard deviation of them.” << endl;
cout << endl << “Number 1: “;
cin >> a;
cout << endl

WSQ07
Continue reading "THE List -.-‘! (WSQ07)"

(WSQ04) Please, don’t joke around

--Originally published at Programming Path

The activity is to run a program where it gives you the sum of a range of numbers, which that range is asked to the user. We needed to be careful if the user inserts the numbers in the wrong order. If that happens then we should put something like “your wrong, please enter it again.

Here is the code:

sum2

Again the code:

#include <iostream>
using namespace std;

int main () {
int l, h, i, r = 0;
cout << “I will sum the numbers in the range you give.” << endl;
cout << endl << “Please enter the lowest number: “;
cin >> l;
cout << “Please enter the highest number: “;
cin >> h;
if (h < l) {
cout << “That number is lower than the first one, please don’t joke around.” << endl;
cout << “Enter the highest number again, please: “;
cin >> h;
}
if (l == 0) {
for (i = 0 ; i <= h; i++) {
r = r + i;
}
}
else {
for (i = l; i <= h; i++) {
r = r + i;
}
}
cout << “The sum from ” << l << ” to ” << h << ” is: ” << r << endl;
return 0;
}

This are the result, with two options:

Wrong order:

I will sum the numbers in the range you give.

Please enter the lowest number: 3
Please enter the highest number: 2
That number is lower than the first one, please don’t joke around.
Enter the highest number again, please: 7
The sum from 3 to 7 is: 25

Right order:

I will sum the numbers in the range you give.

Please enter the lowest number: 3
Please enter the highest number: 7

Continue reading "(WSQ04) Please, don’t joke around"

Easy peasy

--Originally published at Programming Path

Well, I made an exercise of my programming course #WSQ01. It was unexpectedly easy. Of course I didn’t figure it out just by experimenting. I read the book recommended for the course. It is called How to think like a computer scientist. There, I’ve confirmed that it was almost the same commands for adding, subtracting, multiplying and dividing. The only one I couldn’t figure it out by my one was the remainder of the division. So when I read the book, I find the right command.

This was the result for my code, it didn’t take me to long to finished it. Actually, it was fun doing the coding.

mortal

And here it is again:

#include <iostream>
using namespace std;
int main ()
{
int a, b, c, d, e, f, g;
cout << “Insert the first number ” << endl;
cin >> a;
cout << “Insert the second number ” << endl;
cin >> b;

c = a + b;
cout << endl << “Sum of the two numbers = ” << c << endl;
d = a – b;
cout << “Difference of the two numbers = ” << d << endl;
e = a * b;
cout << “Product of the two numbers = ” << e << endl;
f = a / b;
cout << “First divided by second = ” << f << endl;
g = a % b;
cout << “Reminder of integer division = ” << g << endl;

return 0;
}

I really had fun doing this.