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

Slides:



Advertisements
Similar presentations
Types and Arithmetic Operators
Advertisements

Types, Variables and Operators Computer Engineering Department Java Course Asst. Prof. Dr. Ahmet Sayar Kocaeli University - Fall 2013.
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.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
Javascript Essentials How do I write it??  Start Homesite  Between the start and end BODY tags type: 
Data Types and Expressions
0 Chap. 2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations Imperative Programming, B. Hirsbrunner,
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, Fourth Edition
JavaScript, Third Edition
Introduction To C++ Programming 1.0 Basic C++ Program Structure 2.0 Program Control 3.0 Array And Structures 4.0 Function 5.0 Pointer 6.0 Secure Programming.
Basic Elements of C++ Chapter 2.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Data representation and Data Types Variables.
 Value, Variable and Data Type  Type Conversion  Arithmetic Expression Evaluation  Scope of variable.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
2440: 211 Interactive Web Programming Expressions & Operators.
Chapter 2: Using Data.
Computer Programming TCP1224 Chapter 4 Variables, Constants, and Arithmetic Operators.
CPS120: Introduction to Computer Science
C++ Programming: Basic Elements of C++.
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
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)
COMPUTER PROGRAMMING. variable What is variable? a portion of memory to store a determined value. Each variable needs an identifier that distinguishes.
Computer Engineering 1 st Semester Dr. Rabie A. Ramadan 3.
SE-1010 Dr. Mark L. Hornick 1 Variables & Datatypes.
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
Primitive Variables.
CONSTANTS Constants are also known as literals in C. Constants are quantities whose values do not change during program execution. There are two types.
COMP Primitive and Class Types Yi Hong May 14, 2015.
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.
0 Chap.2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations 2.5Arithmetic Operators 2.6Relational.
Department of Electronic & Electrical Engineering Expressions operators operands precedence associativity types.
Department of Electronic & Electrical Engineering Lecture 3 IO reading and writing variables scanf printf format strings "%d %c %f" Expressions operators.
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.
A Sample Program #include using namespace std; int main(void) { cout
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.
Rational Expressions relational operators logical operators order of precedence.
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.
Fundamentals 2.
Chapter Topics The Basics of a C++ Program Data Types
LESSON 2 Basic of C++.
BASIC ELEMENTS OF A COMPUTER PROGRAM
Rational Expressions. relational operators. logical operators
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.
ITEC113 Algorithms and Programming Techniques
Basic Elements of C++.
Object Oriented Programming
Data Types, Identifiers, and Expressions
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.
Revision Lecture
Basic Elements of C++ Chapter 2.
Data Types, Identifiers, and Expressions
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
Chapter 2 Edited by JJ Shepherd
C++ Data Types Data Type
Chapter 2: Java Fundamentals
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.
Expressions.
Chapter 2: Java Fundamentals
Chapter 2: Introduction to C++.
C Programming Lecture-3 Keywords, Datatypes, Constants & Variables
Variables and Constants
Programming Fundamental-1
Presentation transcript:

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

Programming Fundamental Slides2 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 Slides3 Data Types in The Algorithmic Language Predefined Data Types: INT : values (e.g. 5, -321, 12) operations (e.g. +, -, *, /,, MOD,, =, ≠, ≤, ≥ ) FLOAT : values (e.g. 3.2, 1.23E+5, 0.34E-2) operations (e.g. +, -, *, /,, =, ≠, ≤, ≥) BOOL : values (true, false) operations (e.g. AND, OR, NOT) CHAR : values (e.g. ‘A’, ‘t’, ‘(‘, ‘5’, ‘;’ ) operations (e.g., ≤, etc.) String values (e.g. “ABC”, “computer”, “960”) NOTE: In C++ language, some of the operations have different symbols.

Programming Fundamental Slides4 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 Slides5 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 Slides6 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 Slides7 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 Slides8 Identifiers, Location, and Variables.. c ont. Variables: -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 Slides9 Identifiers, Location, and Variables.. c ont. 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 Slides10 Declaring Identifiers In the algorithmic language, we will use identifiers without declaring them In C++, you should define any identifier used in in the program before using it in any statement of the program. Ex: int y;

Programming Fundamental Slides11 Expressions Arithmetic Expression: - It is composed of operands and arithmetic operations ( +, -, *, /, MOD). - Its result is a numeric value (e.g gives 7) - Operands may be numbers and/or identifiers that have numeric values e.g. x – y gives 4, if x is 6 and y is 2 x / 2 gives 6, if x 12 T MOD 2 gives 0 if T is any even number, and 1 if T is any odd number

Programming Fundamental Slides12 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: AND, OR, NOT e.g. X AND Y a AND b OR c where X, Y, a, b, c are defined logical

Programming Fundamental Slides13 Expressions.. cont. 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:, =, ≠, ≤, ≥ e.g. (a < b) gives true, if value of a is less than value of b false, if value of a is not less than value of b (x ≠ y) also gives true or false according to the values of x and y

Programming Fundamental Slides14 Expressions.. cont. NOTES 1) A relational expression may contain arithmetic sub-expressions, e.g. ( ) < (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 Slides15 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 Slides16 Operator Precedence.. cont. PrecedenceDescriptionOperator Higherparentheses ( unary plus, unary minus, Not ++, - –, NOT *, /, MOD Binary plus, binary minus +, -, >= Equal, not equal =, != AND OR LowerAssignment 

Programming Fundamental Slides17 Examples Find the value of the following expression: (1) * 2 / (This is the final result)

Programming Fundamental Slides18 Examples.. cont. (2) ( ) - 6 / (this is the final result)

Programming Fundamental Slides19 Evaluating Logical Expressions The truth table (1) AND table AND True False True True False False False False

Programming Fundamental Slides20 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 Slides21 Examples on Logical Expressions (1) 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 Slides22 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)