WSQ #6, Mastery Topic 14

--Originally published at TC1017 Programing Curse

This time i have to create a program that asks the user for a non-negative integer (let’s call that number n) and display for them the value of n! (n factorial), and then ask the user if he want to do it again.

here also we can se the mastery topic 14, the use of for

#include <iostream>
using namespace std;

int factorial (int n)
{
if (n == 0 ){
return 1;
} else {
int mults = 1;
for (int i = 1; i <= n; i++){
mults = mults * i;
}
return mults;
}

}
int main(){
int n;
char ans;
do{
cout << “Escribe un numero positivo ” << endl;
cin >> n;
for (int i = 0; i <= n; i++){
cout << i << ” factorial is ” << factorial(i) << endl;
}
cout << “Do you want another factorial y/n ” << endl;
cin >> ans;
}
while (ans == ‘Y’ || ans == ‘y’);
cout << “Have a nice day ” << endl;
return 0;
}

Resultado de imagen para loop

image taken from: http://codingfreak.blogspot.com/2012/12/detecting-first-node-in-a-loop.htmlwsq6 dowhile.PNG


WSQ #5 On to Functions

--Originally published at TC1017 Programing Curse

i was asked for do the wsq 1 with functions, it was easy, just read the book

there is the code 312.PNGCaptura65

It is just large…

#include <iostream>
using namespace std;

int PrimerNumero, SegundoNumero;

int suma (int PrimerNumero, int SegundoNumero)
{
int suma4 = PrimerNumero + SegundoNumero;
return suma4;
}
int resta (int PrimerNumero, int SegundoNumero)
{
int resta1 = PrimerNumero – SegundoNumero;
return resta1;
}
int multiplicacion (int PrimerNumero, int SegundoNumero)
{
int multiplicacion1 = PrimerNumero * SegundoNumero;
return multiplicacion1;
}
int division (int PrimerNumero, int SegundoNumero)
{
int division1 = PrimerNumero/SegundoNumero;
return division1;
}
int residuo (int PrimerNumero, int SegundoNumero)
{
int res= PrimerNumero%SegundoNumero;
return res;
}
int main ()
{
int PrimerNumero, SegundoNumero;
cout << “El siguiente programa es una calculadora, con esta puedes obtener, suma, resta, multiplicacion y divison ” << endl;
cout << “Escribe tus 2 numeros ” << endl;
cin >> PrimerNumero;
cin >> SegundoNumero;
int suma4 = suma (PrimerNumero, SegundoNumero);
int resta1 = resta (PrimerNumero, SegundoNumero);
int multiplicacion1 = multiplicacion (PrimerNumero, SegundoNumero);
int division1 = division (PrimerNumero, SegundoNumero);
int res = residuo (PrimerNumero, SegundoNumero);
cout << “La suma es ” << suma4 << endl;
cout << “La resta es ” << resta1 << endl;
cout << “La multiplicacion es ” << multiplicacion1 << endl;
cout << “La Division es ” << division1 << ” y el residuo es ” << res << endl;
return 0;
}


Proyecto Final “Calculadora de promedio”

--Originally published at TC1017 Programing Curse

bart-simson_reprobado.jpg

imagen tomada de Urban360 http://news.urban360.com.mx/9/calificaciones-estilo-gringo-en-las-boletas-escolares-de-mexico/

De proyecto final mi equipo y yo realizaremos una calculadora de promedio, que te diga, lo que tienes, lo que necesitas para pasar, y demás…

Esto para todos aquellos que quieren obtener sus calificaciones de una manera más rápida y sencilla.

aquí están los blogs de mis compañeros de equipo:

https://theblacknietzsche.wordpress.com/

 

Resultado de imagen para boleta de calificaciones caricatura

Imagen tomada de https://communications.madison.k12.wi.us/info-para-final-del-semestre-enero-2014


WSQ#04

--Originally published at TC1017 Programing Curse

I have to write a program that asks the userfor a range of integers and then prints the sum of the numbers in that range.

Tarea4.PNG

There is the photo of my program…

but also here is the code in text…

#include <iostream>
using namespace std;

int x, y, i, result = 0;

int main ()
{
cout << “escribe el numero mas chico ” << endl;
cin >> x;
cout << “escribe el numero mas grande ” << endl;
cin >> y;
if (x > y) {
cout << “tu primer numero no puede ser mas grande que el segundo ” << endl;
}
else
{
for ( i = x; i <= y; i++) {
result += i;
}
cout << “la suma de todos los numeros es ” << result << endl;
}
return 0;
}

 


Quiz #9

--Originally published at TC1017 Programing Curse

this quiz ask us to make a progam that ask the user about 2 coordinates, and the program has to calculate the distance between those coordinates.

Resultado de imagen para plano cartesiano

Image taken from Definicion https://definicion.mx/plano-cartesiano/

Captura.PNG

#include <cmath>
#include <iostream>
using namespace std;
double distancia (double x1,double x2,double y1,double y2)
{
double d= sqrt(pow(x2-x1,2)+pow(y2-y1,2));
return d;
}
int main ()
{
double x1, x2, y1, y2;
cout << “escribe tu primer cordenada de x y y ” << endl;
cin >> x1;
cin >> y1;

cout << “escribe tu segunda coordenada de x y y” << endl;
cin >> x2;
cin >> y2;

double d = distancia(x1, x2, y1, y2);

cout << “la distancia entre las dos coordenadas es ” << d << endl;
return 0;
}

Captura.PNG


WSQ3

--Originally published at TC1017 Programing Curse

Guess-What-What-736.png

image taken from memebucket.com… http://www.memebucket.com/guess-what-what/

This code is about guess a number in a range from 1 to 100, it is fun to play but no to do it ?

#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;

int main()
{
int incognit , x, tries;

srand (time(NULL));
incognit = rand() % 100 + 1;

do {
cout << “wich number do you thing it is… ” << endl;
cin >> x;
tries=tries+1;

if (incognit<x){
cout << “The number is lower ” << endl;
}
else if (incognit>x){
cout << “The number is higher ” << endl;
}
} while (secret!=guess);

cout << “You win ” << endl;
cout << “it took you just ” << tries << “attempts” << endl;
return 0;
}


WSQ3

--Originally published at TC1017 Programing Curse

Guess-What-What-736.png

image taken from memebucket.com… http://www.memebucket.com/guess-what-what/

This code is about guess a number in a range from 1 to 100, it is fun to play but no to do it ?

#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;

int main()
{
int incognit , x, tries;

srand (time(NULL));
incognit = rand() % 100 + 1;

do {
cout << “wich number do you thing it is… ” << endl;
cin >> x;
tries=tries+1;

if (incognit<x){
cout << “The number is lower ” << endl;
}
else if (incognit>x){
cout << “The number is higher ” << endl;
}
} while (secret!=guess);

cout << “You win ” << endl;
cout << “it took you just ” << tries << “attempts” << endl;
return 0;
}


Mastery topic 6 & 7

--Originally published at TC1017 Programing Curse

For those mastery topics i had to create functions to do the proccesses, and in int main just the central code, or ask for the user for the number…

Resultado de imagen para funciones meme

Taken from generadomemes.com http://www.generadormemes.com/meme/5xy2ao

#include <iostream>
using namespace std;

int num1;
int num2;
int suma1;

int funcion1 (int num1)
{
num2=num1;
suma1= num2+num1+10;
return suma1;
}

int main()
{
cout << “Escribe un numero” << endl;
cin >> num1;

suma1 = funcion1 (num1);
cout << “el resultado es: ” << endl;
cout << suma1 << endl;

return 0;
}

masterytopic7-y-6