Data Types, Identifiers, and Expressions

Slides:



Advertisements
Similar presentations
Types, Variables and Operators Computer Engineering Department Java Course Asst. Prof. Dr. Ahmet Sayar Kocaeli University - Fall 2013.
Advertisements

IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
JavaScript, Third Edition
110-D1 Variables, Constants and Calculations(1) Chapter 3: we are familiar with VB IDE (building a form…) to make our applications more powerful, we need.
Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data.
The Data Element. 2 Data type: A description of the set of values and the basic set of operations that can be applied to values of the type. Strong typing:
JavaScript – Part II Data Types and Operations George Mason University June 3, 2010.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
Computer Science 210 Computer Organization Introduction to Boolean Algebra.
Chapter 2: Using Data.
1 st Semester Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
Programming Fundamental Slides1 Data Types, Identifiers, and Expressions Topics to cover here: Data types Variables and Identifiers Arithmetic and Logical.
Computer Engineering 1 st Semester Dr. Rabie A. Ramadan 3.
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
Arithmetic Expressions in C++. CSCE 1062 Outline Data declaration {section 2.3} Arithmetic operators in C++ {section 2.6} Mixed data type arithmetic in.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Tokens in C  Keywords  These are reserved words of the C language. For example int, float, if, else, for, while etc.  Identifiers  An Identifier is.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
1 st Semester Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Java Programming: Guided Learning with Early Objects Chapter 1 Basic Elements of Java.
Chapter Topics The Basics of a C++ Program Data Types
Computer Science 210 Computer Organization
Java Variables and Types
Operators And Expressions
BASIC ELEMENTS OF A COMPUTER PROGRAM
Chap. 2. Types, Operators, and Expressions
Expressions and Assignment
University of Central Florida COP 3330 Object Oriented Programming
Data Types, Arithmetic Operations
ITEC113 Algorithms and Programming Techniques
Basic Elements of C++.
Object Oriented Programming
University of Central Florida COP 3330 Object Oriented Programming
Data Types, Identifiers, and Expressions
Revision Lecture
Variables and Arithmetic Operators in JavaScript
The Selection Structure
Topics The if Statement The if-else Statement Comparing Strings
Computing with C# and the .NET Framework
Java Programming: From Problem Analysis to Program Design, 4e
Basic Elements of C++ Chapter 2.
Chapter 10 Programming Fundamentals with JavaScript
Topics The if Statement The if-else Statement Comparing Strings
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
Logical Operators & Truth Tables.
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
Introduction to C++ Programming
Variables ICS2O.
Basics of ‘C’.
Chapter 2 Variables.
Computer Science 210 Computer Organization
Chapter 2: Java Fundamentals
Associativity and Prescedence
Expressions.
SE1H421 Procedural Programming LECTURE 4 Operators & Conditionals (1)
Chapter 2: Introduction to C++.
The Data Element.
Primitive Types and Expressions
The Data Element.
Variables in C Topics Naming Variables Declaring Variables
Variables and Constants
Boolean Expressions September 1, 2019 ICS102: The course.
Programming Fundamental-1
Presentation transcript:

Data Types, Identifiers, and Expressions Topics to cover here: Data types Variables and Identifiers Arithmetic and Logical Expressions Programming Fundamental Slides

Programming Fundamental Slides Data Types A data type provides a method of modeling or representing a particular set of values and determines what operations can be performed on those values. Programming Fundamental Slides

Programming Fundamental Slides

Data Types in The Algorithmic Language String values (e.g. “ABC” , “computer”, “960”) NOTE: In C++ language, some of the operations have different symbols. Programming Fundamental Slides

Identifiers, Locations, and Variables Memory: It is a part of the computer that has many locations (of fixed size) used to store values (data) and instructions. Programming Fundamental Slides

Identifiers, Locations, and Variables.. cont. Identifiers (Names): - Use meaningful identifiers (names) to represent data in your program. - Identifiers are used to refer to memory locations: to store data in them or retrieve data from them. The rule of defining an identifier: (1) It may contain letters (A .. Z , a .. z ) , digits (0, 1, 2, …, 9), and underscore ( _ ). (2) It should begin with a letter. Programming Fundamental Slides

