The number of calories burned per hour by cycling, jogging and swimming are 200, 475 and 275 respectively. A person loses 1pound of weight for each 3500.

Slides:



Advertisements
Similar presentations
Lecture Set 4 Data Types and Variables Part B – Variables, Constants, Expressions Conversion Rules Options Strict, Option Explicit Scope of Definition.
Advertisements

Java Programming, 3e Concepts and Techniques Chapter 3 Section 63 – Manipulating Data Using Methods – Day 2.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Val Function A Function performs an action and returns a value The expression to operate upon, known as the argument, (or multiple arguments), must be.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
The scanf Function The scanf function reads input from the standard input device into one or more variables Example: scanf(“%lf”, &miles); Reads a real.
Comparing Numeric Values If Val(Text1.Text) = MaxPrice Then (Is the current numeric value stored in the Text property of Text1 equal to the value stored.
CSC110 Fall Chapter 5: Decision Visual Basic.NET.
JavaScript, Third Edition
A variable (X) is declared as an integer Data Type, meaning it can only accept numeric values The Text Box is named BoxContents The Variable X is assigned.
Compunet Corporation1 Programming with Visual Basic.NET Arithmetic, Logical & Bitwise Operators Week # 3 Tariq Ibn Aziz.
Copyright © 2001 by Wiley. All rights reserved. Chapter 3: Variables, Assignment Statements, and Arithmetic Variables Assignment Statements Arithmetic.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 6 Enhancing the Inventory Application Introducing Variables, Memory Concepts and.
Dani Vainstein1 VBScript Session 9. Dani Vainstein2 What we learn last session? VBScript coding conventions. Code convention usage for constants, variables,
Variables and Constants
Ryan Chu. Arithmetic Expressions Arithmetic expressions consist of operators, operands, parentheses, and function calls. The purpose is to specify an.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
1 Chapter 3 – Variables, Input, and Output 3.1 Numbers 3.2 Strings 3.3 Input and Output.
IMS 3253: Math 1 Dr. Lawrence West, MIS Dept., University of Central Florida Topics Five Fundamental Math Operations Precedence of Math.
Arithmetic operations and operators, converting data types and formatting programs for output. Year 11 Information Technology.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Input, Output, and Processing
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
CHAPTER 4: CONTROL STRUCTURES - SEQUENCING 10/14/2014 PROBLEM SOLVING & ALGORITHM (DCT 1123)
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
1 Boolean Expressions to Make Comparisons Boolean expression –Represents only one of two states –Expression evaluates to either true or false Expressions.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Variables & Function Calls. Overview u Variables  Programmer Defined & Intrinsic  Data Types  Calculation issues u Using Functions  The val() function.
Chapter 2 Variables.
Assignment statement: Assigns a value to a variable Variable must appear on the left side, value on the right side of the assignment operator Right side.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
1 Scripting Languages VBScript - Recognized mainly by Internet Explorer only - Netscape does have a plug-in JavaScript - Recognized by Internet Explorer.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Three Memory Locations and Calculations.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
110 E-1 Variables, Constants and Calculations(2) Chapter 3: Operations on variables, scope of a variable, formatting data Doing Arithmetic.
Variables and Expressions Programming Right from the Start with Visual Basic.NET 1/e 7.
Creation of Variables with Numeric, alphanumeric, date, picture, memo data types Constant - A quantity that does not change during the execution of a program.
CSCI 1100/1202 January 18, Arithmetic Expressions An expression is a combination of operators and operands Arithmetic expressions compute numeric.
CHAPTER FOUR Performing Calculations and Manipulating Data: Expressions.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are used in programs so that values can be represented with.
Copyright © Curt Hill The Assignment Operator and Statement The Most Common Statement you will use.
© 2006 Lawrenceville Press Slide 1 Chapter 4 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration statement. For example: Dim.
Topics Designing a Program Input, Processing, and Output
Arithmetic operations and operators, converting data types and formatting programs for output. Year 11 Information Technology.
Operators and Expressions
An Application Uses Variables to Hold Information So It May Be Manipulated, Used to Manipulate Other Information, or Remembered for Later Use.
Visual Basic Variables
Completing the Problem-Solving Process
2.5 Another Java Application: Adding Integers
ITEC113 Algorithms and Programming Techniques
Assignment statement:
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.
Multiple variables can be created in one declaration
The Selection Structure
Arithmetic Operator Operation Example + addition x + y
Visual Basic Numbers Chapter 3.3 Prepared By: Deborah 1/15/2019.
Core Objects, Variables, Input, and Output
Chapter 3: Selection Structures: Making Decisions
Boolean Expressions to Make Comparisons
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
Visual Basic Numbers Chapter 3.3 Prepared By: Deborah 7/9/2019.
Chapter 2 Modular Programs with Calculations and Strings
Presentation transcript:

The number of calories burned per hour by cycling, jogging and swimming are 200, 475 and 275 respectively. A person loses 1pound of weight for each 3500 calories burned. Write a program that allows the user to input the numbers of hours spent at each activity and then calculate the number of pounds worked off.

Operators and Operands in Expressions An Operand can be thought of as something that has a value An Operator is the symbol of an operation carried out on at least 2 operands There are 3 main types of Operator in VB, which take the following Order of Precedence: - Arithmetic Operators - Relational (Comparison) Operators - Logical Operators

Expressions An Expression is a Visual Basic Action There are 2 types of Expression in VB: - Simple - Compound An expression is formed by combining Operators and Operands in a meaningful way The purpose of an expression is to perform a calculation and produce a result, or to cause some action to occur

Simple Expression: (A+B) Compound Expression: An expression with more than 1 OPERATION is called a Compound Expression [(A+B)*(C-D)] (A, B, C, D) are the Operands (*, +, -) are the Operators Each of these Operator Symbols represents an Operation

Arithmetic Operators The hierarchy of operations, or order of precedence, in arithmetic expressions from the highest to the lowest is: [1] Exponentiation: ^ (2 ^ 3 = 8) [2] Multiplication and Division: * / [3] Addition and Subtraction: + -- Example 3 + 4 * 2 = 11 However, the order of evaluation can be changed by using parentheses: () (3 + 4) * 2 = 14

If one set of parentheses are used inside another set, the parentheses are referred to as nested ((3 + 3) / 3) * 4 = 8 (((4 + 3 * 4) / 2) * 4 + (4 + 10 / 2 - 3)) = ? Nested

What Data Types would be assigned to the Variable X as a result of each of the following Operations (2 + 4) (integer + integer) = integer/Long (2 - 4) (integer - integer) = integer/Long (2 * 4) (integer * integer) = integer/Long (2 / 4) (integer / integer) = Single/Double (Two + Four) (string + string) = string (TwoFour)

Val Function A Function performs an action and returns a value The expression to operate upon, known as the argument, (or multiple arguments), must be enclosed in parentheses Val an abbreviation for value Val(ExpressionToConvert) The expression that is converted, can be the Property of a Control, a Variable, or a Constant

The Val Function returns (produces) a value that can be used as a part of a statement, such as an assignment statement iQuantity = Val(txtQuantity.Text) The Val Function converts an argument to numeric, by beginning at the Left-Most Character If that character is a numeric digit, decimal point, or sign, Val converts the character to numeric and moves to the next character. As soon as a non-numeric character is found, the operation stops

Conversion Function The Conversion Function checks if the value stored in the Property of a Control or a Variable is of a specific Data Type required in the execution of a statement(s), and if not the Conversion Function will return a ‘Run-Time Error’ Message The Text in Text Boxes is treated as a String, however in performing Arithmetic Operations (such as ^ * / + -), numeric values are required in the Text property of the Text Boxes

VB Conversion Functions CInt - Converts a value to an Integer CLng - Converts a value to a Long Integer CSng - Converts a value to a Single Precision number CDbl - Converts a value to a Double Precision nember CCur - Converts a value to Currency CStr - Converts a value to a String CVar - Converts a value to a Variant

CInt Function Dim X As Integer X = CInt(Text1 CInt Function Dim X As Integer X = CInt(Text1.Text) Print X Dim X As Integer, Y As Integer Y = CInt(X) * 2 Print Y CInt(“12”) the brackets are by default - 12 CInt(“Twelve”) - Error CInt(Text1.Text) - the value of the Text in Text1, if it is valid

cHours = 12.2 cPayRate = 5 cTotalPay = ?

In the Sample code the Val Function is replaced by the CCur Function The value stored in the Text Property of the Hours text box is converted from a String to Currency and the value is assigned to the Variable cHours as a Currency Data Type If the value in the Text Property is not consistent with the Currency Data Type, then a ‘Run-Time Error’ will occur and the program will stop executing

However, if the value of Hours.Text = 12.2’ PayRate.Text = 5 Using the Val Function and the CCur Function, after multiplication, returns the value of 61 However, if the value of Hours.Text = 12.2’ How would the Functions handle it?

The Val Function will convert the value stored in the Property of the control, to a numeric value, before assigning it as the value of the variable for use in an Arithmetic Calculation The Conversion Function checks if the value stored in the Property of a Control is of a specific Data Type required in the execution of a statement(s) (numeric for the purpose of calculation), and if not the Conversion Function will return a ‘Run-Time Error’ Message