Fibonacci Number!

--Originally published at Loading…

Hi! I know that I should have posted this since Friday, but I couldn’t post it before.

This quiz was a kind of… different, at the begging I didn’t understand very well it said:

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.

I know the Fibonacci series since the elementary school and I think it is absolutely AMAZING! But I didn’t know there was a formula to calculate any number in the series and that was the interesting part about this quiz, Ken gave us a very clearly explanation about it.

This is my code:

fibonacci01fibonacci02

While I was searching about the Fibonacci number and how my others classmates did this quiz, I found this page and I copied and pasted it one of the codes to print the series int he program, I know it’s wrong but it gave me a little laziness to do it by myself. It easier made the program with a function. At the begging I don’t understand how I supposed to count the numbers in the series but then Ken explained me that I have to star with the 0 like 0, 1, 2, 3… and this is how it works:

fibonacci03

P.S: It supposed that between the 0 and the 1 there should be a space.


List…

--Originally published at Loading…

Activity:

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.

This one was a little difficult because I didn’t know NOTHING about arrays or vectors in C++, that’s the reason why I didn’t submit nothing in the las 2 weeks. No matter how much I read or investigate in the book or internet, I didn’t understand how it works, until I found this classmate’s post and it was like the illumination for me. So, this is my code:

list

First I added the library <cmath> for the program recognize the operations. Then in my int main, I established my variables as float, and to make the list I used an array, for this you put a name, in my case “list”, then add the [ ] and in the middle you establish how many numbers you want to store, in this activity we want to store 10. The rest is ‘easy’ you just need to be careful in the operations, pow is a function of exponents and for the rest I think it doesn’t needs much explanation, anyway if you have any question you can leave a comment and I’ ll answer you. I hope I was able to help you.

This is how it works:

list02


Now I know what I’m doing!

--Originally published at Loading…

Hi!!! I know it’s been a long time since my last post (14 days to be exact), but I was… “busy”? Well… whatever, know I’m back , and I’m not lost as at the beginning of the semester

The truth is that not much has happened during these two weeks, we made our exam without value for the grade, but i just did it to prove me if I’m really learning, and guess what? YES I AM!! ? Also, we already finish with the first parcial #OMG, this semester is going too fast.

Actually I’m very surprised for what I have achieved in this time, honestly at the start of the course i had many doubts especially if i’m really going to learn something in this “new way” of teaching, but now I know that I can learn by myself and with little bit of help of my classmates, I hope at the final of the course I can be like a Jedi or at least I can program like a pro.


Quiz 6

--Originally published at Loading…

I decided to make Quiz 6 before the Activity 7, because it seemed to me would be simpler, also the quiz is for this week. BUT this quiz was too different that the others, it was more time-consuming  and really tested me.

We had to do the first 5 exercises of this page, and they were a little bit different from what normally we do. I did them in disorder, but here they all are.

Activity 1, run a program.

This one was one of the most difficult, and not precisely because it was too hardcore, more like, it wasn’t running correctly through the fault of a parenthesis in the wrong place.

So, the activity was:

Type in the following program and run it:

