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


Fibonacci is awesome!

--Originally published at Programming Path

My mom always told me about the Fibonacci patterns in nature and how beautiful they are as well that it is so interesting that it’s all mathematics!

I’ve found a TED talk that explain in a very easy way to understand the Fibonacci series. I recommend you to watch it.

The quiz today was precisely of doing a function that gives you a Fibonacci number. What I did was to ask the user a number, and I return the Fibonacci number, or at least that was my intention of asking, but I think that my question isn’t the correct one.

*Just a note. The first Fibonacci numbers are the next one:

0  1  1  2  3  5  8  13  21  34  55  89…

Here is my code:

quiz6

And the result was this:

Enter the number of numbers you want to know of Fibonacci numbers: 10
fibonacci number: 55.

Another try:

Enter the number of numbers you want to know of Fibonacci numbers: 2
fibonacci number: 1.

Thanks for reading.


Fibonacci

--Originally published at Tec Life

So the problem was make to a program to do a fibonacci serie, so in order to do it I search on internet what a fibonacci serie is, and I found that is a serie that sum the two last number and converted in a new one like 2 + 3 = 5 then the next number will be 5 + 3 = 8 and like that until ends, so in order to not crash my computer I put in the main that the user write how many digits the serie would have :).

I made two programs that does the same thing, the only deference is that one uses functions and the other not.

In the program with the function I start writing my function starting on 0 that in case that the user type 0 or 1 is going to return me that number, and in case that the condition doesn’t be true then is going to return me the number – 2 + the number -1 making a serie, but that only is going to one time, so I use a do while to print all the values of the serie, then I use a for to make all the serie appears and thats all :).

And in the other program because the first to number there are not going to repeat I printed first with a cout and then I use my for to start and finish the serie depending the conditions.

And here is and image of jumping corgi in the snow :).

funnocaptura-de-pantalla-2017-03-02-a-las-09-02-46

Have fun

Image from: http://www.artifexbalear.org/img/fibonac8g.jpg and  http://buzzsharer.com/wp-content/uploads/2015/06/jumping-corgi-winter.jpg

 


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.


#WSQ06

--Originally published at OlafGC / Class #TC1017

Long time no see you, guys. This is a blog post for the WSQ06, which is a factorial calculator. The tricky part is to write down the function, to understand the logic of the factorial numbers to teach it to the computer. I used a float because when you get the factorial of a big number things get pretty nasty for an int. And in the end, you just need to write a loop in case the user wants to run the program again (which we’ve already done dozens of times).

Code:

#include <iostream>
using namespace std;
float factorial(float n)
{
float result;
if(n>0)
result=n*factorial(n-1);
else if(n==0)
result=1;
return result;
}
main ()
{
float num, res;
char op;
do{
cout<<“Write the number you want to convert:”<<endl;
cin>>num;
res = factorial(num);
if(res==0)
cout<<“You cannot get factorials from negative numbers.”<<endl;
else{
cout<<“The factorial number is: “<<res<<“.”<<endl;
}
cout<<“Do you want to calculate another number? (y/n) “;
cin>>op;
if(op==’N’||op==’n’)
cout<<“Have a nice day!”<<endl;
else
cout<<“Let’s go again!”<<endl;
}
while(op==’Y’||op==’y’);
return 0;
}

 


Quiz 6

--Originally published at Tec Life

In order to do this quiz I search the information in one site: http://www.cplusplus.com/reference/

We have to solve 5 problems; the first one was about correcting one program and run it, so I use two new libraries in order to solve the program and start testing and rewriting the program, and the final result was this:captura-de-pantalla-2017-02-13-a-las-09-08-45captura-de-pantalla-2017-02-13-a-las-09-09-01

The second problem was about writing a program to read in a character, an integer, and a float, and print out the values, then cast to other types; so that the interaction with the user is something like the following:

captura-de-pantalla-2017-02-22-a-las-21-25-57

captura-de-pantalla-2017-02-22-a-las-21-26-06