Identifiers, Locations, and Variables.. cont. NOTES: Some programming languages are case sensitive. That is the uppercase identifiers are different than lowercase identifiers (as in C++). In programming languages, some words cannot be used as identifiers in your program. Such words are called reserved words (or keywords) that have special use. Programming Fundamental Slides

Reserved words (or keywords) in c++ main if else while do for

Identifiers, Locations, and Variables.. cont. Examples of valid identifiers: area , length, X , Y1, abc, d3, st_number { these all begin with a letter } Examples of invalid identifiers: 2Y { begins with a digit } Ali’s { contains the symbol ‘ } st-age { the symbol - is not underscore } while { it is a keyword } ab cd { it has a space } Programming Fundamental Slides

Identifiers, Location, and Variables.. cont. -The name of the location is the variable name. -The location content is the value of the variable - You can change the content of the variable at any time in the statements of the algorithm. e.g. Name of the location Inside Memory location employee_name “Ali Ahmed” age 35 hourly_rate 3.25 Programming Fundamental Slides

Identifiers, Location, and Variables.. cont. Constants: - You can use a constant identifier in your algorithm to indicate a constant data. You CANNOT change the content of the constant identifier. Use the keyword CONST to indicate a constant identifier. e.g. CONST pi = 3.14 Here, pi is a constant identifier that cannot be changed Programming Fundamental Slides

Expressions EX: T MOD 2 gives 0 if T is any even number, and Arithmetic Expression: - It is composed of operands and arithmetic operations - Arithmetic operations: - Operands may be numbers and/or identifiers that have numeric values Its result is a numeric value EX : 3 + 4 gives 7 EX: T MOD 2 gives 0 if T is any even number, and 1 if T is any odd number

Expressions .. cont. Logical Expression: - It is called also Boolean expression. - It is composed from operands and operators. - Operands are identifiers that have logical values - Its result is a logical value (true or false) (see later). - Operators are logical: EX: where A, B are defined logical Note: In C++, there is no specific data type to represent “true” and “false”. C uses value “0” to represent “false”, and uses non-zero value to stand for “true”.

Expressions .. cont. - It is composed from operands and operators. Relational Expression: - It is composed from operands and operators. - Operands may be numbers and/or identifiers that have numeric values - Its result is a logical value (true or false). - Operators are relational operators: EX:

Programming Fundamental Slides Expressions .. cont. NOTES A relational expression may contain arithmetic sub-expressions, e.g. ( 3 + 7 ) < (12 * 4 ) 2) A logical expression may contain relational and arithmetic sub-expressions, e.g. 1- x AND y AND ( a > b ) 2- (2 + t ) < (6 * w ) AND ( p = q ) Programming Fundamental Slides

Programming Fundamental Slides Operator Precedence Expressions are evaluated according to the precedence rule. Precedence Rule: - Each operator has its own precedence that indicates the order of evaluation. - If the expression has operators of the same precedence, then the evaluation starts from left of expression to the right. Programming Fundamental Slides

Operator Precedence .. cont. Description Operator In C++ Operator In pseudo code Higher parentheses ( *, /, % *, /, MOD Binary plus, binary minus + , - <, <=, >, >= <, , ≤, >, ≥ Equal, not equal == , != = , ≠ && AND || OR Lower Assignment =  Programming Fundamental Slides

Programming Fundamental Slides Examples Find the value of the following expression: (1) 5 + 8 * 2 / 4 16 4 9 (This is the final result) Programming Fundamental Slides

Programming Fundamental Slides Examples .. cont. ( 9 + 3 ) - 6 / 2 + 5 12 3 9 14 (this is the final result) Programming Fundamental Slides

Evaluating Logical Expressions The truth table AND table AND True False True True False False False False Programming Fundamental Slides

Evaluating Logical Expressions.. cont. (2) OR table OR True False True True True False True False (3) NOT table NOT True False False True Programming Fundamental Slides

Examples on Logical Expressions If x = True, y = False, z = False, find the value of the expression x AND y OR z x AND y OR z False False (the final result) Programming Fundamental Slides

Examples on Logical Expressions .. cont. (2) If a = 3, b = 5, x = true, y = false, find the value of the expression: ( a < b ) AND y OR x ( a < b ) AND y OR x True False True (the final result) Programming Fundamental Slides

Programming Fundamental Slides Short circuiting: Short circuiting means that we don't evaluate the second part of an AND or OR unless we really need to. Programming Fundamental Slides