Intro to Programming Problem 1: Computers have to be told exactly what do to. Problem 2: Computers only understand “Machine language”. Problem 3: Machine.

Slides:



Advertisements
Similar presentations
ISBN Chapter 7 Expressions and Assignment Statements.
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.
COEN Expressions and Assignment
Copyright © by Curt Hill Expressions and Assignment Statements Part 2.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
ISBN Chapter 7 Expressions and Assignment Statements.
25 October Conditionals and Loops. Presentations Brendan: Cyberwarfare Casey: Online shopping (No current event today)
CS 3850 Lecture 5 Operators. 5.1 Binary Arithmetic Operators Binary arithmetic operators operate on two operands. Register and net (wire) operands are.
Operators. Perl has MANY operators. –Covered in Chapter 3 of Prog.Perl Most operators have numeric and string version –remember Perl will convert variable.
Chapter 7 Expressions and Assignment Statements. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Arithmetic Expressions Arithmetic evaluation.
ISBN Chapter 7 Expressions and Assignment Statements.
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
ISBN Chapter 7 Expressions and Assignment Statements.
JavaScript, Fourth Edition
JavaScript, Third Edition
Fall 2006AE6382 Design Computing1 Relational and Logical Operators Use relational operators to test two values Work with values of true and false Compare.
ISBN Lecture 07 Expressions and Assignment Statements.
1 MATERI PENDUKUNG OPERATOR Matakuliah: M0074/PROGRAMMING II Tahun: 2005 Versi: 1/0.
String Escape Sequences
Copyright © 1998 by Addison -Wesley Longman, Inc. 1 Chapter 6 Arithmetic Expressions - Their evaluation was one of the motivations for the development.
1-1 University of Hail College of Computer Science and Engineering Department of computer Science and Software Engineering Course: ICS313: Fundamentals.
7-1 Chapter 7: Expressions and Assignment Statements Arithmetic Expressions –the fundamental means of specifying computations in a programming language.
Chapter 7 Expressions and Assignment Statements. Chapter 7 Topics 1-2 Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational.
Chapter 7 Expressions and Assignment Statements. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Arithmetic Expressions Arithmetic evaluation.
COMP4730/2002/lec7/H.Melikian Arithmetic Expressions Overloaded Operators Type Conversations Relational and Boolean Expressions Short Circuit Evaluation.
C H A P T E R S E V E N Expressions and Assignment Statements.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
2440: 211 Interactive Web Programming Expressions & Operators.
Chapter 3: Data Types and Operators JavaScript - Introductory.
Operators Using Java operators An operator takes one or more arguments and produces a new value. All operators produce a value from their.
Representing numbers and Basic MATLAB 1. Representing numbers  numbers used by computers do not behave the same as numbers used in mathematics  e.g.,
Arithmetic Expressions
C Operators. CONTENTS C OPERATORS TYPES OF OPERATOR UNARY BINARY TERNARY ARITHMATIC RELATIONAL LOGICAL.
Expressions and Assignment Statements
Chapter 7 © 1998 by Addison -Wesley Longman, Inc Arithmetic Expressions - Their evaluation was one of the motivations for the development of the.
ISBN Chapter 7 Expressions and Assignment Statements.
Chapter 4 Controlling Execution CSE Objectives Evaluate logical expressions –Boolean –Relational Change the flow of execution –Diagrams (e.g.,
Data Types Declarations Expressions Data storage C++ Basics.
Operators in JAVA. Operator An operator is a symbol that operates on one or more arguments to produce a result. Java provides a rich set of operators.
Chapter Seven: Expressions and Assignment Statements Lesson 07.
Fundamental Programming Fundamental Programming More Expressions and Data Types.
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.
Operators A binary operator combines two values to get one result: x OP y where OP is any binary operators such as +, -, *, /, ==, !=, >, &&, or even =.
ISBN Chapter 7 Expressions and Assignment Statements.
Copyright © Curt Hill The Assignment Operator and Statement The Most Common Statement you will use.
7-1/27 Chapter 7 Expressions and Assignment Statements Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean.
Expressions and Assignment Statements
Expressions and Assignment Statements
7.2 Arithmetic Expressions
Chapter 7: Expressions and Assignment Statements
Expressions and Assignment Statements
2.0 FUNDAMENTALS OF JAVA PROGRAMMING LANGUAGE
Computing Fundamentals
CS2403 Programming Languages Expressions and Assignment Statements
Relational Operations
Chapter 7: Expressions and Assignment Statements
Expressions and Assignment Statements
Expressions and Assignment Statements
Winter 2018 CISC101 11/22/2018 CISC101 Reminders
Expressions and Assignment Statements
College of Computer Science and Engineering
Expressions and Assignment Statements
Expression and Asignment Statements
Introduction to Programming – 4 Operators
Chapter 7 Expressions and Assignment Statements.
Chapter 7: Expressions and Assignment Statements Sangho Ha
PRESENTED BY ADNAN M. UZAIR NOMAN
Expressions and Assignment Statements
Presentation transcript:

Intro to Programming Problem 1: Computers have to be told exactly what do to. Problem 2: Computers only understand “Machine language”. Problem 3: Machine language is pretty much impossible to use. 8d4c240483e4f0ff 71fc5589e55183ec 10c745f f8078b45f883 c410595d8d61fcc3 A computer can understand this: People used to program this way!!

Intro to Programming Programming languages are the solution. ● Syntax that we can understand ● A program for translating this to machine language ● “Compiler” if the program is translated once ● “Interpreter” if the program is translated every time it is run 8d4c240483e4f0ff 71fc5589e55183ec 10c745f f8078b45f883 c410595d8d61fcc3 i=48 i=i+7 return i A programming language must have:

Intro to Programming The Tao gave birth to machine language. Machine language gave birth to the assembler. The assembler gave birth to the compiler. Now there are ten thousand languages. -- The Tao of Programming Some common languages: ● Fortran ● C/C++ ● Java ● Perl But we will focus on MATLAB, with examples from others.

Vocabulary In order to talk about programs, we need to know some vocabualry. These are some common words that have specific meanings in the programming world. ● Types ● Constants ● Operators ● Expressions ● Variables A specific language can be almost completely defined just by knowing how it treats these 5 concepts.

Types Programs deal with quantities, but not all quantities are the same. Inherently different quantities are assigned different Types. The difference between a 1 and an 'a' is their type. Simple/Primitive Types ● Integer: 1 ● Float: 1.2 ● Character: 'a' ● Boolean: true or false ● String: “abc” (sometimes) Compound Types ● Array: [1,2,3] ● String: “abc” (sometimes) ● Tuple: (1,'a')

Constants Unchangeable values are called Constants. Boring but useful. 7 and 'h' are anonymous constants, usually called literals. You can guess what named constants are... In MATLAB, pi is a named constant. Named constants are usually just called constants.

Operators We learn about operators in elementary school: +, -, ×, ÷. Operators transform one or more values into some other value. If it operates on one value, the operator is unary. Two values, then binary. There are different flavors or operators: ● Arithmetic ● Relational ● Logical

Arithmetic Operators Arithmetic operators do some mathematical computation. Types are typically preserved throughout. (Integer) + (Integer) = (Integer) ● - (unary): Negation ● + : Addition ● - (binary): Subtraction ● * : Multiplication ● / : Division ● % : Modulus ● ^ : Exponentiation

Arithmetic Ops. in MATLAB Since everything in MATLAB is a matrix, it has a few extra operators. Operators preceded by a '.' do element by element operations. >> [1,2,3,4]*[2;2;2;2] ans = 20 >> [1,2,3,4].*[2,2,2,2] ans = Matrix multiplication: Elelement-by-element multiplication: 1*2 + 2*2 + 3*2 + 4*2 [1*2, 2*2, 3*2, 4*2]

Relational Operators Relational operators compare types and give a true or false answer. 3 > 9 = false ● > : Greater than ● >= : Greather than or equal ● < : Less than ● <= :Less than or equal ● == : Equal (most languages use 2 equal signs) ● !=,<>,~= : Not equal ● Most languages use the first form, some the second, MATLAB uses the third.

Logical Operators Logical operators combine boolean values and return another boolean. Most languages follow the C paradigm, so we will look at that, as well as how MATLAB is different. ● C has both strictly logical and “bitwise” operators ● logical ● && : and (true && false => false) ● || : or (true || false => true) ● ! : not (!true => false) ● bitwise: operate on binary representations ● & : and (1110 & > 1010) ● | : or (1110 | > 1111) ● ^ : xor (1110 ^ > 0101) ● ~ : not (~1110 -> 0001)

Logical Operators Matlab has “element-wise” logical operators with the same syntax as C's bitwise operators. e.g. [1,1,1,0] & [1,0,1,1] -> [1,0,1,0] Also, MATLAB uses ~ for negation, never !. >> x = [3,1,4,1,5,9] x = >> l1 = (x>3) l1 = >> l2 = (x<9) l2 = >> l1 & l2 ans = Example in MATLAB:

“Short Circuit” Operators && and || are usually “short circuit” operators. This means that an answer is returned as soon as possible, without evaluating everything. x ~= 0 && (5/x > 2) This can be used to your advantage, the following will not produce an error when x=0: e.g. true || ? -> true The value of ? doesn't matter, the answer is always true.

Expressions Values and operators combine to make expressions. The meat of a program is the expressions it contains. >> pi*10^2 ans = But, this is only for one size circle. To be really useful, we need... Example: The area of a circle with radius 10

Variables Variables have names, types, and values. >> radius = 10; >> pi*radius^2 ans = In this case the last expression is the area of any circle. In many deep ways, programming is about abstraction. We will see it is also about modularity by introducing Functions. Variables are assigned using the assignment operator, =. A variable of a given type can be assigned any value that has that same type.