Can you spot the face? (palindrome)

orlando2120

Photograph Credit

WSQ11, that was fun, wasn’t it? The interesting part was getting to use the big integers. Ken shows us how to do that but I show you how to apply it to a palindrome. I think my program es pretty simple and is easy to understand. See the trick is to separate your problems by sections. So make a function to solve each problem. The video is kind of, sort of long  but I don’t think it’s that tiring to watch so give it a shot. I’m sure you will learn some valuable information in it. Well here is the code:

YoSoy196.cpp

And of course here is the tutorial, enjoy

View original post 4 more words

Quiz 4 Euler Number

Hello people, I was busy for a long time but here I am. This post is about my first quiz of the second partial of the semester. It was not too difficult but I got in trouble with some parts of the code but I finally did it. Well, the instructions for the quiz were:

Create 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 (remember to use absolute value when calculating the difference between two values here).

I search information on Wikipedia about the Euler number to get the idea, and I found interesting information about it: The number e is an important mathematical constant that is the base of the natural logarithm. It is approximately equal to 2.71828,[1] and is the limit of (1 + 1/n)n as n approaches infinity, an expression that arises in the study of compound interest. It can also be calculated as the sum of the infinite series.

Thanks Euler for doing our life easier and harder at the same time.

Here the code of my program.

euleeeeeereulerrrrrrrrr

The new thing here was the SET PRECISION function that I used to call to the user for the number of decimals that he wants to use.

It has to look like that:

#include <iomanip>      // std::setprecision

int main () {
  double f =3.14159;
  std::cout << std::setprecision(5) << f << 'n';
  std::cout << std::setprecision(9) << f << 'n';
  std::cout << std::fixed;
  std::cout << std::setprecision(5) << f << 'n';
  std::cout << std::setprecision(9) << f << 'n';
  return 0;
}

**Don't forget to use the iomanip library to run it without problem.

And the program running:

euruning
dancing-banana
Continue reading "Quiz 4 Euler Number"

Quiz 3

3QFOErL.gifSimplicity is the ultimate sophistication.DaVinci

Hello people. I made my third and the last one of the first partial. We have to create two programs: the first program, may calculate the distance between two points (x1,y1) & (x2,y2). In the second one, we have to create the Fibonacci sequence on C++ and ask to the user for the value that he/she wants. To make that, we use our previous knowledge about it, like conditionals, loops, functions, etc. so it wasn’t difficult.

The instructions were:

1. Write a function called distance(x1, y1, x2, y2) which receives four numbers which represent two points in the cartesian plane. The function should return the distance between the two points (x1,y1) and (x2,y2). Remember that the square of the hypotenuse of a right angle triangle is equal to the sum of the squares of the two other sides. Also, don’t forget to declare the variables with FLOAT to use decimal numbers.

**The new thing here, was the use of the math library, to can execute the square (SQRT in C++). The math library is using like this:

#include <cmath>

And now you can use the formula of the Pitagoras Theorem :

Distance= sqrt((x2-x1)^2+(y2-y1)^2)

Here my code with comments to make it understandable.

dis

And the program running:

disc

2. Write a function called fibonacci which receives a single parameter “n” (a non-negative integer) and returns the nth number in the fibonacci series which is: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89………… So, fibonacci(0) would return 0. fibonacci(5) would return 5 fibonacci(8) would return 21. Note that the first two fibonacci numbers are 0 and 1. All others are the sum of the previous two fibonacci numbers. int fibonacci(int n){ }

Here I got a headache with the Fibonacci Formula, but once

fibc.png
dancing-banana
3QFOErL.gif

Continue reading “Quiz 3”

The best revenge is massive success. –Frank Sinatra

Have a good day! and read those quotes, they’re amazing!.

The two most important days in your life are the day you are born and the day you find out why. –Mark Twain

I am not a product of my circumstances. I am a product of my decisions. –Stephen Covey

Winning isn’t everything, but wanting to win is. –Vince Lombardi

Your time is limited, so don’t waste it living someone else’s life. –Steve Jobs

