Author Archives: Tania Pardo

#Quiz09

Question 1

This is the link for question number 1:

https://github.com/taniaprogram/SolvingProblemsWithProgramming/blob/master/q1p2.cpp

I did not modify anything.

Question 2

This is the link for question number 2:

https://github.com/taniaprogram/SolvingProblemsWithProgramming/blob/master/q2p2.cpp

I did not modify anything.

Question 3

This is the link for question number 3:

https://github.com/taniaprogram/SolvingProblemsWithProgramming/blob/master/q3p2.cpp

In the exam I used recursion, but the asked way to solve this was looping. My original program had a bug that I deleted changed a number in the for loop. So, the correct way to execute the loop for is, until i<=n-2. Before doing this the program works in the correct way.

Question 4

This is the link for question number 4:

https://github.com/taniaprogram/SolvingProblemsWithProgramming/blob/master/q4p2.cpp

In the exam, this program did not compile, my logic was right but my code was not write in the correct way. Then I realized that I did not declare the string in the correct way. Now my program runs, but it has a bug that I could not solve. If the word has zero or one letter, the program prints “Es palindromo”, and this is correct; if the word has more than one letter, the program prints “No es palíndromo”, so, this is the problem, because there is a possibility that the word is palindrome.

#WSQ15

Schedule:

WEEK 1

  • WSQ15
  • Quiz 9
  • Work on masteries (2 points)
  • Work on final project

WEEK 2

  • WSQ16
  • Quiz 10
  • Work on masteries (2 points)
  • Work on final project

WEEK 3

  • WSQ17
  • Quiz 11
  • Work on masteries (2 points)
  • Work on final project

WEEK 4

  • WSQ18
  • Quiz 12
  • Work on masteries (2 points)
  • Work on final project

#WSQ14

In this program you need to estimate the constant “e”, to do this you need to ask the user the number of decimals points, and that will be your precision.

If you want to know about the formula that we are going to use and things about that, you can check this page: http://www.iboenweb.com/ibo/docs/Demostracion%20de%20Formula%20de%20Euler.htm

To organize the program I created a function called factorial, to calculate the factorial that will be introduced in the function calculateE.

The function calculateE is float, because is going to return a non integer number.

The loop do-while, inside the function calculateE, is useful to add the value according with the formula, but this loop will depend by the precision that the user wants.

Finally, you need to truncate the number calculated depending by the precision asked.

Here you can see my code and the program working.

If you don’t know how to round a float, you can check this page: http://stackoverflow.com/questions/11208971/round-a-float-to-a-given-precision/11209099#11209099

Also, here you can find my code:

GitHub: https://github.com/taniaprogram/SolvingProblemsWithProgramming/blob/master/Euler.cpp

Google Drive: https://drive.google.com/file/d/0B-NM4ghaDXBvUEw5RE9nTVZrTjQ/view?usp=sharing

#WSQ13

Babylonian Method is used to calculate square root, and in this program we implemented that method, if you want to know more about it, you can check this link: http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method

First, the program asks the user for a float number; then, babylonian method is implemented in a loop that will be executed while the condition is true.

I think that this program is really simple, because you have the formula, and the only thing that you have to do is convert that formula in code.

Here you can see my code and the program working.

Also, you can find my code here:

GitHub: https://github.com/taniaprogram/SolvingProblemsWithProgramming/blob/master/root.cpp

Google Drive: https://drive.google.com/file/d/0B-NM4ghaDXBvT0V0T1hZVDBfWTg/view?usp=sharing

#WSQ12

For this program I had to calculate the greatest common divisor of two possitive integers, to do this we implemented Euclidean Algorithm, if you want to know more about this you can check this link: http://es.wikipedia.org/wiki/Algoritmo_de_Euclides

I think that this program is really simple, because you only need to evaluate each case and apply the formula.

For this program I think that is useful to know something about functions, because you can implement them and have a program more organized.

Here you can see my code and the program working.

Also you can find my code here:

GitHub: https://github.com/taniaprogram/SolvingProblemsWithProgramming/blob/master/gcd.cpp

Google Drive: https://drive.google.com/file/d/0B-NM4ghaDXBvYk1MT2dwWGhKQXc/view?usp=sharing

#WSQ11

