Presentation is loading. Please wait.

Presentation is loading. Please wait.

TIPOS DE DATOS DECLARACIONES // File: pgm1-4ex6.cpp // Description: 1.4 Exercise 6 // Programmer: N. Ashton // Date: 1/15/2006 #include using namespace.

Similar presentations


Presentation on theme: "TIPOS DE DATOS DECLARACIONES // File: pgm1-4ex6.cpp // Description: 1.4 Exercise 6 // Programmer: N. Ashton // Date: 1/15/2006 #include using namespace."— Presentation transcript:

1

2 TIPOS DE DATOS DECLARACIONES

3 // File: pgm1-4ex6.cpp // Description: 1.4 Exercise 6 // Programmer: N. Ashton // Date: 1/15/2006 #include using namespace std; int main() { cout << "N. Ashton"; cout << "\n123 Main Street"; cout << "\nBoston, MA 02210"; return 0; } Nuestro primer programa

4 Estilo en la programacion #include using namespace std; int main ( ) {cout<< "Reading a program\n"; cout << "is much easier\n" ;cout << " if a standard form for main is used\n" ;cout << "and each statement is written\n" ; cout << "on a line by itself\n" ; system("PAUSE");return 0;}

5 Temas zEjemplo de algoritmo zEjemplo de codificación

6 Ejemplo:Escriba programa para sumar dos números Algoritmo. obtener valores a sumar (num1, num2).Obtener la suma resultado = num1 + num2.Mostrar el resultado (en el monitor)

7 Programa(codificacion // Este programa calcula la suma de dos enteros #include<iostream> int main() { int num1, num2, resultado; num1 = 3; num2 = 4;

8 z //Se calcula la suma resultado = num1 + num2; zcout <<"La suma de "; zcout << num1; zcout << " + "; zcout << num2; cout << " = "; zcout<< resultado<<endl;

9 zcout << return 0; z}z}

10 Built-in Data Types Two categories of data types –Built-in (primitive or atomic) such as int or float –Class (user or programmer-defined)

11 Integer Data Types C++ provides nine built-in integer data types Variations related to storage capacity Most commonly used: int, bool, and char Unsigned data types enforce sign convention

12 Figure 2-2 C++ Integer Data Types

13 Integer Data Types (continued) The int data type –Common storage allocation: 4 bytes Range of values: -2,147,483,648 to 2,147,483,647 The char data type –Stores individual characters (letters, numbers, symbols) –ASCII: standard accommodates 256 codes –Unicode: accommodates 65,536 characters

14 Table 2-2 The ASCII Uppercase Letter Codes

15 The escape character –Escape sequence A backslash followed by one or more characters Example: newline character ‘\n’ –Tells compiler to escape from normal interpretation routine The bool data type –Represents Boolean (logical) –Range of values restricted to 1 (True) or 0 (False) Integer Data Types (continued)

16 Table 2-3 Escape Sequences

17 Integer Data Types (continued) Determining storage size –sizeof ( ) operator: evaluates capacity in bytes –Data type argument inserted between ( ): sizeof(int) Signed and unsigned data types –Signed data type permits zero, positive and negative values –Unsigned data type restricted to zero, positive values char, bool, and other integers

18 #include using namespace std; int main() { cout << "\nData Type Bytes" << "\n--------- -----" << "\nint " << sizeof(int) << "\nchar " << sizeof(char) << "\nbool " << sizeof(bool) << '\n'; return 0; }

19 Table 2-4 Integer Data Type Storage

20 Floating-Point Types Floating-point numbers are real numbers Include decimal point in explicit references; e.g., 3.0 C++ supports 3 types: float, double, long double Exponential Notation –Alternative system for representing floating- point data –Similar to scientific notation –Example: 5.67e2 Assume base 10. Letter ‘e’ = exponent, 2 = power

21 Table 2-5 Floating-Point Data Types


Download ppt "TIPOS DE DATOS DECLARACIONES // File: pgm1-4ex6.cpp // Description: 1.4 Exercise 6 // Programmer: N. Ashton // Date: 1/15/2006 #include using namespace."

Similar presentations


Ads by Google