Every strike brings me closer to the next home run. –Babe Ruth

It’s ok to fail.- Ken Bauer

Jaja, hope you like it.

Regards: EdM.

Quotes taken from http://www.forbes.com/sites/kevinkruse/2013/05/28/inspirational-quotes/#6e180ffe6697

 

Challenge accepted, Quiz 2.

giphy

Hello my friends. I had to mention that we made this quiz some weeks ago, and here is my post about it. I fell nervous when we made the quiz, but after doing my WSQ09 I learned how to use the for Loop and it safe my life. Also lynda (A platform where you can search for information about everything -www.lynda.com-). And if you want to learn more, I suggest to visit this page who helps a lot with C++ (and obviusly to make the programs of this quiz) http://www.cplusplus.com/doc/tutorial/control/ ; on this link, you can find useful information about the loops, who are always necesary, and here another link to understand the functions (I have to read it sometimes because I really get in trouble with it, but now I’m a master on functions ;D). The links:

http://www.lynda.com/C-tutorials/Creating-user-defined-functions/167922/181569-4.html

http://www.cplusplus.com/doc/tutorial/functions/

But well, let’s go to the important think, the quiz.

The instructions were:

1. Create a program with the following function. Write a function called superpower that has receives two parameters (ints) and returns an integer which is first parameter raised to the power of the second, which is to say it returns a b . There are many ways to do this, but the intent is for you to use a loop or recursion.

So to do that, at first, we have to use the function SUPERPOWER and inside of it, we have to do the operation (a^b) -I had a headache doing that- because it wasn’t too difficult but i had my for loop wrong so I had to start again and make it functional. So, here my code with some comments to make it easier.

spp

And the exe.

sppc

2. Create a program with the following function. Write a function called

sts
stsc
giphy-3.gif

Continue reading “Challenge accepted, Quiz 2.”

#WSQ09 Factorial Calculator.

logo-factorial

Hello again people!, this post is about my new program “Factorial Calculator”, and as the name says, it calculates the factorial of the number that you choose. But what is a factorial?

The factorial function (symbol: !) means to multiply a series of descending natural numbers. Examples:

  • 4! = 4 × 3 × 2 × 1 = 24
  • 7! = 7 × 6 × 5 × 4 × 3 × 2 × 1 = 5040
  • 1! = 1

