RSS

Advertencia

Bienvenidos, Un Blog Diseñado especialmente para la Sociedad Electrónica Universitaria. Todo el material de este BLOG a sido extraído exclusivamente de sitios públicos de Internet , por lo que este material es considerado de libre distribución . En ningún artículo legal se menciona la prohibición de material libre por lo que este BLOG no infringe en ningún caso la ley. Nuestra finalidad, sin un afán de Lucro, es de ofrecer conocimiento a quienes por diferentes motivos no pueden acceder al material educativo Publicado, Promover la Investigación en áreas de Electrónica y Generar Nuestro Propio Conocimiento. El autor de este sitio no asume ninguna responsabilidad sobre el mal uso de esta información. Atentamente: Los Administradores.

Introducción a la Programación en C++

9/3/09



Un Buen, Preciso Para la Asignatura de Programación para Ingeniería
(Para más información del libro hacer clic en Leer más)
Link: MediaFire 1 Mega
http://www.mediafire.com/download.php?dmjmym2fjni


Indice General

1 Conceptos b´asicos de programaci´on 1
1.1 Ordenador y perif´ericos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Bits, bytes y palabras . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Lenguajes de programaci´on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3.1 Lenguajes de bajo nivel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3.2 Lenguajes de alto nivel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.4 Elaboraci´on de un programa . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.5 Traductores . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.5.1 Ensambladores . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.5.2 Int´erpretes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.5.3 Compiladores . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2 Primer contacto con C 7
2.1 Un poco de historia . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.2 Caracter´ısticas del lenguaje . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.3 Creaci´on de un programa . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.4 Primeros pasos con C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.5 El modelo de compilaci´ondeC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3 Empezando a programar 13
3.1 Identificadores . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.2 Estructura de un programa . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.3 Variables y constantes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.3.1 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.3.2 Constantes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.3.3 Entrada y salida de valores . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.4 Expresiones . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.4.1 Operador de asignaci´on. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.4.2 Operadores aritm´eticos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.4.3 Operadores relacionales . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.4.4 Operadores l´ogicos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.4.5 Prioridad de operadores . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.5 Ejercicios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
4 Construcciones condicionales 23
4.1 Construcci´on if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.1.1 Variante if-else . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
4.1.2 Variante if-else-if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
4.2 El operador condicional ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
4.3 Construcci´on switch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
4.4 Ejercicios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
5 Construcciones iterativas 33
5.1 Construcci´on while . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
5.2 Construcci´on do-while . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
5.3 Construcci´on for . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
5.3.1 El operador coma (,) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
5.3.2 Equivalencia for-while . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
5.4 Las sentencias break y continue . . . . . . . . . . . . . . . . . . . . . . . . . . 38
5.5 Ejercicios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
6 Tipos de datos elementales 41
6.1 N´umeros enteros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
6.1.1 Modificadores . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
6.1.2 Resumen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
6.2 Caracteres . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
6.2.1 Caracteres especiales . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
6.2.2 Enteros y el tipo char . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
6.2.3 Conversiones de tipos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
6.3 N´umeros reales . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
6.4 Ejercicios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
7 Tipos de datos estructurados: Tablas 49
7.1 Vectores . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
7.1.1 Consulta . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
7.1.2 Asignaci´on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
7.1.3 Ejemplos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
7.2 Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
7.2.1 Consulta . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
7.2.2 Asignaci´on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
7.2.3 Ejemplo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
7.3 Tablas multidimensionales . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
7.3.1 Ejemplo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
7.4 Cadenas de caracteres . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 577.
4.1 Asignaci´on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
7.4.2 Manejo de cadenas de caracteres . . . . . . . . . . . . . . . . . . . . . . . . . 59
7.4.3 Ejemplos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
7.5 Ejercicios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
8 Otros tipos de datos 63
8.1 Estructuras . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
8.1.1 Declaraci´on de variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
8.1.2 Acceso a los campos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
8.1.3 Asignaci´on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
8.1.4 Ejemplo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
8.2 Uniones . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
8.2.1 Ejemplo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
8.3 Tipos de datos enumerados . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
8.4 Definici´on de nuevos tipos de datos . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
8.5 Tiras de bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
8.5.1 Operador de negaci´on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
8.5.2 Operadores l´ogicos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
8.5.3 Operadores de desplazamiento de bits . . . . . . . . . . . . . . . . . . . . . . 71
8.6 Ejercicios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
9 Punteros 75
9.1 Declaraci´on y asignaci´on de direcciones . . . . . . . . . . . . . . . . . . . . . . . . . 75
9.1.1 Declaraci´on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
9.1.2 Asignaci´on de direcciones . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
9.2 Indirecci´on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
9.3 Operaciones con punteros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
9.4 Punteros y tablas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
9.5 Punteros y estructuras . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
9.6 Ejercicios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
10 Funciones 87
10.1 Generalidades . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
10.2 Definici´on y llamada . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
10.2.1 Definici´on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
10.2.2 Prototipos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
10.2.3 Llamada . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
10.3 Variables y par´ametros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
10.3.1 Variables locales . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
10.3.2 Variables globales . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
10.3.3 Par´ametros formales . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
10.4 Devoluci´on de resultados . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
10.5 Paso de par´ametros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
10.5.1 Paso de par´ametros por valor . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
10.5.2 Paso de par´ametros por referencia . . . . . . . . . . . . . . . . . . . . . . . . 95
10.5.3 Las tablas y las funciones . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
10.5.4 Par´ametros en la funci´on main . . . . . . . . . . . . . . . . . . . . . . . . . 99
10.6 Recursividad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
10.7 Ejercicios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
11 Ficheros 105
11.1 Abrir y cerrar ficheros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
11.2 Leer y escribir en ficheros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
11.3 Otras funciones para el manejo de ficheros . . . . . . . . . . . . . . . . . . . . . . . . 111
11.3.1 feof . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
11.3.2 ferror . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
11.3.3 fflush . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
11.4 Ficheros est´andar: stdin, stdout, stderr . . . . . . . . . . . . . . . . . . . 113
11.5 Ejercicios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
A El preprocesador 119
A.1 Directiva include . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
A.2 Directivas define y undef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
A.3 Directivas ifdef y ifndef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
A.4 Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
B La librer´ıa est´andar 123
B.1 Manipulaci´on de cadenas de caracteres . . . . . . . . . . . . . . . . . . . . . . . . . . 123
B.2 Entrada y salida . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
B.2.1 Entrada y salida b´asica . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
B.2.2 Entrada y salida con formato . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
B.2.3 Ficheros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
B.3 Funciones matem´aticas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
B.4 Clasificaci´on y manipulaci´on de caracteres . . . . . . . . . . . . . . . . . . . . . . . . 128
B.5 Conversi´on de datos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
B.6 Manipulaci´on de directorios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
B.7 Memoria din´amica . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
C Sistemas de numeraci´on 135
C.1 Naturales . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
C.2 Enteros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
C.3 Reales . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
C.3.1 Problemas derivados de la representaci´on en coma flotante . . . . . . . . . . . 138

0 comentarios:

Publicar un comentario

textoalternativo