Quiz 5

These are the instructions:

  1. Create a function called is_palindrome which receives a string as a parameter and returns true if that string is a palindrome, false otherwise. Remember that a palindrome is a word that is the same forward or backward. For full points your function must ignore case and must work with any character (not just letters). So (“Dad$dad” is a palindrome even though the D is capital and d is lower case).

Captura de pantalla 2016-04-07 a las 14.56.49

In this code, you will need strings, and arrays and also the for loop.
You’ll need to add this library #include <string>

Now to know if it the word is a palindrome, the code must be like this:
int large = word.length();
for (int x = large – 1; x >= 0; x–){
backwards += word[x];
}

the word.length() returns the length of the string, in terms of bytes. So for the “For” loop the loop will be adding the last letter to the first of the word, one by one, and save it in “backwards”. And if the word and backwards are the same, then that is a palindrome.

You can take a look on this web page. http://www.cplusplus.com/reference/string/string/length/

And the Code in GitHub

  1. Create a function called find_threes that receives as a parameter a list (or Vector or array for C++ students) of numbers and returns the sum of all numbers in that list that are evenly divisible by 3. Note if using vectors, you will need an additional parameter to represent the number of numbers in the array. So if the list was [0,4,2,6,9,8,3,12], the function would return 30 (0+6+9+3+12).

 