(Information taken from  https://www.mathsisfun.com/numbers/factorial.html).

Here is the code of the program:

fc

As you can see, here we have to use the for loop, and that’s new for me, so we have some problems with it, but finally I learned how to use it and it’s so easy.

The for loop has the next sequence.

for ( the variable that are you going to use as a counter; the condition; and finally the variable with ++ to add 1 when the cycle is repeating)

{

The proccess of the loop

}

It seems like that.

for (int m=1; m<=num1; m++)
{
result=m*result;
}

 

So it was the new thing that i learned with this program, the for loop.

Now, check my program running:

fcgg.png

If you have problems with it, you can see this information:

http://www.tutorialspoint.com/cprogramming/c_for_loop.htm

and if you dont understand clearly, dont feel affraid and ask me!

 

Here my code on GitHub, hope it will be useful for you!.

https://github.com/eduardomrlsg/TC101/blob/master/FactorialCalculator

Regards!

EdM

#WSQ08 On to functions.

FunctionAllTheThings

Hello people! I made a new program about functions, and yes, it’s the same program as the WSQ03, but now using Functions. What is a function on C++? “In C++, a function is a group of statements that is given a name, and which can be called from some point of the program. The most common syntax to define a function is:

type is the type of the value returned by the function.
name is the identifier by which the function can be called.
parameters (as many as needed) ”

(you can find more interesting information here: http://www.cplusplus.com/doc/tutorial/functions/)

And well, that page helps me a lot making my work easier, and as I sayed before, it was a remake of an old program so it was not difficult for me.

Here, the screenshots of my code using functions:

Haga click para ver el pase de diapositivas.

Here the program on Cygwin Terminal:

ofgg

And that’s all.

The functions help us to make our program clear and more easy to understand. We cant forget that to put the “RETURN” at the end of the function to make it workable.

Hope you like it!

Don’t forget to see my codes on GitHub. Click here to see them.

EdM.

 

#WSQ07 – Sum of numbers.

sum-of-consecutive-numbers

Hello people! It’s time of partial exams so I was so bussy studying but here I am with new posts of programming 😀. Well, on this new program we have to ask for a range of integers and then prints the sum of the numbers in that range. For example if we use 9 and 15, the program may do the next addition: 0+9+10+11+12+13+14+15=x. How do we do that?

First, we have to ask for the two numbers to have the range of numbers to make the addition. Then we use a loop (DO-WHILE) to add the following numbers with a counter (++) while the counter be different of the bigger number.

So, here the screenshot of my C++ code.

son

As you can see, the loop do-while help us to make the increase in the lower number until we reach the highest bound.

And the program running:

songggg.png

Dont forget to see my codes on GitHub, click here to see them.

Quiz time, not really bad.

quiz
TC1017 Class

Hello people! I made my first quiz of the class and it was not difficult. It was about the topics that we saw before so I did it so fast.

I felt nervous when Ken gave us the quiz, but after read it I made it without problem. It consists in three programs:

  1. Make a program that calculates the volume of a cylinder.
  2. Make a program that does basic arithmetic operations.
  3. The same as the second but using float (Float uses the numbers with decimals)

Here we used a new command (FLOAT) that is necessary when you want to use decimals numbers on your operations. You have to declare your variables with Float at the begin.

Also I learnt a new command that helps you to separate the message you’re printing to the user. It was (n) and you have to put in the begin of the line that you’re going to print on the board.

For example:

cout<<“Hi my name’s Eduardo.”;

cout<<“nI’m happy with my Flipped Learning.”;

And that runs like that:

Hi, my name’s Eduardo.

I’m happy with My Flipped Learning.

 

And here the screenshot of my programs.

  1. Here we ask to the user for the radius and the height of the cylinder, and then, the program do the operation. Remember that we have to declare the variable PI(3.1416) using the command FLOAT to use decimals numbers.

The screenshots:

prog1

Running:

prog1cpp

2)On this program (It’s the same that the WSQ03 Fun with numbers) we make basic arithmetic operations asking to the user for 2 differents numbers and then make the product, the division and the remainder of the last. Remember that we are using integers numbers so we have to use the command INT.

The screenshots:

prog2

Running:

PROG2g

3) On the last program, we

prog3
prog3c

Continue reading “Quiz time, not really bad.”

#WSQ06 Pick a number. Playing on C++.

game

Hi people. I made a new program on C++ and it’s so cool. I like to do this stuff because is funny and also you learn new commands and variables that are useful on C++. On this game, you have to guess a number between 1-100. Check it and enjoy it!

 

Well, this program made me feel crazy because I didn’t know how to use a random function, but vualá, I checked a friend’s post and it helped me a lot! I searched for information on Sergio post and I found the formula and I saw the video and the pages that he used (https://sercho93.wordpress.com/2016/01/31/pick-a-number/).

And here is the screenshot of my code.

Haga click para ver el pase de diapositivas.

And the screenshot of the program running.

gpckan

On this program, we start using conditionals and cycles on C++. For the cycles, we use the commands DO-WHILE and that repeat an action until it’s false (When the While condition is false). So here, we want to find a random number between 1-100 and to make that, we use the do-while with the condition (number that the user choose != –different of– the number that the program choose), so when the function is true (different) it will repeat the program until you guess the program and the number is the same.

Also we have to use counters, to know how many guesses you need to get the correct number. To print the message of it is to low or to high, we use the conditional IF(that helps you to choose one or another way into the program, because if one it’s false, the another it’s true and with that you can take more than one way).

Another important thing is that the number has to be

maxresdefault

Continue reading “#WSQ06 Pick a number. Playing on C++.”