CST-115 Introduction to Computer Programming

Slides:



Advertisements
Similar presentations
Previously… We created a simulated temperature reader which alerts if too hot or too cold… Download the solved practice to keep in sync: Thermostat.vi.
Advertisements

Based on LabVIEW 2011 Student Edition
Floyd, Digital Fundamentals, 10 th ed EET 2259 Unit 5 Loops  Read Bishop, Sections 5.1 and 5.2.  Lab #5 and Homework #5 due next week.  Exam #1 next.
CS320n –Visual Programming LabVIEW Foundations. Visual ProgrammingLabVIEW Foundations2 What We Will Do Today Hand back and review the midterm Look at.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
Loops A.About While Loops B.About For Loops C.About Case structures D.Sequence Structures E.Formula Node You Will Learn:
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Expressions and Operators Program Style.
Introduction to LabVIEW Seth Price Department of Chemical Engineering New Mexico Tech Rev. 10/5/14.
Simple Data Type Representation and conversion of numbers
LabVIEW an Introduction
Computer Science 111 Fundamentals of Programming I Number Systems.
1 Introduction to Flowcharting. 2 Writing a program Defining the problem –Write down what the program will do Planning –Write down the steps, draw a flowchart.
1 Introduction to Flowcharting. 2 Writing a program Defining the problem –Write down what the program will do Planning –Write down the steps, draw a flowchart.
Summary of what we learned yesterday Basics of C++ Format of a program Syntax of literals, keywords, symbols, variables Simple data types and arithmetic.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Introduction to LabVIEW 8.5
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
Mathematical Calculations in Java Mrs. C. Furman.
CMSC 104, Version 8/061L10ArithmeticOps.ppt Arithmetic Operators Topics Arithmetic Operators Operator Precedence Evaluating Arithmetic Expressions In-class.
1 09/27/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
Data Types and Conversions, Input from the Keyboard CS303E: Elements of Computers and Programming.
Data Types and Conversions, Input from the Keyboard If you can't write it down in English, you can't code it. -- Peter Halpern If you lie to the computer,
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
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.
Week 3 Labview exercises
ECT 109 Help Bcome Exceptional
EET 2259 Unit 12 Data Acquisition
EET 2259 Unit 13 Strings and File I/O
Lecture 2 D&D Chapter 2 & Intro to Eclipse IDE Date.
EET 2259 Unit 4 SubVIs Read Bishop, Chapter 4.
Course Learning Map Lesson # Lesson Title Lesson 3 Lesson 2 Lesson 1
Introduction to Programming
Lecture No. 4 Number Systems
Chapter 4 C Program Control Part I
Data Types and Conversions, Input from the Keyboard
EET 2259 Unit 5 Loops Read Bishop, Sections 5.1 and 5.2.
Variables, Expressions, and IO
Arithmetic Operators Topics Arithmetic Operators Operator Precedence
Course Learning Map Lesson # Lesson Title Lesson 3 Lesson 2 Lesson 1
Introduction to LabVIEW
Arithmetic Operator Operation Example + addition x + y
Arithmetic Operators in C
Chapter 5 SubVIs.
Arithmetic Operators Topics Arithmetic Operators Operator Precedence
Dr. Clincy Professor of CS
Fundamentals of Programming I Number Systems
EET 2259 Unit 5 Loops Read Bishop, Sections 5.1 and 5.2.
Arithmetic Operators in C
Arithmetic Expressions & Data Conversions
THE COMPUTE STATEMENT Purpose: performs mathematical calculations
Doing Arithmetic Today’s lecture is in chapter 2 Assignment statement:
Building Java Programs
Chapter 3: Selection Structures: Making Decisions
Building Java Programs
Building Java Programs
Summary of what we learned yesterday
Chapter 3: Selection Structures: Making Decisions
In this class, we will cover:
EET 2259 Unit 9 Arrays Read Bishop, Sections 6.1 to 6.3.
Unit 3: Variables in Java
Introduction to Java, and DrJava
Introduction to LabVIEW
EET 2259 Unit 13 Strings and File I/O
Using C++ Arithmetic Operators and Control Structures
EET 2259 Unit 5 Loops Read Bishop, Sections 5.1 and 5.2.
EET 2259 Unit 2 Virtual Instruments
EET 2259 Unit 4 SubVIs Read Bishop, Chapter 4.
Arithmetic Expressions & Data Conversions
Python Creating a calculator.
Building Java Programs
Presentation transcript:

CST-115 Introduction to Computer Programming Lecture 5 - Arithmetic Operators Prof. M. Higazi

