#WSQ08 Yo soy 196 11/03/17 and WSQ08.cpp

--Originally published at Solving Problems with Programming

PICTURE OF ACTOR

So in this nine week class I started with doing this WSQ09. I started reviewing in creating and calling functions in C++.#Mastery06, #Mastery07, #Mastery16 Use of recursion for repetitive algorithms, #Mastery17 When to use what type of repetition in a program, #Mastery18 Creation and use of Arrays/ Vectors in C++. Futhermore, in this WSQ assignment we have mostly all the topics of the course from 1 to 20.

What I did for this numeric program is solving the problem to the user by creating a program that asks the user for two pieces of data:

  • The lower bound of the sequence
  • The upper bound of the sequence
Then you check the values from the lower bound (inclusive) to the upper bound (inclusive) and make a report of them. During the analysis of each number, if a Lychrel number is found it should be reported immediately with something like “Found a Lychrel number: 196”
The report must show:
  • The range of numbers analysed (lower to upper bound)
  • The number of natural palindromes (no addition to inverse needed)
  • The number of non-Lycherels encountered (become palindromes)
  • The number of Lycherel number candidates (that did not converge to palindrome)

Since you will not be able to prove that a number is Lycherel (since you cannot computer forever to check), our definition for a Lycherel candidate will be if a number does not converge after 30 iterations of applying the addition to the inverse.

To get this working well, you will need support for Big Integers. So I need to use that library that my teacher  ken bauer has given to me, here you go:

This link is for Library of Big Integer provided by ken bauer

Hence, the resources I need it to solve this program are here:

ken bauer

Similar code provided for

wsq8v2
wsq8v3
wsq8v4
wsq8v5
wsq8v6
wsq8v7
wsq8v8
yo soy 196
Continue reading "#WSQ08 Yo soy 196 11/03/17 and WSQ08.cpp"

#WSQ09 Multipart Data and Files 10/03/17 and WSQ09.cpp

--Originally published at Solving Problems with Programming

PICTURE OF ACTOR

So in this nine week class I started with doing this WSQ09. I started reviewing in creating and calling functions in C++.#Mastery06, #Mastery07, #Mastery16 Use of recursion for repetitive algorithms, #Mastery17 When to use what type of repetition in a program, #Mastery18 Creation and use of Arrays/ Vectors in C++.

Futhermore in this assignment we have two new mastery topics covered #Mastery19 Creation and use of strings and #Mastery21 Reading and writing of text files.

What I did for this numeric program is solving the problem to the user by writing a function that receives as parameter the name of a file (this would be a string value like data.txt) and this function counts the number of lines and the number of characters in the file which it returns as a single value (but with two values). I will want to look at how to create/define and return a struct value from a function and how to open and read text files line by line.

Hence, the resources I need it to solve this program are here:

ken bauer

How to convert string to char

C++ Tutorial for Beginners 43 – How to Read from a .txt file using C++

The following photograph shows the solution to this problem:

wsq9v1

wsq9v2wsq9v3wsq9v4

Picture of author

So at first I wrote the same structure of the program just did the same as what i did in Hello World: Second Class, Second Blog (Blog of the second class 12/01/17) and Hello World.cpp,  #WSQ01 Post Fun with Numbers 16/01/17 and WSQ1.cpp#WSQ02 Post Temperature 23/01/17 and WSQ02.cpp#WSQ03 Post Pick a Number 23/01/17 and WSQ03.cpp#WSQ04 Post Sum of Numbers 23/01/17 and WSQ04.cpp#WSQ05 Six Tutorial On To Functions 12/02/17 and WSQ05.cpp#WSQ06 Factorial

charactes
Continue reading "#WSQ09 Multipart Data and Files 10/03/17 and WSQ09.cpp"

RZArector

--Originally published at prgrm.co

Alright WSQ07.

This one had me smacking my pencil against my head for a while. We needed to make a program that asks the user for values and then it gives back the sum, average and standard deviation, using vectors.

Ok, piece of cake! Yeah right, Ken came along and told me to do it with functions, at this point it got interesting.

This is the main() of the program, let’s check it out by parts:

