Learning the Language - V

Similar documents
Fundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials

Unit 3. Operators. School of Science and Technology INTRODUCTION

T H E I N T E R A C T I V E S H E L L

Chapter 4: Basic C Operators

C: How to Program. Week /Mar/05

9. Elementary Algebraic and Transcendental Scalar Functions

Chapter 2 - Introduction to C Programming

Operators. Java operators are classified into three categories:

1. Variables 2. Arithmetic 3. Input and output 4. Problem solving: first do it by hand 5. Strings 6. Chapter summary

Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1

MITOCW watch?v=kvtlwgctwn4

Scheme Tutorial. Introduction. The Structure of Scheme Programs. Syntax

Arithmetic Operators. Binary Arithmetic Operators. Arithmetic Operators. A Closer Look at the / Operator. A Closer Look at the % Operator

Chapter 17. Fundamental Concepts Expressed in JavaScript

Operators & Expressions

Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators

Any Integer Can Be Written as a Fraction

Computer Programming CS F111

Lecture 3 Tao Wang 1

Summer Assignment Glossary

Introduction to TURING

Department of Computer Science

Introduction to Computers. Laboratory Manual. Experiment #3. Elementary Programming, II

A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

Add Subtract Multiply Divide

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program

PRG PROGRAMMING ESSENTIALS. Lecture 2 Program flow, Conditionals, Loops

Project 3: RPN Calculator

Statements and Operators

Lesson 3: Basic Programming Concepts

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

Professor: Sana Odeh Lecture 3 Python 3.1 Variables, Primitive Data Types & arithmetic operators

Operators. Lecture 3 COP 3014 Spring January 16, 2018

Fundamentals of Programming CS-110. Lecture 3

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan

9/10/10. Arithmetic Operators. Today. Assigning floats to ints. Arithmetic Operators & Expressions. What do you think is the output?

Fundamentals: Expressions and Assignment

Overview (4) CPE 101 mod/reusing slides from a UW course. Assignment Statement: Review. Why Study Expressions? D-1

Arithmetic. 2.2.l Basic Arithmetic Operations. 2.2 Arithmetic 37

ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 1 IDL Operators

Introduction to Computer Programming CSCI-UA 2. Review Midterm Exam 1

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur

Ex: If you use a program to record sales, you will want to remember data:

VARIABLES & ASSIGNMENTS

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */

Introduction to Programming using C++

CSI Lab 02. Tuesday, January 21st

Mathematical Data Operators

DOWNLOAD PDF MICROSOFT EXCEL ALL FORMULAS LIST WITH EXAMPLES

VARIABLES. Aim Understanding how computer programs store values, and how they are accessed and used in computer programs.

Rational numbers as decimals and as integer fractions

L-System Fractal Generator: Language Reference Manual

An algorithm may be expressed in a number of ways:

Two Types of Types. Primitive Types in Java. Using Primitive Variables. Class #07: Java Primitives. Integer types.

Expressions. Operands. Operators

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

COMP Primitive and Class Types. Yi Hong May 14, 2015

I Internal Examination Sept Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs.

CSE 1001 Fundamentals of Software Development 1. Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018

Decisions, Decisions. Testing, testing C H A P T E R 7

Contents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual

Lesson 1: Arithmetic Review

Mobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02

CS Kangmei Yang. Page 1

Basics of Java Programming

Overview of C, Part 2. CSE 130: Introduction to Programming in C Stony Brook University

Java Programming Fundamentals - Day Instructor: Jason Yoon Website:

MIT AITI Python Software Development

9 Using Equation Networks

XQ: An XML Query Language Language Reference Manual

Candidate Forms Automatic Calculations in Fields

Lesson 3: Arithmetic & Casting. Pic 10A Ricardo Salazar

Imelda C. Go, South Carolina Department of Education, Columbia, SC

LECTURE 3 C++ Basics Part 2

