1 / 20

TIPOS DE DATOS

TIPOS DE DATOS. DECLARACIONES. Nuestro primer programa. // File: pgm1-4ex6.cpp // Description: 1.4 Exercise 6 // Programmer: N. Ashton // Date: 1/15/2006 #include <iostream> using namespace std; int main() {

cyrah
Télécharger la présentation

TIPOS DE DATOS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. TIPOS DE DATOS DECLARACIONES

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

  3. Estilo en la programacion #include <iostream> 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;}

  4. Temas • Ejemplo de algoritmo • Ejemplo de codificación

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

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

  7. //Se calcula la suma resultado = num1 + num2; • cout <<"La suma de "; • cout << num1; • cout << " + "; • cout << num2;cout << " = "; • cout<< resultado<<endl;

  8. cout << return 0; • }

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

  10. 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

  11. Figure 2-2 C++ Integer Data Types

  12. 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

  13. Table 2-2 The ASCII Uppercase Letter Codes

  14. Integer Data Types (continued) • 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)

  15. Table 2-3 Escape Sequences

  16. 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

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

  18. Table 2-4 Integer Data Type Storage

  19. 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

  20. Table 2-5 Floating-Point Data Types

More Related