nt main(){
int i, n, thesum = 0;

cout << "Insert the values you want: ";
cin >> n;

vector <float> values(n);

for (i=0; i<n; i++){

cout << "Insert number: " ;
cin >> values[i];
}


cout << endl << "The sum of the values you have selected is: " << sum(values);
cout << endl << "The average of the values you have selected is: " << average(values);
cout << endl << "The standart deviaton of this set of number is: " << standart(values) << endl;

return 0;

}
  1. First important part: vector <float> values(n). As you can see here the vector is being declared then in between “< >” you determine the type variable and finally the name of the vector and how many numbers it will have.
  2. Then the number of values the user will provide the program with:
 int i, n, thesum = 0;

cout << "Insert the values you want: ";
cin >> n;

vector <float> values(n);

for (i=0; i<n; i++){

cout << "Insert number: " ;
cin >> values[i];
}

As you can see here, the program ask the user for the values wanted and then a for loop will store this values in the vector <float> values (n); 

That was the easy part now let’s move on to the functions, the first one will add up all

Continue reading "RZArector"

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.


#WSQ07 Lists 03/03/17 and WSQ07.cpp

--Originally published at Solving Problems with Programming

PICTURE OF ACTOR

So in this eight week class I started with doing the survey of mid semester where I gave ideas in order to improve this course and this and this WSQ07. I started reviewing in creating and calling functions in C++. #Mastery06, #Mastery07, #Mastery16 Use of recursion for repetitive algorithms, #Mastery17 When to use what type of repetition in a program and #Mastery18 Creation and use of Arrays/ Vectors in C++.

What I did for this numeric program is solving the problem to the user by writing 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.Futhermore, Once you have this working, change it so that users keep giving you values until they signal “no more values”. How would you implement this and in particular for the C++ group, how to you deal with an unknown size to your array during compilation?

The quantity of the value depends of the quantity of the type float variable that has only 32 bits of leght, therefore you need a new library in order to increase the value of numbers called Biginteger.hh but I am going to add it in the next WSQ08 called Yo soy 196. Next, to deal with an unknown size of my array during compilation we need to ask the user the number of that size and save it in a variable n.

The resources I need it to solve this program are here:

ken bauer

Similar code made by Eduardo Torres

C Programming Tutorial: Functions (Call By Value, Reference,passing Arrays to function)

The following photograph shows the solution to this problem:

wsq7v2

wsq7v3

wsq7v4wsq7v5

wsq7v6

Picture of author

So at first I wrote the same structure of the program just did the same as

s1
s2
s3
s4
s5
Continue reading "#WSQ07 Lists 03/03/17 and WSQ07.cpp"

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


WSQ06.Factorial-lml.

--Originally published at Programming Path

More loops!! Haha I actually forgot how to do some loops, but thanks to Sergio, I could remember that exist the loop of DO.

The assignment  was to ask the user a non-negative number to find its factorial number. It doesn’t specify if it has to be done as a function or not, but I decided to do it as a function.

Here is the code:

wsq06

It wasn’t that hard, but like I said before, I forgot that I could do a loop with DO.

Thanks for reading.


Post of the week #5 what things I learned in this week #5 ? And Index of Mastery Topics

--Originally published at Solving Problems with Programming

Picture of author

First let me tell you that  I learn and achieved all transversal topics and you can see it in the following link: Post of the week #3 what things i learned in this week #3 ? And Index of Mastery Topics

I also explain my project and formed a small team that corresponds of completing this ability to create C++ project in IDE and run inside the IDE and can be explained in my post My Project For the Course TC1017 and Expo Ing

Futhermore, I am going to present the report of all the Mastery Topics achieved in this week:

  1. #Mastery01 Use of comments, achieved in: Post of the week #2 what things i learned in this week #2 ?
  2. #Mastery02 C++ Good Style coding conventions, achieved in: Post of the week #2 what things i learned in this week #2 ?
  3. #Mastery03 Basic types and their use, achieved in: Post of the week #2 what things i learned in this week #2 ?
  4. #Mastery04 Basic output (print), achieved in: Post of the week #2 what things i learned in this week #2 ?
  5. #Mastery05 Basic user input (text based), achieved in: Post of the week #2 what things i learned in this week #2 ?
  6. #Mastery06 Calling functions, achieved in: #Quiz03
  7. #Mastery07 Creating functions, achieved in: #Quiz03
  8. #Mastery08 Importing and using libraries, achieved in: Post of the week #1 what things i learned in this week #1 ?
  9. #Mastery09 Creating and using your own libraries (program with multiple files), achieved in: #Quiz03
  10. #Mastery10 Use of the conditional “if”, achieved in: #WSQ02 Post Temperature 23/01/17 and WSQ02.cpp
  11. #Mastery11 Use of “else” with a conditional if, achieved in: #WSQ02 Post Temperature 23/01/17 and WSQ02.cpp
  12. #Mastery12 Nesting of conditional statements (ifs inside ifs): #WSQ02 Post Temperature 23/01/17 and WSQ02.cpp
  13. #Mastery13 Use of
    recursion
    int-sumsquare
    double-function
    Continue reading "Post of the week #5 what things I learned in this week #5 ? And Index of Mastery Topics"

