#WSQ10

--Originally published at Diego Casillas Yamamoto TC1017

Para sacar una raíz cuadrada por el medio babilonio es simple solo tienes que usar esta formula:

latex.png

que dice que la raíz = a la raíz que ti piensas que es mas en numero al que le quieres sacar raíz entre la raíz que tu crees todo sobre dos.

En mi codigo le puse un ciclo for para que use esta formula 100 veces.

 

Captura de pantalla 2017-05-03 a las 11.28.48.png


#WSQ03

--Originally published at Diego Casillas Yamamoto TC1017

Este codigo es para un programa que genera un numero entre 1-100 al azar y el usuario lo tiene que adivinar y el programa te cuenta las veces que adivinas, al final te pregunta si quieres volver a jugar

 

Captura de pantalla 2017-05-03 a las 10.54.25.pngCaptura de pantalla 2017-05-03 a las 10.54.37.png

 

Mastery Topics:

  1. Nesting of conditional statements (ifs inside ifs)
  2. Use of “else” with a conditional if

Switch Case Example

--Originally published at Diego Casillas Yamamoto TC1017

This code is a switch case example that ask the user to enter a code and it return the type of car the user entered.

// Programa para ver que tipo de carro es por un codigo

#include <iostream>

using namespace std;

int main(){
int code;

cout << “Please enter the code: ” << endl;
cin >> code;

switch (code){
case 11:
cout << “Convertible” << endl;
break;

case 12:
cout << “Coupe” << endl;
break;

case 13:
cout << “Jeep” << endl;
break;

case 14:
cout << “Limusine” << endl;
break;

case 15:
cout << “Sedan” << endl;
break;

case 16:
cout << “Sport” << endl;
break;

case 17:
cout << “SUV” << endl;
break;

case 20:
cout << “Other” << endl;
break;

default:
cout << “Invalid Code” << endl;

}

return 0;
}


Do While

--Originally published at Diego Casillas Yamamoto TC1017

This code is an example for the do while loop.

If you enter a number of hours greater to 23 the program tell you it is invalid and try again

#include <iostream>
using namespace std;

int main(){
int h, m;

do{
cout << “Enter hours” << endl;
cin >> h;
if((h > 23)||(h < 0))
cout << “Not valid” << endl;
}while((h > 23)||(h < 0));
do{
cout << “Enter minutes: ” << endl;
cin >> m;
if((m > 60)||(m < 0))
cout << “Not valid”;
}while((m > 60)||(m < 0));
cout << h << “:” << m << endl;

return 0;
}

 

Mastery Topics:

  1. Use of loops with “while” and “do while”
  2. Nested loops
  3. Create accounts: Blog, Twitter, GitHub

#Quiz11

--Originally published at Diego Casillas Yamamoto TC1017

For this quiz I used the formula that find out the distance between 2 points.

distan16.gif

 

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

int dis(int x1, int y1, int x2, int y2){
int r;
r=sqrt(pow((x2-x1),2)+(pow((y2-y1),2)));
return r;
}

int main(){

int a,b,p,q;

cout << “introduzca dos puntos (x,y)”;
cin >> a;
cin >> b;
cin >> p;
cin >> q;

cout << “La distancia entre los puntos es: ” << dis(a,b,p,q);
}

 

Mastery Topics:

  1. C++ Good Style coding conventions
  2. Importing and using libraries
  3. Calling functions

#WSQ04 Sum of Numbers

--Originally published at Diego Casillas Yamamoto TC1017

#TC1017

This program ask the user for the range to make a sum of the numbers within the range.

#include <iostream>
using namespace std;

int main(){
int sum,beg,fin,i=0;

cout << “From which number would you like to begin? “<< endl;
cin >> beg;
cout << “The last number you would like to sum?” << endl;
cin >> fin;

while (beg<=fin){
sum=sum+beg;
beg++;
}

cout << sum;
}