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.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
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.
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.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
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.
Microsoft Visual Basic 2005 BASICS Lesson 4 Mathematical Operators.
Review for Mid-term! October 26, Review Homework Worksheet True or False Operators are symbols that perform specific operations in Visual Basic.
Arithmetic operations and operators, converting data types and formatting programs for output. Year 11 Information Technology.
Visual Basic.NET BASICS Lesson 4 Mathematical Operators.
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: CONTROL STRUCTURES - SEQUENCING 10/14/2014 PROBLEM SOLVING & ALGORITHM (DCT 1123)
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
Mathematical Calculations in Java Mrs. G. Chapman.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
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.
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)
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Three Memory Locations and Calculations.
Mathematical Calculations in Java Mrs. C. Furman.
Exceptions, handling exceptions & message boxes Year 11 Information Technology.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Programming with Microsoft Visual Basic th Edition
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
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.
28 Formatted Output.
Math operations 9/19/16.
A variable is a name for a value stored in memory.
Chapter 2 Variables.
Topics Designing a Program Input, Processing, and Output
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
Data Types, Arithmetic Operations
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.
Assignment and Arithmetic expressions
Variables, Expressions, and IO
Unit 42 : Spreadsheet Modelling
Operators and Expressions
Variables and Arithmetic Operations
Chapter 6 Variables What is VBScript?
Place Value, Names for Numbers, and Reading Tables
Visual Basic Programming Chapter Four Notes Working with Variables, Constants, Data Types, and Expressions GROUPBOX CONTROL The _____________________________________.
CIS16 Application Development Programming with Visual Basic
Arithmetic Expressions & Data Conversions
Chapter 2 Variables.
CSI 101 Elements of Computing Spring 2009
Reading Input from the Keyboard
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
Data Types and Expressions
Topics Designing a Program Input, Processing, and Output
Data Types and Expressions
Topics Designing a Program Input, Processing, and Output
EECE.2160 ECE Application Programming
Unit 3: Variables in Java
Chapter 2 Variables.
EECE.2160 ECE Application Programming
Data Types and Expressions
Chapter 2 Modular Programs with Calculations and Strings
Arithmetic Expressions & Data Conversions
Data Types and Expressions
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 Operator Operation + Addition - Subtraction * Multiplication / Division \ Integer division Mod Modulus – 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: Any operation inside brackets Exponentiation Multiplication and division Integer division Modulus 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 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: FirstInt + SecondInt ^ 2 8 / SecondInt / FirstInt FirstInt * (FirstInt + 1) FirstInt * FirstInt + 1 ((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. From To Byte Short, Integer, Long, Single, Double, or Decimal Short Integer, Long, Single, Double, or Decimal Integer Long, Single, Double, or Decimal Long Single, Double, or Decimal Decimal Single, Double Single Double

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 code Name Description C or c Currency Formats with a dollar sign, commas and 2 decimal places. Negative values are enclosed in parentheses F or f Fixed-point Formats as a string of numeric digits, no commas, 2 decimal places and a minus sign for negative values. N or n Number Formats with commas, 2 decimal places and a minus sign for negative values. D or d Digits Use only for integer data types. Formats with a minus sign for negative values. P or p Percentage Multiplies 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’.