25.11.2014 Views

Presentación de PowerPoint

Presentación de PowerPoint

Presentación de PowerPoint

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

JOHN ALEXANDER DIAZ, SC3-UIS<br />

MÓNICA LILIANA HERNÁNDEZ, SC3-UIS, Ing.<br />

Bucaramanga, Septiembre 19 <strong>de</strong> 2012


Presentación<br />

Buenas técnicas <strong>de</strong> programación<br />

Lenguajes <strong>de</strong> programación<br />

Ejercicio


¿Qué NO se <strong>de</strong>be hacer?<br />

"First, solve the problem. Then, write the<br />

co<strong>de</strong>" – John Johnson


Enten<strong>de</strong>r el problema a tratar<br />

Pseudocódigo<br />

Diagrama <strong>de</strong> Flujo<br />

Programación


Enten<strong>de</strong>r el problema a tratar<br />

• Documentación, ejercicios, etc.


Pseudocódigo<br />

• Herramienta para el programador<br />

• Determinar la estructura <strong>de</strong> un algoritmo antes<br />

<strong>de</strong> programarlo<br />

• Lenguaje natural, palabras claves, comentarios


Diagrama <strong>de</strong> Flujo<br />

• Representación gráfica <strong>de</strong>l algoritmo<br />

• Compuesto por símbolos con un significado<br />

<strong>de</strong>finido<br />

• Tener en cuenta a quien va dirigido


Ventajas <strong>de</strong>l Diagrama <strong>de</strong> Flujo<br />

• Facilita la comprensión <strong>de</strong>l algoritmo<br />

• Ilustra la secuencia <strong>de</strong>l algoritmo, permitiendo<br />

encontrar posibles problemas, cuellos <strong>de</strong><br />

botella, redundancia, mejoras <strong>de</strong>l algoritmo, etc.


Algoritmo <strong>de</strong> la amistad by Sheldon Cooper, Ph.D.


Símbolos <strong>de</strong> un Diagrama <strong>de</strong> Flujo


inicio/fin<br />

Entrada<br />

general<br />

Entrada<br />

Decisión<br />

Iteración<br />

Indicar inicio y fin <strong>de</strong>l diagrama.<br />

Entrada <strong>de</strong> datos<br />

Entrada <strong>de</strong> datos por teclado<br />

Dependiendo <strong>de</strong>l resultado se<br />

toma un camino<br />

Instrucción <strong>de</strong>be ejecutarse un<br />

número n <strong>de</strong> veces


Salida<br />

impresa<br />

Resultados serán impresos en un<br />

archivo<br />

Resultados se imprimirán en<br />

pantalla<br />

Proceso<br />

Acción o instrucción que se<br />

<strong>de</strong>be realizar, operaciones, etc.<br />

Flujo, indica la secuencia lógica<br />

<strong>de</strong>l algoritmo


Ejemplo:<br />

• Desarrolle un algoritmo que permita leer dos<br />

valores distintos, <strong>de</strong>terminar cual <strong>de</strong> los dos<br />

valores es el mayor y escribirlo.


Pseudocódigo<br />

1. Inicio<br />

2. Inicializar variables:<br />

A = 0, B = 0<br />

3. Solicitar la introducción<br />

<strong>de</strong> dos valores distintos<br />

4. Leer los dos valores<br />

5. Asignarlos a las<br />

variables A y B<br />

6. Si A = B Entonces<br />

regresa a 3. porque los<br />

valores <strong>de</strong>ben ser distintos<br />

7. Si A>B Entonces<br />

Escribir A, “Es el mayor”<br />

8. De lo contrario:<br />

Escribir B, “Es el mayor”<br />

9. Fin Si<br />

10. Fin


Diagrama <strong>de</strong> Flujo


PROGRAMACION<br />

• Determinar Lenguaje a utilizar, <strong>de</strong>pendiendo <strong>de</strong><br />

la naturaleza <strong>de</strong>l problema a tratar.<br />

• Lenguaje <strong>de</strong> Programación compilado: C, C++<br />

• Lenguaje <strong>de</strong> programación interpretado (script):<br />

Bash, Java, Python, Perl


Lenguaje <strong>de</strong> Programación<br />

compilado<br />

• El programa <strong>de</strong>be<br />

compilarse para po<strong>de</strong>r<br />

ejecutarse, el código<br />

fuente se traduce por<br />

medio <strong>de</strong>l compilador a<br />

un archivo ejecutable.<br />

• Depen<strong>de</strong>ncia <strong>de</strong> la<br />

plataforma<br />

Lenguaje <strong>de</strong> programación<br />

interpretado<br />

• Las instrucciones se<br />

interpretan y ejecutan<br />

una a una en tiempo <strong>de</strong><br />

ejecución.<br />

• In<strong>de</strong>pendiente <strong>de</strong> la<br />

plataforma (portable)


Lenguaje <strong>de</strong> Programación<br />

compilado<br />

• Se usa para problemas<br />

complejos<br />

• Rendimiento (tiempo)<br />

Lenguaje <strong>de</strong> programación<br />

interpretado<br />

• Se usa para realizar<br />

procesos específicos y<br />

puntuales<br />

• Bajo rendimiento (lento)<br />

DOCUMENTAR<br />

CODIGO


Tipo <strong>de</strong> variables<br />

Funciones<br />

Estructura


Declaración <strong>de</strong> variables<br />

Tipo Sintaxis Descripción<br />

Int Int a;<br />

Float Float a;<br />

Double Double a;<br />

Números enteros con 16 bits<br />

[-32768,32767] ó [0,65535]<br />

