Use of diferent Functions

--Originally published at how not to program

Here is a code showing diferent functions

#include <iostream>
using namespace std;

int num1, num2, res, dif, mul;
float div;
int resta(int a, int b)
{
dif = a – b;
return (dif);
}
int mult(int a, int b)
{
mul = a * b;
return (mul);
}
int residuo(int a, int b)
{
res = a % b;
return (res);
}
float division(int a, int b)
{
div = a / b;
return (div);
}

int main(){
cout << “Introduce dos numeros. ” << endl;
cin >> num1 >> num2;
cout << “La resta es: ” << resta(num1,num2) << endl;
cout << “La multiplicacion es: ” << mult(num1,num2) << endl;
cout << “El residuo es: ” << residuo(num1,num2) << endl;
cout << “La division es: ” << division(num1,num2) << endl;
return 0;
}


Guess the code

--Originally published at how not to program

Here is an other guess the code, guess what the code do in the comments

#include <iostream>
#include <string>
using std::string;
using std::cout;
using std::cin;
using std::endl;

int main(){
string palabra, alreves, respuesta;
cout << “Dame la palabra ” << endl;
cin >> palabra;

// cout << palabra;

int tamano = palabra.length();
for(int i = tamano-1; i>=0; i–){
// cout << palabra[i];
alreves = alreves + palabra[i];
}
cout << alreves << endl;
if(palabra == alreves)
{
cout << “Es palindromo ” << endl;
}
else
{
cout << “No es palindromo ” << endl;
}
}


Guess the code

--Originally published at how not to program

Here is a new code, guess what it does

#include <iostream>

using namespace std;

int a , b, c, d;

int main()
{
cout << “escribe un numero” << endl;
cin >> a;
cout << “escribe otro numero” << endl;
cin >> b;
cout << “escribe otro numero” << endl;
cin >> c;
cout << “escribe otro numero” << endl;
cin >> d;
if (a>b){

if (a>c)
{
if (a>d){

cout << “El primer numero es mas grande que todos ” << endl;
}
}
}
else {

cout << ” mejor me mato ” << endl;
}
return 0;
}


Use of comments

--Originally published at how not to program

Here is a code of how to use comments

#include <iostream>

using namespace std;
// Add a Double “//” then just type. The program will ignore the text after the “//”
int main()
{
cout << “Hello world!” << endl;
// No matter where in the code it is

/* you can also use “/*” to start a coment but you need to close it just like a parenthesis with “* /” */

return 0;

}


L’ê.

--Originally published at prgrm.co

In this WSQ, we had to calculate the value of e, to a desired lenght.

I watched this video that explains what e is.

#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
    int A, B;
    double E, D;
    
    for (A=1; A<=15; A++ )
    {
        D=1;
        for (B=1; B<=A ; B++ )
        {
            D = D * B;
        }
        E = E + 1 / D;
    }
    cout<<setprecision(10)<<"Estimated Value of e is "<< E + 1 <<endl;
    system("pause");

WSQ13 – Scilab

--Originally published at The Talking Chalk

Seemengly, Scilab is a program similar to raptor in the context of his simplicity; however, it allows you to plot graphs and it has already a mathematics library included by default.

Investigating more on the software in http://www.scilab.org/scilab/about I found that it is indeed a mathematical operations solving software that allos to plot graphs (even in three dimensions), create simulations and store data.

1cap2

The Topics

#Data analyis

#Visualization of data with tools


Final project

--Originally published at how not to program

Here is the final result of our final project. its about a code that gets the coordenates for a solid for you to graph it. I worked with Josue reyes and Rodrigo Zermeño

#include <iostream>
#include <fstream>
#include <cmath>
#define pi 3.14159

using namespace std;

char figura;
int HP, LP1, LP2, HC, RC;
float x, y, z;

int main(){
cout << “Que figura quieres (C=Cilindro/P=Prisma): “;
cin >> figura;
if((figura== ‘c’) || (figura== ‘C’)){
cout << “Ingresa la altura en milimetros (No mayor a 1000 mm): ” << endl;
cin >> HC;
cout << “Ingresa el radio en milimetros (No mayor a 1000 mm): ” << endl;
cin >> RC;
ofstream myfile;
myfile.open(“ArchivoCilindroProyecto.txt”);
myfile << “Las coordenadas del cilindro son: ” << endl;
for(z=0; z<=HC; z++){
for (int x=RC; x>=-RC; x–){
y=sqrt(pow(RC,2)-pow(x,2));
myfile << “(” << x << “,” << y << “,” << z << “)” << endl;
}
for (int x=RC-1; x>=-RC+1; x–){
y=sqrt(pow(RC,2)-pow(x,2));
myfile << “(” << x << “,-” << y << “,” << z << “)” << endl;
}
for (int y=RC; y>=-RC; y–){
x=sqrt(pow(RC,2)-pow(y,2));
myfile << “(” << x << “,” << y << “,” << z << “)” << endl;
}
for (int y=RC-1; y>=-RC+1; y–){
x=sqrt(pow(RC,2)-pow(y,2));
myfile << “(-” << x << “,” << y << “,” << z << “)” << endl;
}
}
}else if((figura== ‘p’) || (figura== ‘P’)) {
cout << “Ingresa la altura en milimetros (No mayor a 1000 mm): “;
cin >> HP;
cout << “Ingresa el lado 1 de la base en milimetros (No mayor a 1000 mm): “;
cin >> LP1;
cout << “Ingresa el lado 2 de la base en milimetros (No mayor a 1000 mm): “;
cin >> LP2;
ofstream myfile;
myfile.open(“ArchivoPrismaRectangularProyecto.txt”);
myfile << “Las coordenadas del Prisma

Continue reading "Final project"