This is an interesting (and kind of difficult) program, because you have to ask the user for the lower bound and the upper bound of a secuence; then, you have to evaluate each number of that secuence, and print how many numbers are natural palindromers, no lycher numbers and lycher number candidates.

I look for some information about lycher numbers in this link: http://en.wikipedia.org/wiki/Lychrel_number

The code has so many lines, so, you can find it here:

GitHub: https://github.com/taniaprogram/SolvingProblemsWithProgramming/blob/master/lycher.cpp

Google Drive: https://drive.google.com/file/d/0B-NM4ghaDXBvVkdRWmhXTmVLNm8/view?usp=sharing

And here you can see the program working.

The only thing that I could not implement is Big Integers library because it has not been updated (you can check more information here https://mattmccutchen.net/bigint/), so, the program does not work with numbers bigger than 100.

Finally, I used math.h or cmath, and you can find information here: http://www.cplusplus.com/reference/cmath/

#WSQ10

This program consists on ask the user for ten numbers and show the user the total, average and standard deviation of those numbers.

I implemented arrays, but is useful to know that this program works with vectors too.

Here you have some pictures, the first one shows my code and in the second one you can show the program working.

The “new” thing in this program is know how to declare and use arrays, but I found it really simple, because once you know how to declare a variable, declare an array is easy, because you follow the same structure.

If you don’t know how to implement arrays, you can look this link, I found it really useful:

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

Also, you can find my code here:

GitHub: https://github.com/taniaprogram/SolvingProblemsWithProgramming/blob/master/Arreglos.cpp

Google Drive: https://drive.google.com/file/d/0B-NM4ghaDXBvVndJMjVhNFE3QW8/view?usp=sharing

#Mastery27

When you validate inputs, you allow that the program works better because all the things that the user writes will be evaluated before to executed a part of code.

In this picture you can see some examples of validating input, one of them validates a “char” and the other an “int”.

Is useful to know that in this example I used “DO-WHILE” to validate the input but you can validate inputs using “FOR”, “WHILE”, “IF”and more…

In the following picture you will see the program working, and you can realize that validating input is really useful to avoid that your program has bugs.

In this link you will find a pp that I did to explain validating input with more detail: https://drive.google.com/file/d/0B-NM4ghaDXBvZzRXNlpqR0I1UXM/view?usp=sharing

And here you will find my C++ code: https://drive.google.com/file/d/0B-NM4ghaDXBvTnNITkxPVXRwRzQ/view?usp=sharing

Finally, in this link I found information that helped me to uderstand the logic for this process: http://stackoverflow.com/questions/2075898/good-input-validation-loop-using-cin-c

#Mastery12

Functions are really useful when you want to structure and organize a program. Stating functions is really easy because you only need to write the type of value that the function will return and between “()” you declare the parameters.

Here you can see a picture of an example:

In this link you can find a pp that I did to explain how to create functions with detail: https://drive.google.com/file/d/0B-NM4ghaDXBvT0hGVmtHM3FDMms/view?usp=sharing

Also, here you can find my c++ code: https://drive.google.com/file/d/0B-NM4ghaDXBvVVI2Nmw3bUNVb0U/view?usp=sharing

Finally, in this link I found useful information to understand this, and I used that information to do my pp: http://www.cplusplus.com/doc/tutorial/functions/

 

#Mastery21

Recursion is when a function calls itself a determinated number of times. This programming technique will help you when when you want to REPEAT the same part of code, that sounds like looping and is easy to understand.

Calculating the factorial of a number is a very good example of recursion. Here you can see a picture:

In the picture is really clear how the function is called again, but the function calls itself until the function gives a result.

I did a pp to explain this with more detail and there you can find more examples of recursion, this is the link:

https://drive.google.com/file/d/0B-NM4ghaDXBvMFZ0TEVTeVFaQ0E/view?usp=sharing

You can find my c++ in this links:

 https://drive.google.com/file/d/0B-NM4ghaDXBvQTlDUk9sTTF3czg/view?usp=sharing

 https://drive.google.com/file/d/0B-NM4ghaDXBvR0taeXlfUEJRcXM/view?usp=sharing

  https://drive.google.com/file/d/0B-NM4ghaDXBvQ3JNdEhFaWFOUWM/view?usp=sharing

Finally, I found useful information here:

http://www.cplusplus.com/articles/D2N36Up4/