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

Slides:



Advertisements
Similar presentations
1 Lecture 7  Fundamental data types in C  Data type conversion:  Automatic  Casting  Character processing  getchar()  putchar()  Macros on ctype.h.
Advertisements

Types and Variables. Computer Programming 2 C++ in one page!
1 9/10/07CS150 Introduction to Computer Science 1 Data Types Section 2.7 – 2.12 CS 150 Introduction to Computer Science I.
1 9/8/08CS150 Introduction to Computer Science 1 Data Types Section 2.7 – 2.12 CS 150 Introduction to Computer Science I.
Data types and variables
The Fundamentals of C++ Basic programming elements and concepts JPC and JWD © 2002 McGraw-Hill, Inc.
How Create a C++ Program. #include using namespace std; void main() { cout
CS150 Introduction to Computer Science 1
JavaScript, Fourth Edition
Chapter 2 Data Types, Declarations, and Displays
Chapter 2: Introduction to C++.
JavaScript, Third Edition
Basic Elements of C++ Chapter 2.
Chapter 2 Data Types, Declarations, and Displays.
Objectives You should be able to describe: Data Types
Input & Output: Console
3. The Nuts and Bolts of C++ Computer Programming 3. The Nuts and Bolts of C++ 1 Learning the C++ language 3. The Nuts and Bolts of C++ (4)
CS1 Lesson 2 Introduction to C++ CS1 Lesson 2 -- John Cole1.
Chapter 2: Using Data.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
CPS120: Introduction to Computer Science
Lecture #5 Introduction to C++
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
The Fundamentals of C++ Chapter 2: Basic programming elements and concepts JPC and JWD © 2002 McGraw-Hill, Inc. Modified by S. Sudarshan.
C++ Programming: Basic Elements of C++.
Knowledge Base C++ #include using std namespace; int main(){} return 0 ; cout
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Lecture 3: The parts of a C++ program (Cont’d) Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
VARIABLES AND DATA TYPES Chapter2:part1 1. Objectives: By the end of this section you should: Understand what the variables are and why they are used.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 9, 2005 Lecture Number: 6.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
Lab 4 - Variables. Information Hiding General Principle: – Restrict the access to variables and methods as much as possible Can label instance variables.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Chapter 7 C supports two fundamentally different kinds of numeric types: (a) integer types - whole numbers (1) signed (2) unsigned (b) floating types –
C++ Programming Lecture 3 C++ Basics – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
Programming Fundamentals. Summary of previous lectures Programming Language Phases of C++ Environment Variables and Data Types.
1 Comments Allow prose or commentary to be included in program Importance Programs are read far more often than they are written Programs need to be understood.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
C++ for Engineers and Scientists Second Edition
Objects Variables and Constants. Our Scuba Problem #include // cin, cout, > using namespace std; int main() { const double FEET_PER_ATM = 33.0, LBS_PER_SQ_IN_PER_ATM.
Types Chapter 2. C++ An Introduction to Computing, 3rd ed. 2 Objectives Observe types provided by C++ Literals of these types Explain syntax rules for.
Types Chapter 2. C++ An Introduction to Computing, 3rd ed. 2 Objectives Observe types provided by C++ Literals of these types Explain syntax rules for.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
1 Objects Types, Variables, and Constants Chapter 3.
1 A more complex example Write a program that sums a sequence of integers and displays the result. Assume that the first integer read specifies the number.
7. BASIC TYPES. Systems of numeration Numeric Types C’s basic types include integer types and floating types. Integer types can be either signed or unsigned.
CS0007: Introduction to Computer Programming Primitive Data Types and Arithmetic Operations.
1Object-Oriented Program Development Using C++ Built-in Data Types Data type –Range of values –Set of operations on those values Literal: refers to acceptable.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
1 ENERGY 211 / CME 211 Lecture 3 September 26, 2008.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
C++ Lesson 1.
C++ First Steps.
Documentation Need to have documentation in all programs
Computing Fundamentals
Variables A variable is a placeholder for a value. It is a named memory location where that value is stored. Use the name of a variable to access or update.
Chapter 2: Problem Solving Using C++
Chapter 2: Introduction to C++
C++ for Engineers and Scientists Second Edition
2.1 Parts of a C++ Program.
Escape Sequences Some Java escape sequences: See Roses.java (page 68)
CISC 1600/1610 Computer Science I
Variables T.Najah Al_Subaie Kingdom of Saudi Arabia
Chapter 2: Introduction to C++.
C++ Programming Lecture 3 C++ Basics – Part I
C++ Programming Basics
Programming Fundamental-1
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<iostream> 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<<endl;

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