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

## 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:

TIPOS DE DATOS DECLARACIONES

// 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

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;}

Temas zEjemplo de algoritmo zEjemplo de codificación

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)

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

z //Se calcula la suma resultado = num1 + num2; zcout <<"La suma de "; zcout << num1; zcout << " + "; zcout << num2; cout << " = "; zcout<< resultado< { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/14/4620471/slides/slide_8.jpg", "name": "z //Se calcula la suma resultado = num1 + num2; zcout << La suma de ; zcout << num1; zcout << + ; zcout << num2; cout << = ; zcout<< resultado<

zcout << return 0; z}z}

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

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

Figure 2-2 C++ Integer Data Types

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

Table 2-2 The ASCII Uppercase Letter Codes

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)

Table 2-3 Escape Sequences

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

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

Table 2-4 Integer Data Type Storage

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

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