Computer Engineering 1 st Semester Dr. Rabie A. Ramadan 3.

Slides:



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

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.
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
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: 
CIS 234: Using Data in Java Thanks to Dr. Ralph D. Westfall.
ECE122 L3: Expression Evaluation February 6, 2007 ECE 122 Engineering Problem Solving with Java Lecture 3 Expression Evaluation and Program Interaction.
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
Chapter 2 Data Types, Declarations, and Displays
JavaScript, Third Edition
CSci 142 Data and Expressions. 2  Topics  Strings  Primitive data types  Using variables and constants  Expressions and operator precedence  Data.
String Escape Sequences
Data Types.
Basic Elements of C++ Chapter 2.
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.
CPS120: Introduction to Computer Science Lecture 8.
Java Building Elements Lecture 2 Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University
A Variable is symbolic name that can be given different values. Variables are stored in particular places in the computer ‘s memory. When a variable is.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
2440: 211 Interactive Web Programming Expressions & Operators.
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.
CPS120: Introduction to Computer Science Variables and Constants Lecture 8 - B.
Basic Notions Review what is a variable? value? address? memory location? what is an identifier? variable name? keyword? what is a legal identifier? what.
Computer Engineering 1 nd Semester Dr. Rabie A. Ramadan 2.
CH2 – Using Data. Constant Something which cannot be changed Data Type Format and size of a data item Intrinsic Data Types Pg. 47 – Table 2-1 Basic ones.
Chapter 2: Using Data.
CPS120: Introduction to Computer Science
UniMAP Sem1-07/08EKT120: Computer Programming1 Week2.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Programming Fundamental Slides1 Data Types, Identifiers, and Expressions Topics to cover here: Data types Variables and Identifiers Arithmetic and Logical.
SE-1010 Dr. Mark L. Hornick 1 Variables & Datatypes.
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
PHY-102 SAPVariables and OperatorsSlide 1 Variables and Operators In this section we will learn how about variables in Java and basic operations one can.
Primitive Variables.
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.
Data Types Declarations Expressions Data storage C++ Basics.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
COMP Primitive and Class Types Yi Hong May 14, 2015.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Programming in Java (COP 2250) Lecture 4 Chengyong Yang Fall, 2005.
CPS120: Introduction to Computer Science Variables and Constants.
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.
0 Chap.2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations 2.5Arithmetic Operators 2.6Relational.
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.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
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.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
Chapter Topics The Basics of a C++ Program Data Types
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
ITEC113 Algorithms and Programming Techniques
Basic Elements of C++.
Data Types, Identifiers, and Expressions
Multiple variables can be created in one declaration
Computer Engineering 1nd Semester
Java Programming: From Problem Analysis to Program Design, 4e
Basic Elements of C++ Chapter 2.
Data Types, Identifiers, and Expressions
Basic Notions Review what is a variable? value? address? memory location? what is an identifier? variable name? keyword? what is legal identifier? what.
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
Basics of ‘C’.
Chapter 2: Java Fundamentals
elementary programming
Chapter 2: Java Fundamentals
Chapter 2: Introduction to C++.
Primitive Types and Expressions
Chapter 2 Primitive Data Types and Operations
Variables and Constants
Presentation transcript:

Computer Engineering 1 st Semester Dr. Rabie A. Ramadan 3

2 C++ Names The name of a variable could: Starts with an underscore “_” or a letter, lowercase or uppercase, e.g. _Students, pRice Can include letters, underscore, or digits. Examples are: keyboard, total_grade, _Score_Side1 Cannot include special characters such as !, %, ], or $ Cannot include an empty space Cannot be any of the reserved words Should not be longer than 32 characters (although allowed)

3 Reserved Words

4 Variables and Their Data Types The amount of memory space necessary to store a variable is also referred to as a data type.

5

6 Variables and Their Data Types char 8 bits Signed char: -128  +127 Unsigned char 0  255 Escape sequences are characters

Escape characters 7

Examples 8

9 Variables and Their Data Types Integers – 32 bits or 4 bytes Holds numerical data Signed or Unsigned Short integers 16 bits or 2 bytes Signed or Unsigned Long integers To enforce positive numbers 32 bit long

10 Example

11 Practice -- what is the o/p

12 Practice -- what is the o/p

13 O/P

14 Variables and Their Data Types Floating points Real numbers  ex bytes Declared as : float x; Floating number with double precision 8 bytes Declared as : double x; Larger storage 10 bytes Declared as: long double x;

Example 15

16 Variables and Their Data Types String Group of characters No limit Declared as: string name; getline() function Takes the data from external source and save it into a string variable Ex. getline(cin, name); cin is to notify the compiler that the data is coming from external source Ex. getline( cin, name, ‘?’)  getline( cin, stringName, delimiter ) Saves the data when the delimiter is entered

Example 17

Example (cont.) 18

19 What are constants? const PI = 3.14; #define PI 3.14

20 Operators and Operands “Don't cut the tree that shades you.”

21 Operators Arithmetic : Unary Operators  sign (+ or -) Algebraic operators + Addition - Subtraction * Multiplication / Division % Reminder ++ Increment -- Decrement += Add to the current content -= subtract from the current content *=, /=,..

22 Operators Logical operators o/p true or false ! NOT && AND || OR > greater than < less than >= greater than <= less than == equal

23 Operators

24 Operators Conditional operator (?) :

25 Operators Explicit type casting operator Converts a datum of a given type to another.

26 Operator Precedence Operator classificationOperators parentheses( ) postfix operators[] x++ x-- unary operators++x --x +x -x ! creation or castnew (type)x multiplicative* / % additive+ - relational >= <= equality (boolean)= = != logical AND&& logical OR|| assignment=

27 Example

28 Example

29 Example

30 Control Statement

31 Flow of the Control

32 Control Statements Ways for a programmer to control what pieces of the program are to be executed at certain times. branching statements and loops.

33 Branching Statement

34 Example

35 Nesting Branch

36

37 Switch Statement

38 Switch Statement

39 Reading Materials Chapters 1, 2 and 3, 5 (till 5.3).