The next program was only about to the following pattern:

                        C
                      i   I
                    s       s
                  b           b
                e               e
              s                   s
            t s e b s i C i s b e s t

 

So the only thing that I have to do was print the letters in that order and that was allcaptura-de-pantalla-2017-02-13-a-las-09-42-22

For the fourth problem they ask us to write a program to read three ints and to print them in ascending order, so the most easy thing to do was using a lot of if and else to solve this problem:captura-de-pantalla-2017-02-22-a-las-21-31-32

captura-de-pantalla-2017-02-22-a-las-21-31-43

And the last problem they ask us to write a program given the following rules, write a program to read a year (4 digit integer) and tell whether the given year is/was a leap year.

  1. There were no leap years before 1752.
  2. If the year divides by 400 then it is a leap year.
  3. All other years that divide by 100 are not leap years.
  4. All other years that divide by four are leap years.

So I use the main if as 1752 because if that wasn’t true then the year will be normal, the I use another if to say the conditions when the year will be

captura-de-pantalla-2017-02-23-a-las-08-29-54
captura-de-pantalla-2017-02-23-a-las-08-30-04
Continue reading "Quiz 6"

#WSQ05

--Originally published at OlafGC / Class #TC1017

#include <iostream>
#include <cmath>
using namespace std;

int sum(int n1, int n2)
{
return(n1+n2);
}
int dif(int n1,int n2)
{
return(n1-n2);
}
int pro(int n1, int n2)
{
return(n1*n2);
}
int divi(int n1, int n2)
{
return(n1/n2);
}
int mod(int n1, int n2)
{
return(n1%n2);
}

int main()
{
int n1,n2;
cout<<endl;
cout<<“This program gives you the sum, difference, multiplication, division and the remainder of two given numbers.”<<endl;
cout<<endl;
cout<<“Please insert the first number:”<<endl;
cin>>n1;
cout<<“Please insert the second number:”<<endl;
cin>>n2;
int s=sum(n1,n2);
int d=dif(n1,n2);
int p=pro(n1,n2);
int di=divi(n1,n2);
int m=mod(n1,n2);
cout<<“The result of the sum is “<<s<<“.”<<endl;
cout<<“The result of the difference is “<<d<<“.”<<endl;
cout<<“The result of the product is “<<p<<“.”<<endl;
cout<<“The result of the division is “<<di<<“.”<<endl;
cout<<“The remainder of the division is “<<m<<“.”<<endl;
return 0;
}


Talking Chalk/ OlagGC #FinalProject©

--Originally published at OlafGC / Class #TC1017

So here is the first post about our progress in the project. We have eight weeks left. We had two ideas: the first one consisted on assembling a robotic arm and program it; the second one, in making an app (for cellphone or computer) very similar to Duo-lingo, but instead of learning  new idiom, it will teach you C++. We thought it may be a great support tool (gamification) for learning how to program, helping students on their journey through  Solving Problems with Programming.

sin-titulo

***Update***

This is a link to the latest update of our SUPER ULTRA MEGA ADVANCED, GREAT AND POWERFUL INNOVATIVE PROJECT, a post made by me and The Talking Chalk

on his blog.


Quiz (Week 6)

--Originally published at Programming Path

Well… this was a bit large but I did it. I just didn’t made the post because of partials and to be honest, I forgot that we had quiz and I did not publish it, but here I am.

The quiz had 5 problems, so I will post a lot of photos and codes.

The first problem was this:

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;

This was pretty easy. I just needed to write the same code but in c++. Here is the picture:

quiz5-1

Second problem:

Write a program to read in a character, an integer, and a float, and print out the values, then cast to other types; so that the interaction with the user is something like the following:

	Input a single character, followed by : h
	Input an integer, followed by :  4872
	Input a float, followed by :  182.937
	The character h when cast to an int gives value ?????
	The character h when cast to a float gives value ?????
	The integer 4872 when cast to a char gives value ?
	The integer 4872 when cast to a float gives value ?????
	The float 182.
quiz5-2
quiz5-3
quiz5-4
quiz5-5
Continue reading "Quiz (Week 6)"