Arithmetic operations and operators, converting data types and formatting programs for output. Year 11 Information Technology.

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

Types and Arithmetic Operators
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.
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.
Chapter 2 Data Types, Declarations, and Displays
Chapter 3: Introducing the Microsoft.NET Framework and Visual Basic.NET Visual Basic.NET Programming: From Problem Analysis to Program Design.
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.
Computer Science 1000 Spreadsheets II Permission to redistribute these slides is strictly prohibited without permission.
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.
Variables and Constants
Variable Declaration  It is possible to declare multiple variables of the same data type on the same line.  Ex. double hours, rate, total;  Variables.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
06/10/ Working with Data. 206/10/2015 Learning Objectives Explain the circumstances when the following might be useful: Disabling buttons and.
IMS 3253: Math 1 Dr. Lawrence West, MIS Dept., University of Central Florida Topics Five Fundamental Math Operations Precedence of Math.
Agenda  Commenting  Inputting Data from Keyboard (scanf)  Arithmetic Operators  ( ) * / + - %  Order of Operations  Mixing Different Numeric Data.
Variables, Constants, and Calculations
Microsoft Visual Basic 2005 BASICS Lesson 4 Mathematical Operators.
Chapter 5 Using Data and COBOL Operators. Initializing Variables When you define a variable in WORKING- STORAGE, you also can assign it an initial value.
Review for Mid-term! October 26, Review Homework Worksheet True or False Operators are symbols that perform specific operations in Visual Basic.
Visual Basic.NET BASICS Lesson 4 Mathematical Operators.
CHAPTER 2 PART #4 OPERATOR 2 nd semester King Saud University College of Applied studies and Community Service Csc 1101 By: Asma Alosaimi Edited.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
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.
Input, Output, and Processing
Chapter 2: Using Data.
Representing Data: Constants and Variables CHAPTER THREE Matakuliah: T0063 – Pemrograman Visual Tahun: 2009.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
CHAPTER 4: CONTROL STRUCTURES - SEQUENCING 10/14/2014 PROBLEM SOLVING & ALGORITHM (DCT 1123)
Introduction to Programming with RAPTOR
Mathematical Calculations in Java Mrs. G. Chapman.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
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.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Variables & Function Calls. Overview u Variables  Programmer Defined & Intrinsic  Data Types  Calculation issues u Using Functions  The val() function.
Programming with Visual C++: Concepts and Projects Chapter 3A: Integral Data (Concepts)
Java™ How to Program, Early Objects Version, 8/e © by Pearson Education, Inc. All Rights Reserved.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Three Memory Locations and Calculations.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Mathematical Calculations in Java Mrs. C. Furman.
Exceptions, handling exceptions & message boxes Year 11 Information Technology.
1 Chapter 3 – Examples The examples from chapter 3, combining the data types, variables, expressions, assignments, functions and methods with Windows controls.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Programming with Microsoft Visual Basic th Edition
Lesson 4 Mathematical Operators! October 6, 2009.
110 E-1 Variables, Constants and Calculations(2) Chapter 3: Operations on variables, scope of a variable, formatting data Doing Arithmetic.
Microsoft Visual Basic 2012 CHAPTER FOUR Variables and Arithmetic Operations.
More Visual Basic!. Creating a Standalone Program A standalone program will allow you to make a program file that can be run like other Windows programs,
Chapter 3: Introducing the Microsoft.NET Framework and Visual Basic.NET Visual Basic.NET Programming: From Problem Analysis to Program Design.
Making Interactive Programs with Visual Basic .NET
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
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.
© 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.
A variable is a name for a value stored in memory.
Topics Designing a Program Input, Processing, and Output
Arithmetic operations and operators, converting data types and formatting programs for output. Year 11 Information Technology.
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
2.5 Another Java Application: Adding Integers
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.
Variables and Arithmetic Operations
Number and String Operations
CSI 101 Elements of Computing Spring 2009
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
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
Chapter 2 Modular Programs with Calculations and Strings
Presentation transcript:

Arithmetic operations and operators, converting data types and formatting programs for output. Year 11 Information Technology