#include 
main()
{ /* PROGRAM TO PRINT OUT SPACE RESERVED FOR VARIABLES */
	char c;  
	short s;  
	int i;  
	unsigned int ui;  
	unsigned long int ul; 
	float f;
	double d;  
	long double ld;  
	cout << endl 
  	     << "The storage space for each variable type is:"
	     << endl;
	cout << endl << "char: \t\t\t%d bits",sizeof(c)*8;  //  \t means tab 
	cout << endl << "short: \t\t\t%d bits",sizeof(s)*8;
	cout << endl << "int: \t\t\t%d bits",sizeof(i)*8;
	cout << endl << "unsigned int: \t\t%d bits",sizeof(ui)*8;
	cout << endl << "unsigned long int: \t%d bits",sizeof(ul)*8;
	cout << endl << "float: \t\t\t%d bits",sizeof(f)*8;
	cout << endl << "double: \t\t%d bits",sizeof(d)*8;
	cout << endl << "long double: \t\t%d bits",sizeof(ld)*8;

First I completed what it was needing to the program, added the libraries & , wrote using namespace std; (as always), and wrote int before the main. Then I substituted the cout << endl << for printf(. Later, in order to make sizeof( )*8 works Ken said that we need to wrote int( before. And that’s all, this is my code:

quiz6-1

With this activity I learned to use \t for add

quiz6-2
quiz6-3
quiz6-4
quiz6-5
whatsapp-image-2017-02-14-at-10-54-35-pm
whatsapp-image-2017-02-14-at-10-57-10-pm
Continue reading "Quiz 6"

Factorial Calculator

--Originally published at Loading…

This one was a little harder than the others, and it was a challenge to begin with because I couldn’t remember what is a factorial. But after I asked Ken and he explained me ( )…ie_factorial__6…the activity, it wasn’t too difficult. The activity consist in this:

Create a program that asks the user for a non-negative integer (let’s call that number n) and display for them the value of n! (n factorial).

After showing them the answer, ask them if they would like to try another number (with a simple y/n response) and either ask again (for y) or quit the program and wish them a nice day (if they answered n).

So, the first thing was do a function for the factorial, I established this function with the loop for, I wasn’t too sure of how doing it, so with the help of one page of Google and a classmate’s blog I could do it . In my main I established my variables as int and char, and then add the loop do/while for repeat until the user said no. Inside the “do” I put an if for the case that the number should be negative. This is my code:

factorial01factorial02

And this is how it works ?:

factorial03


Now with functions!

--Originally published at Loading…

This one was pretty easy! Actually we had to do the same that in our first program but now using a function for every operation. So now that I already know how to do functions was simple enough and fast to do this activity.

The first thing that I did was open my WSQ01 project and I copied and pasted it in a new file. I wasn’t sure if there exist functions for each operation, so I googled and this page really helped me to do all the activity.

These are my functions, easy: function0And this is the main, what the program shows:
function01And it runs correctly… I think. function02

I hope I was able to help you, if you have any question don’t doubt to send a message.


X<Y and X*X (Minimum and Squares)

--Originally published at Loading…

Today we had our 4th quiz, actually the semester is going very fast 🙄. Ken said:

I want you to (in class) create a program with two functions:

  • int minimumThree(int x, int y, int z){ }  // returns the value that is smallest of x, y and z
  • int sumSquares(int x, int y, int z) {}  // returns the value of the sum of squares of x, y, z

At the begging I was very lost cause I didn’t know how to make that, so I start looking what my other classmate did, and honestly it confused my a little cause everyone had something different, only one post really help me, but then Ken explained what is the function and how it’s supposed to work and then the knowledge finally comes to my.

So I make the function of minimumThree with a if/else if/else for give the smallest value. And the sumSquares I did by multiplying the variables by its self (like the title). The rest is pretty easy, you just write what you want the program “said”. This is my code:

quiz4

 Its very importan that in the function you establish what value does it supposed to return.

quiz4-1


Numbers… again?

--Originally published at Loading…

Yes, but this activity was different, the #WSQ04 said:

Write a program that asks for a range of integers and then prints the sum of the numbers in that range (inclusive).

You can use a formula to calculate this of course but what we want you to do here is practice using a loop to do repetitive work.

This one was easy, don’t even need to add an extra library. And because I don’t start the chapter 3 of the book yet (#sorry ☹️), I decided to do it with the functions and loops that I already know. First I read the hole activity very well, and checked my other classmate’s works to understand how to do it, and in my head I made a flowchart.

As usually first I established my variables as int, put the “instructions” using cout, and wrote the operations. Then I added an if for the condition that both numbers were equal, and in the else part I put the do/while loop for make the addition. So, this is the code in the easy form, with nothing extra:

num

After proving that the program runs correctly, I decided to do my “extra” 💪🏼, so, I added an else if  for the condition that the “higher” number was lower than the “lower” number. Everything that I did was, literally, copy/paste what I already had and insert it inside the function. And voilà ? this is my code at the final:

num3num2

?

num4


I have a number chosen between 1 and 100.

--Originally published at Loading…

The activity was:

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

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.

So the first step was to remember how to generate random numbers, and as always I searched it in St.Google, and I found a very good page that helped my a lot. I add the <ctime> and <cstdlib> libraries to make the program works. Then I established my 2 variables with int, I wrote srand(time(NULL)), for make the number always random, and the equation.

To make that the program continue until the user guesses I add a do/while function, that includes an if function to set the parameters and give the hints of ‘too high’, ‘too low’ or BRAVO, if you guess. Before to making something more pro, I wanted to be sure that it works correctly, I compiled and guess what… It didn’t do it, you will never guess the number, i don’t know why but it change it every time, so I looked for help and I found it in a classmate’s blog, he has a char command with a condition, so I try it in my program and it works, so that was the solution. At the final I add an extra variable to count the opportunities, and an if to show if your a loser or a winner. This is my code at the final:

randrand02


There was quiz today?!

--Originally published at Loading…

Yes, today we did our 3rd quiz, and it was… “easy”? At first, when I read what we have to do my face was a little like this 😕 because I didn’t read the chapter 3 and I don’t have idea what I have to do, but Ken show us a code, I Googled and compared it with some of the codes that my classmates had in their blogs, at the end I understand what I was doing with all that. This is my code:

qp qp2

First I had to add the <cmath> library in order to make my functions works, the square and cube root functions. Also I used double for my variables, so it could give me decimal numbers, I declared everything like the ecuation and the cout. After I add a if fuction, if the number that the user gives was negative, then a do/while start, so it ask for a new number, and a nesting of conditional statements for if the case repeats (negative number).

And this is how it runs:

qp3

I know it’s a little late, but I swear I did it in class.