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.

Slides:



Advertisements
Similar presentations
CSci 1130 Intro to Programming in Java
Advertisements

Types and Arithmetic Operators
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
TIPOS DE DATOS DECLARACIONES // File: pgm1-4ex6.cpp // Description: 1.4 Exercise 6 // Programmer: N. Ashton // Date: 1/15/2006 #include using namespace.
Javascript Essentials How do I write it??  Start Homesite  Between the start and end BODY tags type: 
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 3: Numeric Data *Variables *Numeric data.
Basic C Programming Data Types and Arithmetic Operations 01/30/15.
Chapter 3 Numerical Data. Topics Variables Numeric data types Assignment Expressions.
Data types and variables
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
JavaScript, Fourth Edition
Chapter 2 Data Types, Declarations, and Displays
Chapter 2: Introduction to C++.
ASP.NET Programming with C# and SQL Server First Edition
JavaScript, Third Edition
String Escape Sequences
1 Chapter Two Using Data. 2 Objectives Learn about variable types and how to declare variables Learn how to display variable values Learn about the integral.
Chapter 2 Data Types, Declarations, and Displays.
Objectives You should be able to describe: Data Types
Java Chapter 2 Creating Classes. Class Defines structure of an object or set of objects; Includes variables (data) and methods (actions) which determine.
Chapter 2 Getting Started in C Programming
A First Book of ANSI C Fourth Edition
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
Operaciones y Variables
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
Chapter 3: Data Types and Operators JavaScript - Introductory.
1 Do you have a CS account? Primitive types –“ building blocks ” for more complicated types Java is strongly typed –All variables in a Java program must.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
CSE 1301 Lecture 2 Data Types Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
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.
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
Lesson 3 – Primitive Data Types Objective: Students will investigate the definition and usage of objects and primitive data types in Java in order to practice.
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.
CHAPTER 4 GC 101 Data types. DATA TYPES  For all data, assign a name (identifier) and a data type  Data type tells compiler:  How much memory to allocate.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Lesson 6 Getting Started in C Programming Hu Junfeng 2007/10/10.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Chapter 3 – Variables and Arithmetic Operations. Variable Rules u Must declare all variable names –List name and type u Keep length to 31 characters –Older.
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
Data Types Declarations Expressions Data storage C++ Basics.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 9, 2005 Lecture Number: 6.
COMP Primitive and Class Types Yi Hong May 14, 2015.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Programming Fundamentals. Summary of previous lectures Programming Language Phases of C++ Environment Variables and Data Types.
Module B - Computation1/61 Module-B-Computation Variables Basic Memory Operations Expressions.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
C++ for Engineers and Scientists Second Edition
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Chapter 14 JavaScript: Part II The Web Warrior Guide to Web Design Technologies.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
CS0007: Introduction to Computer Programming Primitive Data Types and Arithmetic Operations.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
Java Programming: Guided Learning with Early Objects Chapter 1 Basic Elements of Java.
Chapter 2 Variables.
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
Chapter 2: Problem Solving Using C++
ITEC113 Algorithms and Programming Techniques
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
C++ for Engineers and Scientists Second Edition
Chapter 2 Variables.
Chapter 2: Introduction to C++.
Chapter 2 Variables.
Presentation transcript:

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 value for data type Two categories of data types –Built-in (primitive or atomic) such as int or float –Class (user or programmer-defined)

2Object-Oriented Program Development Using C++ Table 2-1 Built-In Data Type Operations

3Object-Oriented Program Development Using C++ 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

4Object-Oriented Program Development Using C++ Figure 2-2 C++ Integer Data Types

5Object-Oriented Program Development Using C++ Integer Data Types (continued) The int data type –Signed integers within compiler specific range –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

6Object-Oriented Program Development Using C++ Table 2-2 The ASCII Uppercase Letter Codes

7Object-Oriented Program Development Using C++ 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)

8Object-Oriented Program Development Using C++ Table 2-3 Escape Sequences

9Object-Oriented Program Development Using C++ 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

10Object-Oriented Program Development Using C++ Table 2-4 Integer Data Type Storage

11Object-Oriented Program Development Using C++ 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

12Object-Oriented Program Development Using C++ Table 2-5 Floating-Point Data Types

13Object-Oriented Program Development Using C++ Arithmetic Operations Five binary arithmetic operators: +, -, *, /, % Binary operators require two operands Syntax template for simple binary expression –literalValue operator literalValue –Example: cout object accommodates evaluation and display

14Object-Oriented Program Development Using C++ Arithmetic Operations (continued) Expression –Combination of operators and operands –Can be evaluated to yield a value Integer expression: operands exclusively int type Floating-point expression: operands exclusively floating-point Mixed-mode expression: result of operation is double precision value

15Object-Oriented Program Development Using C++ Arithmetic Operations (continued) Integer division –Truncates remainder associated with Real division –Examples: 9/3 = 3, 10/3 = 3, 11/3 = 3 –Remainder value captured with modulo arithmetic Negation –Generate negative value by prefixing minus sign (-) –Example: -10 represents negative 10 –Negation is an instance of a unary operation

16Object-Oriented Program Development Using C++ Table 2-6 Summary of Arithmetic Operators

17Object-Oriented Program Development Using C++ Operator Precedence and Associativity Operator precedence: defines hierarchy of operations Three levels of precedence –P1: All negations are done first –P2: Multiplication, division, and modulo operations –P3: Addition and subtraction Parentheses trump normal precedence Associativity: defines operation sequence on level Pn –P1: right to left –P2 and P3: from left to right

18Object-Oriented Program Development Using C++ Table 2-7 Operator Precedence and Associativity

19Object-Oriented Program Development Using C++ Using Variables to Construct a Data Declaration Section Variable: container identified by three parts –Name (represents storage location or memory address) –Data type –Value Programmer selects variable name according to rules Assignment statement stores value in variable –Example: int numOne = 17

20Object-Oriented Program Development Using C++ Figure 2-5 Naming Storage Locations

21Object-Oriented Program Development Using C++ Declaration Statements Declaration instructs compiler to allocate memory Syntax –dataType variableName; –Example: int myNumber; Variables of same type may be declared on same line

22Object-Oriented Program Development Using C++ Initialization Initialization: assigning initial value in declaration Example: float finalGrade = 98.3; Valid initializers –Literals –Expressions with literals –Expressions with literals and previously initialized variables

23Object-Oriented Program Development Using C++ The Data Declaration Section Four variable classifications –Instance, class, local, global –Parameter sometimes included as fifth type Instance variables –Automatically created with declaration –Provided to each created object –Default access set to private (keyword) Class variables: shared by all objects of a class

24Object-Oriented Program Development Using C++ Table 2-8 Determination of a Variable’s Type

25Object-Oriented Program Development Using C++ Memory Allocation Compiler performs several functions –Extracts storage requirements from data type –Associates variable name with memory address –Flags misspelled variables as error (undeclared identifier) Local variables and objects –Declared within a method (or function) –Automatically allocated memory Instance variables: undefined until object creation

26Object-Oriented Program Development Using C++ Figure 2-9A Defining the Integer Variable Named total

27Object-Oriented Program Development Using C++ Summary Built-in data types: range of values and set of operations Programmer-defined types: classes Variable: data type, name, value Variable name represents memory address Initialization: assigning value in declaration

28Object-Oriented Program Development Using C++ Summary (continued) Operand: variables or literal included in expression Operands and operators constitute expression Expressions evaluate to produce value Two sets of operation rules : operator precedence and associativity