Números <strong>de</strong>cimales con precisión sencilla<br />

[4 Bytes]<br />

Números <strong>de</strong>cimales con doble precisión<br />

[8 Bytes]<br />

char Char a; 1 carácter 1 Byte [-128,127] ó [0,255]<br />

Vector int Int A[10]; Vector <strong>de</strong> enteros con 10 posiciones<br />

vector char<br />

char A[10];<br />

Vector <strong>de</strong> caracteres con 10 posiciones<br />

(1 palabra o frase)


Declaración <strong>de</strong> variables<br />

double vector[10];<br />

char ca<strong>de</strong>na[256];<br />

char matriz[10][20];<br />

vector[2]=3;<br />

scanf("%d",&vector[7]);


FUNCIONES<br />

Las funciones retornan<br />

valores.<br />

Int SUMA (int a, int b){<br />

}<br />

sum=a+b;<br />

return (sum);<br />

PROCEDIMIENTOS<br />

Son funciones que no<br />

retornan nada y que se<br />

les llama únicamente<br />

para que ejecuten su<br />

código.<br />

printf(“hola mundo”);


ENTRADA-SALIDA<br />

• Printf(“hola mundo”);<br />

• Scanf(“%d”, &a);<br />

• Getchar();<br />

• Putchar();<br />

• fflush(input);<br />

• Fprintf();<br />

• Fscanf();<br />

• Imprimir<br />

• Almacenar<br />

• Almacenar<br />

• Imprimir<br />

• Limpiar buffer<br />

• Imprimir en archivo<br />

• Almacenar <strong>de</strong>s<strong>de</strong><br />

archivo


Manejo <strong>de</strong> archivos<br />

FILE *fopen(char *nombre,<br />

char *modo);<br />

Int fclose(FILE *puntero al<br />

archivo);<br />

modo<br />

“r” Lectura<br />

“r+” Lectura (y escritura)<br />

“w” Escritura<br />

“w+” Escritura (y lectura)


For (i=1; i


If (condición){<br />

//Instrucciones<br />

}//fin if<br />

Else {<br />

//instrucciones<br />

}<br />

//abreviado<br />

Var=(condición)?true:false


switch ( opcion){<br />

case 1:<br />

instrucciones;<br />

break;<br />

}<br />

case 2:<br />

instrucciones;<br />

break;


do-while<br />

do{<br />

instrucciones;<br />

}<br />

while(condición);


while<br />

while(condición){<br />

}<br />

instrucciones;


comentarios<br />

/*comentarios*/<br />

//Inclusión <strong>de</strong> librerías<br />

#inclu<strong>de</strong> // head<br />

//Funciones<br />

Int función(int a, int b);<br />

//<strong>de</strong>claración <strong>de</strong> variables globales<br />

int c; float prom;<br />

/*función principal [main], el contenido <strong>de</strong><br />

la función <strong>de</strong>be ir en llaves*/<br />

int main () {<br />

// <strong>de</strong>claración <strong>de</strong> variables locales<br />

int d;<br />

instrucciones;<br />

}//Fin función main<br />

//<strong>de</strong>sarrollo <strong>de</strong> funciones adicionales<br />

int función(int a, int b) {<br />

// <strong>de</strong>claración <strong>de</strong> variables locales<br />

instrucciones;<br />

} //Fin función


#inclu<strong>de</strong> <br />

#inclu<strong>de</strong> <br />

#inclu<strong>de</strong> <br />

int main(){<br />

int i, datos[4];<br />

for(i=0 ; i


Ecuaciones diferenciales <strong>de</strong> tipo dy/dx=<br />

ax^2 +by +c usando el método <strong>de</strong> Euler.<br />

http://grid.uis.edu.co/images/b/b5/EcuacionesDiferenciales.pdf


INICIO<br />

¿Entiendo<br />

el método<br />

<strong>de</strong> Euler?<br />

NO<br />

SI<br />

¿Seguro?<br />

SI<br />

NO<br />

Ni modo,<br />

hay que<br />

repasar<br />

Perfecto!!<br />

FIN


Metodología<br />

• Analizar el problema<br />

• Pseudocódigo<br />

• Diagrama <strong>de</strong> Flujo<br />

• Programación


El lenguaje comenzó a <strong>de</strong>sarrollarse en 1980.<br />

<br />

<br />

<br />

<br />

<br />

Su autor fue B. Stroustrup, <strong>de</strong> la ATT.<br />

Al comienzo se <strong>de</strong>nomino C with classes y era una extensión <strong>de</strong>l<br />

lenguaje C.<br />

En 1983 toma el nombre <strong>de</strong> C++ y hace referencia al operador<br />

incremento <strong>de</strong> C.<br />

En 1987 ATT comenzó a estandarizar el lenguaje internamente<br />

<strong>de</strong>bido a la gran difusión y éxito que iba obteniendo el mismo.<br />

En 1989 se formó un comité ANSI (seguido algún tiempo <strong>de</strong>spués<br />

por un comité ISO) para estandarizarlo a nivel americano e<br />

internacional.


Los ficheros fuente <strong>de</strong> C++ tiene la extensión *.cpp, en<br />

lugar <strong>de</strong>l *.c utilizado en C.<br />

Declaración simplificada <strong>de</strong> variables tipo enumeración.<br />

Declaración simplificada <strong>de</strong> variables correspondientes a<br />

estructuras.<br />

Mayor flexibilidad en la <strong>de</strong>claración <strong>de</strong> variables.<br />

Conversiones explícitas <strong>de</strong> tipo.<br />

Sobrecarga <strong>de</strong> funciones.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!