What are Arithmetic Operators? take numerical values (either literals or variables) as their operands and return a single numerical value used to perform many of the familiar arithmetic operations that involve the calculation of numeric values a mathematical function that takes two operands and performs a calculation on them You can use an arithmetic operator with one or two arguments to negate, add, subtract, multiply, and divide numeric values.

Arithmetic Operators – Functions Palette Arithmetic Operators are found in the Functions Palette: Functions Palette Numeric

Arithmetic Operators – Code Design Front Panel Block Diagram Control Terminals Indicator Terminals Wires Nodes All wires must be connected to the appropriate nodes and all nodes must be wired; failure to do so will give you inaccurate results or prompt you with an error message

Arithmetic Operators – Code Design With LabVIEW, there are more than one way to write a specific piece of code. Consider the two examples shown below using simple add/subtract/product/division operators verses the Compound Arithmetic operator to build equations:

Example 1 Considering the following values for the Controls: Number1 = 125 Number2 = 75 What would the indicator “Result” output?

Example 2 Considering the following values: Numeric = 3 Numeric2 = 5 What would the indicator “Result” output? Wires

Example 3 Considering the following values: Integer1 = 9 Integer2 = 4 What would the indicators “Sum”, “Difference”, and “Product” output? Although we didn’t cover this function yet, can you figure out what the “Remainder” and “Quotient” indicators would output?

Numeric Conversion Numerics default to double-precision (8 bytes) or long integer (4 bytes) LabVIEW automatically converts to different representations As an example, a “For Loop” (which will be covered later) count terminal always converts to a long integer Gray coercion dot on terminal indicates conversion The default representation of a numeric control or indicator is a double-precision floating-point number. LabVIEW can represent a number as: Byte (8-bit) signed or unsigned integer. Word (16-bit) signed or unsigned integer. Long (32-bit) signed or unsigned integer. Single-precision (32-bit) floating-point number. Double-precision (64-bit) floating-point number. Extended-precision (96-bit*) floating-point number. * Depends upon the operating system When two terminals of different data types are wired together, LabVIEW will convert one numeric to the same representation as the other. This is signified by a gray “coercion dot.” Class participation: Ask why the while loop MUST convert an input to an integer. <hint: can you have 1.5 loops?>

Arithmetic Operators - Numeric Conversion LabVIEW chooses the representation that uses more bits. If the number of bits is the same, LabVIEW chooses unsigned over signed. To choose the representation, right-click on the terminal and select Representation. When LabVIEW converts floating-point numerics to integers, it rounds to the nearest integer. LabVIEW rounds x.5 to the nearest even integer. For example, LabVIEW rounds 2.5 to 2 and 3.5 to 4. If you wire two different numeric data types to a numeric function that expects the inputs to be the same data type, LabVIEW converts one of the terminals to the same representation as the other terminal. PREPARE for this slide. Carefully read and think through how to explain the last bullet point. A good idea is to use LabVIEW to demonstrate this point. Place a For Loop on the block diagram (note that they have not been introduced to for loops at this time, so use your best judgment about doing this first), wire a double precision numeric to the number of iterations input. Wire the index output through an increment and then out of the For loop, disabling indexing. Run the VI to show that 3.4 rounds to 3. 3.49 rounds to 3. 3.5 rounds to 4. 4.49 rounds to 4. 4.5 rounds to 4!

Example – Calculations Slope Arithmetic Operators can be used to compute to perform various calculations and computations Shown below is a code for the slope formula: m = (Y2 – Y1) / (X2 – X1)

Hands-on Exercise For your experience, take a few minutes and design the code shown below. This will help you with the familiarization of coding with Arithmetic Operators. Try a few numbers for A,B,C and see how your answers look. Do not spend more than 10 minutes on this exercise.

Pretty soon…things will get more complex ;) Instructor: Build this example subVI slope.vi on your computer and demonstrate creating an icon/connector and calling the VI from another VI along with the next four slides.

Pre-Lab Assignment Note: You will be assigned your first Lab Assignment next week. You must complete this pre-lab assignment and demonstrate it prior to starting the lab. The lab assignment will not be given to those who don’t complete the pre-lab, thus resulting to a grade of 0. Pre-Lab Assignment Develop a program that requests the user to enter in a temperature in degrees Celsius (°C). It should then take this value and convert it to degrees Fahrenheit (°F). Your control should be called “Temp (C)” and your indicator should be called “Temp (F)”. Make sure you test your program and confirm that it is accurate. Test using 25 °C, your output should be 77 °F. This pre-lab will be due by the beginning of the next class.