In this one, the code must look something like this: Captura de pantalla 2016-04-07 a las 15.09.45
If you look well it is pretty simple. The find_threes function has 2 values inside, repeat and number[] (This will use an

Continue reading “Quiz 5”

Quiz 4

We created a function called euler_calc with a single parameter precision. The value of precision is used to determine when to stop calculating. Your calculation will stop when the two consecutive values estimating e differ by less than precision. For example:

Captura de pantalla 2016-04-07 a las 14.13.26

In this code, you’ll need also another function for a factorial because de euler number has this formula:  Captura de pantalla 2016-04-07 a las 14.19.44

so it is 1/factorial with a limit until when the two consecutive values estimating e differ by less than precision. And the precision will be as short or long as you want.

If you calculate the e number on a scientific calculator, the number will be 2.718281828.

First you write the euler function like this euler_cacl (float precision) , with the 2 floats variables, e for the answer, prev for the previous e value; and 1 int = n. Then there’s the loop Do While, and will do e = e / (1/factorial(n)).

The factorial function must be like this, because you can’t have 0* n, because it will return you 0, and you can’t have a 0 as a divisor.

For the While in the euler function, must be while ((e-prev)>precision). The the loop will stop and you will have the answer which is “e”.

Here’s my GitHub link.
https://github.com/antonioangelm24/TC101/blob/master/Quiz%204

 

WSQ09

Captura de pantalla 2016-04-07 a las 14.17.07
This program will give you the factorial value of a number that you will give.
It’s pretty easy. The function has only int x (which is the number that you’ll give) , and in the function you will have the int n (that will be the factorial number at the end) and int i (that is the actual number in the serie).
The loop will give you the product between n*i, and it will save the product in n, and i will be i + 1 every loop. While i  is lower or equal than x.

It is pretty easy.
Here’s the Code in GitHub.

QUIZ 3

This quiz took me a while, not only because I finished it on last class, but I haven’t had time in the partials week.
Anyway, the first quiz was kind of easy because you only needed to follow the formula of the distance of two points in the plane.

 

So I look up in google for the formula and I found this one on http://www.elosiodelosantos.com/sergiman/div/formula_dos_puntos.htm
and the formula wasdistancia_0 and I just create the function of the program based on the formula.
Also, I needed to include the cmath library, in order to be able to use  “sqrt” that is the square root. One of my classmates told me that.Captura de pantalla 2016-02-20 a las 21.10.17

The link of my github account on this code is at the end.

 

For the second exercise, we needed to create a program which can tell you the value of a location in the fibonacci’s serie.
Honestly at the beginning I was so frustrated because I have no idea how to do it. I look up to the formula but i was this one: fibonacci-sequence-formula, and I didn’t understand it. So my friend Miguel gave me a hand. Told to put those 4 integers to use them on my code. Finally with his help we could create this code and I worked. You should see my face at the moment.

Captura de pantalla 2016-02-20 a las 21.10.30

The link to my GitHub account is right here.
https://github.com/antonioangelm24/TC101/blob/master/Quiz%203%20_%202%20-%20Fibonacci

https://github.com/antonioangelm24/TC101/blob/master/Quiz%203_1

 

WSQ08 – on to the functions

This program should give you the same results as the WSQ03 but using function for each operation.

Captura de pantalla 2016-02-16 a las 8.59.42Captura de pantalla 2016-02-16 a las 8.59.47So basically, I write single functions, to the sum, product, difference, and division operations. Using void instead of int. And this was kind of quickly because I just copy the main code from de WSQ03, and then I started to editing what I needed.

Here’s the link to my GitHub.

WSQ08 – On To Functions


Quiz 2

In this quiz, to make the program run, you needed to create also a function.

Like in the first problem. Captura de pantalla 2016-02-16 a las 8.42.12You needed to create the function superpower and to declare the integers a and b in it.
The program should make the result of the first number powered to the second. But all in one function. Also inside the function you need to declare everything you will use, only in the int main, you will type int a, b. Because until then the program ask you for them.

And for the second program:

Captura de pantalla 2016-02-16 a las 8.42.21Kind of the same, but you need to print with * (stars), the number that you provide to the program. So the program print * in the same line, with this loop, until the int n, equals the int a, that it would be the number you’ve written.

Also you don’t need to use “int” with the function, you can use “void” because in this cae you don’t need to return anything.

 

As always, my link to my GitHub:
https://github.com/antonioangelm24/TC101
as Quiz2- a & Quiz2-b

WSQ07- Sum of numbers

This program should give you the sum of a specific range, that you will provide to the computer. So if you type 3 & 9, the program should return the sum of 3+4+5+6+7+8+9.

So.. Captura de pantalla 2016-02-16 a las 8.37.19

First you need to call the two integers of the range, also the result.
I did one work like this when I was in computing remedial.
In this case y & x are the range and x the result.
You keep adding +1 every time until y = z, then you stop.

 

The link to my GitHub is here too..
https://github.com/antonioangelm24/TC101/blob/master/WSQ07

 

WSQ06 – Pick a number

In this WSQ, we created a programm that works like a mini simple viodegame. Guess the correct number.
So, for the computer to choose a random number we use “rand()%100” = x, that will be the mysterious number. Also use srand(time(NULL)) because Ken told to use it. Something about everytime, would be a different number, or something like that. But in the class I’ll ask him again.

Also I checked various blogs from my co-students LOL.

Captura de pantalla 2016-02-16 a las 0.45.04I did something extra here. I Put inly 7 chances to guess the right number, ’cause if you don’t, you’ll lose every talent that you think you have.

Just kiddin, you only will lose the game.

My GitHub link:
https://github.com/antonioangelm24/TC101/blob/master/WSQ06

 

QUIZ-1

In this first quiz, i hadn’t any trouble with any of the exercise, just i forgot to do it in time LOL.

The first programm:Captura de pantalla 2016-02-16 a las 0.30.41.pngWe need to give the volume of a cylinder, and the formula is H*pi*ra^2, so again it was pure algebra. Also I needed to put float, instead of int, because of the decimal point.

In the second one:

Captura de pantalla 2016-02-16 a las 0.30.52I needed to create a programm that works like de WSQ03, asking for two integers, and give back the product, the division, the remainder, etc.

And for the third it was the same as the second, but using float variables.

Captura de pantalla 2016-02-16 a las 0.31.03

Here’s the link to my GitHub also..

https://github.com/antonioangelm24/TC101

 

#WSQ05 – Temperature

First of all, I finally know how to put the picture along side the tittle LOL.
Well this programm was kind of easy, because the instructions gave me the formula.
We needed to convert the temperature grades from Fahrenheit to Celsius, and then tell if the water could boil at that temperature under normal conditions of presure and at the sea level.
You need to use a conditional “IF”, if the temperature is 100 Cº or higher the water will boil, if it isn’t, then the water won’t.

Captura de pantalla 2016-02-16 a las 0.17.33Here’s the link to my GitHub too.

https://github.com/antonioangelm24/TC101/blob/master/WSQ05