Quiz Week 6

--Originally published at Carlos David Mendoza

En este quiz teníamos que hacer 5 programas. Empecemos con el primero:

  1. En este caso teníamos que corregir el siguiente:
    #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;
    }

    Así que para corregir este teníamos que cambiar cout por printf ademas de agregar int antes de sizeof. Me quedo así:

    programa-1 p1

     

     

  2. 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.937 when cast to a char gives value ?
    	The float 182.937 when cast to an int gives value ?????

    Aquí era simplemente hacer el programa y convertir a char, float e int. Queda así: programa-2 p2

    3. Write a program to print the following pattern:

                            C
                          
    programa-3
    p3
    programa-4-1
    programa-4-2
    p4
    programa-5-1
    programa-5-2
    p5
    Continue reading "Quiz Week 6"

Sum of numbers

--Originally published at Carlos David Mendoza

#WSQ04

Mis recursos esta vez fueron el libro, la ayuda de Ken y conocimientos anteriores.

En esta ocasión solo use 3 variables, 2 las cuales son los valores que le pido al usuario y la otra para la formula. Primero use un while por si el usuario me daba primero el número grande y luego el chico, así que mientras el orden fuera el incorrecto, el programa le seguirá diciendo que vuelva a intentar.

Una vez que introduce los valores correctamente el programa continua. Escribí lo siguiente:         while (n1<=n2)

Esto porque dentro del while aumento el valor de n1, y este while me dice que hasta que sea menor o igual que el n2 seguirá haciendo la suma. Aquí esta mi programa:

captura-de-pantalla-2017-02-12-a-las-14-49-32

captura-de-pantalla-2017-02-09-a-las-20-18-18

captura-de-pantalla-2017-02-09-a-las-20-18-20

Y eso seria todo.


#QUIZ04

--Originally published at Carlos David Mendoza

En este quiz teníamos que hacer funciones, en las cuales una me diera el mínimo de 3 números y la otra función me tenia que dar la suma del cuadrado de 3 números. Es importante que primero nombremos las funciones antes de hacer lo de int main().

Para la función en donde tenemos que encontrar el mínimo use ifs para encontrar el mínimo de los tres y luego simplemente como return le puse la variable del mínimo.

Para la función de los cuadrados fue más fácil ya que en el mismo return puse la operación.

Aquí esta mi programa:

captura-de-pantalla-2017-02-03-a-las-11-02-17captura-de-pantalla-2017-02-03-a-las-11-02-21

Y en la siguiente imagen se ve el programa en funcionamiento:

captura-de-pantalla-2017-02-03-a-las-11-04-19


Pick a number

--Originally published at Carlos David Mendoza

#WSQ03

En esta actividad cubro los siguientes Mastery Topics:

  • 8. Importing and using libraries.
  • 13. Use of loops with “while” and “do while”.

Mis recursos esta vez fueron el libro, la ayuda de un compañero, una página de cplusplus y los blogs hechos por otros compañeros.

Aquí abajo se ve mi código en el cuál use una librería random llamada cstdlib. También averigüe que tengo que poner time(NULL) para que realmente funcione el programa y que si sea random.

captura-de-pantalla-2017-01-31-a-las-13-51-06captura-de-pantalla-2017-01-31-a-las-13-51-11

Por último en la siguiente imagen se puede ver el programa en funcionamiento.

captura-de-pantalla-2017-01-31-a-las-13-53-31


#QUIZ03

--Originally published at Carlos David Mendoza

Este ejercicio trataba de que el usuario nos de un número y nosotros hacer una fórmula para que le de la raíz cuadrada y la raíz cúbica.

Mi código fue el siguiente:

Captura de pantalla 2017-01-27 a la(s) 10.37.25.png

Use mis funciones square_root y cube_root para que cuando las use, lo que me regrese sea la raíz cuadrada del número y la raíz cúbica de este mismo. Para esto use las funciones sqrt cbrt las cuales agregue con la biblioteca cmath.

En la siguiente imagen se ve el programa en funcionamiento:

Captura de pantalla 2017-01-27 a la(s) 10.33.13.png


Temperatura

--Originally published at Carlos David Mendoza

#WSQ02

En esta actividad cubro los siguientes Mastery Topics:

  • 10. Use of the conditional “if”.
  • 11. Use of “else” with a conditional if.
  • 12. Nesting of conditional statements (if inside ifs)

Mis recursos fueron el libro usado para esta materia que se encuentra en Page One y conocimientos del semestre pasado.

Mi código es el siguiente en el cual use condicionales y le agregue unos mas para que te diga en que estado está el agua:

captura-de-pantalla-2017-01-26-a-las-13-24-48

En la siguiente imagen se puede ver el programa en funcionamiento:

Captura de pantalla 2017-01-26 a la(s) 13.26.23.png

Eso sería todo. Gracias!


Crazy Numbers

--Originally published at Carlos David Mendoza

#WSQ01

In my code for the “fun with numbers” code I’m covering the next mastery topics:

  • 1. Use of comments
  • 3. Basic types and their use
  • 4. Basic output
  • 5. Basic user input

My resources was the book used for this class and knowledge that I acquired from the semester before.

cin Is something obvious when you know how to use cout, so what I did was to ask the first number, then the second. After this, what I chose to do was to put all the formulas first, giving me the answers using variables. There are different ways and faster and easier ways for doing this code, but meh, I chose this way.

After that, all I had to do was to output the answers.

Here is my code and the program running in the terminal:

captura-de-pantalla-2017-01-19-a-las-21-07-18

captura-de-pantalla-2017-01-19-a-las-21-01-49captura-de-pantalla-2017-01-19-a-las-21-02-24

That´s all!


Hello World

--Originally published at Carlos David Mendoza

First of all, this is my code, I used the help of the book. “Main” is like what states the program, the code goes inside it. “Cout” is what the terminal is printing and “endl” is the end of the line. For now “return 0” means that is the end of the program.

captura-de-pantalla-2017-01-17-a-las-11-13-49

When the code is finished, we have to “save.as” in this case the name of my file is “hellohowareyou.cpp”. We have to put .cpp so that we can state that this is a c ++ program.

captura-de-pantalla-2017-01-17-a-las-11-14-56

Here I show how you start compiling your code, in my case the code is in the desktop in a binder called tec

captura-de-pantalla-2017-01-17-a-las-11-14-20

Then we write the commands to finish the compilation

captura-de-pantalla-2017-01-17-a-las-11-17-46

Finally the code is showed.

captura-de-pantalla-2017-01-17-a-las-11-17-52

Thanks, that´s all.

 

 

 

 

 


How to create a blog

--Originally published at Carlos David Mendoza

This tutorial will be shown step by step, let´s get started.

First of all, in this case, we have to go to wordpress.com

captura-de-pantalla-2017-01-16-a-las-18-31-58

In this page we will choose the option that says “Crear sitio web”.

Once we have chosen this option the next page will open:

captura-de-pantalla-2017-01-16-a-las-18-32-06

In this part we have 3 options that we can choose, that depends on the way you want your page to be.captura-de-pantalla-2017-01-16-a-las-18-32-23

Now something like this will appear, just choose anyone you like. Next you´ll have to create a name for your page.

captura-de-pantalla-2017-01-16-a-las-18-32-40

Now choose the free option to continue, unless you want to pay for something you can get free, but well, it´s your choice.

captura-de-pantalla-2017-01-16-a-las-18-32-48

Finally, all you have to do is put your mail, the name you want, a password of your choice and that´s all, you can now star editing your page and posting blogs!

captura-de-pantalla-2017-01-16-a-las-18-34-12