Post of the week #4 what things I learned in this week #4 ? And Index of Mastery Topics

--Originally published at Solving Problems with Programming

Picture of author

First let me tell you that  I learn and achieved all transversal topics and you can see it in the following link: Post of the week #3 what things i learned in this week #3 ? And Index of Mastery Topics

I also explain my project and formed a small team that corresponds of completing this ability to create C++ project in IDE and run inside the IDE and can be explained in my post My Project For the Course TC1017 and Expo Ing

Futhermore, I am going to present the report of all the Mastery Topics achieved in this week:

  1. #Mastery01 Use of comments, achieved in: Post of the week #2 what things i learned in this week #2 ?
  2. #Mastery02 C++ Good Style coding conventions, achieved in: Post of the week #2 what things i learned in this week #2 ?
  3. #Mastery03 Basic types and their use, achieved in: Post of the week #2 what things i learned in this week #2 ?
  4. #Mastery04 Basic output (print), achieved in: Post of the week #2 what things i learned in this week #2 ?
  5. #Mastery05 Basic user input (text based), achieved in: Post of the week #2 what things i learned in this week #2 ?
  6. #Mastery06 Calling functions, achieved in: #Quiz03
  7. #Mastery07 Creating functions, achieved in: #Quiz03
  8. #Mastery08 Importing and using libraries, achieved in: Post of the week #1 what things i learned in this week #1 ?
  9. #Mastery09 Creating and using your own libraries (program with multiple files), achieved in: #Quiz03
  10. #Mastery10 Use of the conditional “if”, achieved in: #WSQ02 Post Temperature 23/01/17 and WSQ02.cpp
  11. #Mastery11 Use of “else” with a conditional if, achieved in: #WSQ02 Post Temperature 23/01/17 and WSQ02.cpp
  12. #Mastery12 Nesting of conditional statements (ifs inside ifs): #WSQ02 Post Temperature 23/01/17 and WSQ02.cpp
  13. #Mastery13 Use of
    recursion
    int-sumsquare
    double-function
    Continue reading "Post of the week #4 what things I learned in this week #4 ? And Index of Mastery Topics"

Sum of numbers

--Originally published at my programming blog

This week the activity I needed to do was create a program that would ask the user for two numbers, the lower bound and the upper bound, and the program would give the user the sum of all the numbers from the lower bound to the upper bound.

I had some trouble with this because I was a little confused because every program from my classmates or on the internet were different so when Ken explained it in class I understood.

So what I did was:

  1. Named 3 integers, x,y and sum.
  2. I equaled sum to 0.
  3. Then I asked the user for the lower and upper bound.
  4. I used a while loop so if the user gave me a higher number in the lower bound the program would ask the user to enter the numbers in the right order.
  5. After that I used a condition where if the integers where in the right order there would be a for loop.
  6. In the for loop is like instructions, it is stated that while the int i that is equaled to x is less or equal to y the second number , i will increase.
  7. And then I equaled sum to i.
  8. Finally I printed the sum of the range.

The code:

#include <iostream>
using namespace std;
int main ()
{

int x, y, i, sum=0;
cout<< “Let’s to the sum of all the numbers in a range.”<<endl;
cout<< “Please give me the lower bound: “<< endl;
cin>> x;
cout<< “Please give me the upper bound: “<<endl;
cin>> y;

while (x>y){
cout<<“Please enter the numbers in the right order (from small to big).”<<endl;
cout<< “Please give me the lower bound: “<< endl;
cin>> x;
cout<< “Please give me the upper bound: “<<endl;
cin>> y;
}

if(x<=y){
for(int i=x; i<=y;

screen-shot-2017-02-08-at-11-24-21-am
screen-shot-2017-02-08-at-11-25-12-am
Continue reading "Sum of numbers"