Main points of chapter 3... Variables – can change based on user input Constant – values that remain the same set in the program Calculation – mathematical calculation that occurs as part of the program Parse – method of converting data to another data type

Arithmetic operations OperatorOperation +Addition -Subtraction *Multiplication /Division \Integer division ModModulus – remainder of division ^Exponentiation

Integer division (\) – divides one integer by another, giving an integer result and dropping the remainder. E.g. TotalMinutesInt = 150, then HoursInt = TotalMinutesInt \ 60 returns 2 hours for HoursInt. Mod – returns the remainder of a division operation. For the above example, MinutesInt = TotalMinutesInt Mod 60 would return 30. Exponentiation (^) – raises a number to the power specified.

Order of operations The order of operations in arithmetic expressions in programming is as follows: 1.Any operation inside brackets 2.Exponentiation 3.Multiplication and division 4.Integer division 5.Modulus 6.Addition and subtraction Nested parentheses can be used i.e. ((Score1Int + Score2Int + Score3Int) + 6) / 3 You can also use nested parentheses for clarity (helps show what the order of operations will be).

Nested parentheses can be used i.e. ((Score1Int + Score2Int + Score3Int) + 6) / 3 You can also use nested parentheses for clarity (helps show what the order of operations will be).

Activity Indicate what the order of operations will be for the following equations: 1.FirstInt + SecondInt ^ / SecondInt / FirstInt 3.FirstInt * (FirstInt + 1) 4.FirstInt * FirstInt ((SecondInt / FirstInt) + ThirdInt) * 4

Using calculations in code These are performed in the assignment statements. Whatever appears on the right side of the assignment operator (=) is assigned to the item on the left. E.g. AmountDueLbl = PriceDec * QuantityDec.ToString() means that the product of the price and quantity will be returned to the Amount Due label.

Assignment operators Multiple operators that perform a calculation and assign the result as one operation. The combined operators are: +=, -=, *=, /=, \= and &=. – E.g. Long version: ‘Subtract 1 from variable. CountdownInt = CountdownInt - 1 Shortcut version: CountdownInt -=1

Converting between numeric data types Implicit conversions – If converting from one data type to another, where there is no danger of losing precision, the conversion can be performed by an implicit conversion. FromTo ByteShort, Integer, Long, Single, Double, or Decimal ShortInteger, Long, Single, Double, or Decimal IntegerLong, Single, Double, or Decimal LongSingle, Double, or Decimal DecimalSingle, Double SingleDouble

Explicit conversions – Used to convert data types that do not have implicit conversions. We use convert classes such as ToDecimal, ToSingle etc. – E.g. NumberDec = Convert.ToDecimal (NumberSingle)

Rounding numbers You can use the Decimal.Round method to round decimals. – C2 (currency to decimal places) – P0 (percentage to 0 decimal places)

Formatting data for display When you want to display the numeric data in the Text property of a label or text box, you must first convert the value to a string. Using the ToString method and formatting codes, you can choose to display a $, % and so on. Format specified codes format the display of the output. See next slide for the format specifier codes. Once a value has been formatted, the formatted value can no longer be used in future calculations (i.e. Once a value has been converted to currency in a text box, the text box value cannot be reused.

Format specifier codeNameDescription C or cCurrencyFormats with a dollar sign, commas and 2 decimal places. Negative values are enclosed in parentheses F or fFixed-pointFormats as a string of numeric digits, no commas, 2 decimal places and a minus sign for negative values. N or nNumberFormats with commas, 2 decimal places and a minus sign for negative values. D or dDigitsUse only for integer data types. Formats with a minus sign for negative values. P or pPercentageMultiplies the value by 100, adds a space and percentage sign.

Choosing the controls for program output You can use either text boxes or labels to display output data, but either should be clearly differentiated from (editable) input areas. In the Windows environment, input areas usually have a white background whilst output should have gray. If using a text box rather than a label to display output data, set the ReadOnly property to True (which will immediately change the background colour) and set TabStop property to False.

Programming prac. We will work through the programming example on page 133 of ‘Programming in Visual Basic 2008’.