cast int( x float( x str( x hex( int string int oct( int string int bin( int string int chr( int int ord( ch

Object Oriented Programming with Java

PLT Fall Shoo. Language Reference Manual

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #16 Loops: Matrix Using Nested for Loop

Outline. Data and Operations. Data Types. Integral Types

3. EXPRESSIONS. It is a sequence of operands and operators that reduce to a single value.

Information Science 1

CIS 194: Homework 4. Due Wednesday, February 18, What is a Number?

Chapter 1 & 2 Introduction to C Language

Intro to Computer Programming (ICP) Rab Nawaz Jadoon

Lesson #3. Variables, Operators, and Expressions. 3. Variables, Operators and Expressions - Copyright Denis Hamelin - Ryerson University

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators

Introduction to MATLAB

Course PJL. Arithmetic Operations

CMSC201 Computer Science I for Majors

Variables, expressions and statements

hp calculators HP 35s Using Algebraic Mode Calculation modes Functions of a single number in algebraic A simple example in algebraic

CIS 110: Introduction to Computer Programming

Chapter 03: Computer Arithmetic. Lesson 09: Arithmetic using floating point numbers

Our Strategy for Learning Fortran 90

ANSI C Programming Simple Programs

Lesson 5: Introduction to the Java Basics: Java Arithmetic THEORY. Arithmetic Operators

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

Chapter Two PROGRAMMING WITH NUMBERS AND STRINGS

Transcription:

Learning the Language - V Fundamentals We now have locations to store things so we need a way to get things into those storage locations To do that, we use assignment statements Deja Moo: The feeling that you've heard this bull before. 2 An assignment statement reads Place what the right side of the expression evaluates to into the location on the left side of the expression The left side and right side are separated by an equals sign (=) Note that the right side is evaluated and then placed into the left side The left side is just a location For example the assignment statement X = 1. Would evaluate the right side A constant evaluates to itself Then since there is nothing else to evaluate it would store the result in the memory location labeled X 4 1

Fundamentals Since we have an evaluation, then a replacement, a statement like X = X + 1. Is completely proper and meaningful The computer looks at the right side first It gets the value stored in X Adds 1 to it Store the result in X If X had 21 originally stored in it and the expression X = X + 1 Was executed, after the execution of the expression, X would contain 22 Since X is a variable, it can change values during the execution of the program 5 6 If we had mistakenly tried 21 = X + 1 That would have generated an error because 21 is a constant and doesn t refer to a memory location Yes, mathematically it seems to be completely correct but the = sign is a replacement operator in this case not a logical condition 7 8 2

VBA doesn t look at the algebraic quality of the statement, just the syntax of the statement Remember that when encountered like this, the equal sign means store the evaluation of the right side in the location pointed to by the right side 9 10 When we evaluate an expression in VBA we need to know what order things are done in For example if we have the expression X = 2 + 4 / What would we expect to be stored in X after execution? Two possibilities X = 2 X =. X = 2 + 4 / Two possibilities X = 2 X =. The first evaluation comes from 2 + 4 = 6 and then 6 / = 2 The second evaluation comes from 4 / = 1. and then 1. + 2 =. 11 12

s Your calculator would probably give you the value of 2 because you would punch it in left to right as you read it VBA has a bit more sophistication For ARITHMETIC evaluations, VBA has a number of operators 1 14 All of the operators except two are just what you would expect them to be The two special operators require some explanation 15 16 4

When we use regular division on two integers and then store the result in an integer, what we get is a rounding off of the quotient into an integer Not all languages are like that but VB has chosen that as their standard For example if we have a function We have two integer arguments and the function returns an argument If we call the function with a=1 and b=2 the function returns 0 because the result of the division rounds off to 0 1 0.5 0 2 = 17 18 If we call the function with a= and b=4, the function evaluates to 1 because 0.75 rounds to 1 0.75 1 4 = The integer division operator will make the same division but rather than rounding, it will remove any decimal part of the result 0.75 0 4 = 19 20 5

If we write a function using the integer division operator we get a different result from the evaluation 0.75 0 4 = The Mod operator is used to divide two numbers and return only the remainder. The modulus, or remainder, operator divides number1 by number2 (rounding floating-point numbers to integers) and returns only the remainder as result. For example, in the following expression, A (result) equals 5. A = 19 Mod 6.7 21 22 Again, illustrating with a function we have All of the operators beside the first take two arguments The uniary minus only take one argument 2 24 6

For example, the uniary minus would be used as X = -1.2 The order in which arithmetic expression are evaluated are 25 26 For operators of equal precedence, they are evaluated in left to right order For example, if we have the expression X = 1. + 2.. * 4. / 5. ^ 1. / 2. X = 1. + 2. -. * 4. / 5. ^ 1. / 2. 1 X = 1. + 2. -. * 4. / 5. / 2. 2 X = 1. + 2. - 12./ 5. / 2. X = 1. + 2. - 2.4 / 2. 4 X = 1. + 2. - 1.2 5 X =. - 1.2 6 X = 1.8 27 28 7

Remember, the order of operations is uniary negation, exponentiation, multiplication and division, integer division, modulo arithmetic, and then addition and subtraction For operators of equal precedence, the order is left to right Some examples for you to try Find the value for X after each of these expressions has executed X = -1./.^5/10 Mod 20. X = -1./.*5./10*20. X = -1./.*5.*10\20 X = 1./-.*-5.*10./-20. 29 0 We have a way to circumvent the normal arithmetic order of operations is we choose to do so Anything that we enclose in parentheses will be evaluated first This order goes from inner to outer X = 1. + ((2. +.) * 4. / 5.) ^ (1. / 2.) For Example 1 X = 1. + 2. -. * 4. / 5. ^ 1. / 2. 1 X = 1. + 2. -. * 4. / 5. / 2. 2 X = 1. + 2. - 12./ 5. / 2. X = 1. + 2. - 2.4 / 2. 4 X = 1. + 2. - 1.2 5 X =. - 1.2 6 X = 1.8 X = 1. + (5. * 4. / 5.) ^ (1. / 2.) 2 X = 1. + (20. / 5.) ^ (1. / 2.) X = 1. + 4. ^ (1. / 2.) 4 X = 1. + 4. ^ 0.5 5 X = 1. + 2. 6 X =. 1 2 8

Parentheses allow us to control the order of evaluation of an arithmetic expression Parentheses are evaluated from the inside out when they are nested For every open parenthesis ( there must be a closed parenthesis ) In VBA this looks like 4 The tall line after the equal sign is just where the cursor was The Range( A1 ).Value = X puts a copy of the value that is currently stored in the variable X into the Value property of the Range object So when we run the program we get 5 6 9

Now if we modify our program to check the two arithmetic expressions use used before we would have The # signs is VBA s way of showing that these are single constants and not integer constants After you type in 1. when you hit the end of the expression and hit return, VBA will replace 1. with 1# 7 8 We are going to put the evaluation of the first expression in cell A1 and the evaluation of the second expression in cell A2 On running the program 9 40 10