Data Types, Arithmetic Operations

Slides:



Advertisements
Similar presentations
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Advertisements

Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
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.
CIS 234: Using Data in Java Thanks to Dr. Ralph D. Westfall.
1 9/20/06CS150 Introduction to Computer Science 1 Review: Exam 1.
Data types and variables
IS437: Fall 2004 Instructor: Dr. Boris Jukic Data Types, Constants, Variables, Scope, Conversion.
Chapter 2 Data Types, Declarations, and Displays
VB .NET Programming Fundamentals
String Escape Sequences
110-D1 Variables, Constants and Calculations(1) Chapter 3: we are familiar with VB IDE (building a form…) to make our applications more powerful, we need.
Objectives You should be able to describe: Data Types
 Value, Variable and Data Type  Type Conversion  Arithmetic Expression Evaluation  Scope of variable.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
Chapter 2 Primitive Data Types and Operations F Introduce Programming with an Example  The MyInput class F Identifiers, Variables, and Constants F Primitive.
Variable, Expressions, Statements and Operators By: Engr. Faisal ur Rehman CE-105 Fall 2007.
Language Elements 1. Data Types 2 Floating Point (real) Single Precision Double Precision Decimal Fixed Point (integer) Byte Short Integer Long Numerical.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 4 Working with Variables, Constants, Data Types, and Expressions.
CSE 1301 Lecture 2 Data Types Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
Chapter 2: Using Data.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Programming Fundamental Slides1 Data Types, Identifiers, and Expressions Topics to cover here: Data types Variables and Identifiers Arithmetic and Logical.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Introduction to Programming
Variables & Function Calls. Overview u Variables  Programmer Defined & Intrinsic  Data Types  Calculation issues u Using Functions  The val() function.
CNS 1120 Exam 1 Review. Programming Language Elements Syntax = the rules to follow Syntax = the rules to follow Semantics = the meaning of symbols Semantics.
Chapter 2 Variables.
COMP Primitive and Class Types Yi Hong May 14, 2015.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Programming with Microsoft Visual Basic th Edition
CSM-Java Programming-I Spring,2005 Fundamental Data Types Lesson - 2.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Introduction ABAP Fields and Variables. Slide 2 Fields (Introduction) In ABAP, fields (or data objects) are named locations in memory Variables store.
Tokens in C  Keywords  These are reserved words of the C language. For example int, float, if, else, for, while etc.  Identifiers  An Identifier is.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
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.
Data Types. Visual Basic provides data type Single for storing single-precision floating-point numbers. Data type Double requires more memory to store.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
Java Programming: Guided Learning with Early Objects Chapter 1 Basic Elements of Java.
Egyptian Language School Computer Department
A variable is a name for a value stored in memory.
Chapter 2 Variables.
BASIC ELEMENTS OF A COMPUTER PROGRAM
Visual Basic Variables
Tokens in C Keywords Identifiers Constants
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
ITEC113 Algorithms and Programming Techniques
Object Oriented Programming
Data Types, Identifiers, and Expressions
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
Chapter 6 Variables What is VBScript?
Data Types, Identifiers, and Expressions
CIS16 Application Development Programming with Visual Basic
Chapter 2 Variables.
Lectures on Numerical Methods
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.
Chapter 2: Introduction to C++.
Primitive Types and Expressions
Unit 3: Variables in Java
Chapter 2 Variables.
Chapter 2 Primitive Data Types and Operations
Variables and Constants
Programming Fundamental-1
Presentation transcript:

Data Types, Arithmetic Operations Lecture 2

What are we going to cover Variables Data types Operators Methods Classes and objects

Variable 18 Address: 0803 Name: MyAge Address: 0000 A variable is a symbolic name for a location in memory where some data are stored. Every variable has its address in memory and value

Declaring variable in VB.NET Dim n As Integer Dim p As Double Dim str As String Dim weLikeFunPro As Boolean … Name: n 0.0 Name: p Name: str

Variable identifiers You can choose any name for variables as long as the name is not already a word in the VB.NET language (such as class, imports); the name has no spaces in it; the name does not include operators such as “+” and “-”; the name starts either with a letter or an underscore (_). Valid names: correct, _correct Invalid names: #wrong, ^wrong, 1wrong Note: control names are variables, rules apply

Data Type Every variable has its type identifying what sort of data should be stored in it: Integer, String, Floating-point number etc.

Data Type It is very essential to show the type of the variable Because internally the computer stores all the values in binary and does not differentiate the type. The compiler needs to know the type in order to be able to convert the binary value into the specified type. It also prevents logical errors e.g. if you try to assign some text into a numeric variable compiler would flag this as error.

Data Type 01000110 Integer: 70 Char: ‘ F ‘ Double: 70.0

Variable types (integer types) VB.NET name Description Range Byte 8-bit unsigned number 0 to 255 Short 16-bit signed number -32768 to 32767 Integer 32-bit signed number -2^31 to 2^31-1 Long 64-bit signed number -2^63 to 2^63-1

Variable types (decimal types) VB.NET name Description Precision Range Single 32-bit floating point number 7 significant digits +/- 1.4x10^(-45) to +/- 3.4x10^38 Double 64-bit floating point number 15-16 significant digits +/- 5.0x10^(-324) to +/- 1.7x10^308 Decimal 128-bit fixed point number 28 significant digits +/- 1.0x10^(-28) to +/- 7.9x10^28

Variable types (other) Char – one letter String – text of any length Date – date and time Boolean – true or false

Conversion between types Generally compiler should not let you to assign one data type to another However in practice it uses implicit conversion for the types it knows how to convert e.g. Integer to Long In VB.Net compiler is even more flexible allowing you to avoid some of explicit conversion required Option Strict On will enable strict rules

Conversion between types CType(value, class) Dim a As Long = 1000 Dim b As Integer b = CType(a, Integer) CDbl CInt

Conversion between types All .NET languages – Convert class: Convert.ToBoolean() Convert.ToDateTime() Convert.ToDecimal() Convert.ToDouble() Convert.ToInt32() - Integer Convert.ToInt64() - Long

Assignment operation Operator ‘=‘ represents the assignment operation which means: to assign the value of the expression on the right hand side of the ‘=‘ sign to the variable on the left hand side n = 5 p = 2.6 Str = “Hello World” weLikeFunPro = True 5 Name: n

Arithmetic operations VB.Net supports all simple arithmetic operations: +, - , *, /, \ - integer division, Mod – remainder division, ^ - exponentiation, & - String concatenations

Arithmetic operations P = (n * 3 + 2) mod 5 P = N / M N = 5 ^ 3

Operator Precedence Highest Exponentiation (^) * / \ Mod + - Lowest

Constants Constants are the variables whose values cannot be changed by the program Declaring the constants: Const PI As Single = 3.14 Const PASSWORD As String = “magic”

Comments Comments are very useful tool that help the developers to put hints on the code blocks for future use. Use single quote to point the comment string ‘ This is a comment line Always use comments in your programs. This will make your life easier.

String functions String class exposes a variety of methods to manipulate strings String.Insert String.ToLower, String.ToUpper String.Substring String.Split String.Join and many more…

Methods A method is a block of code. A method has a header and a body. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click n = n + 1 p = p – 0.1 End Sub

Methods Methods are used to break up the code from one monolithic peace into smaller reusable modules. It is like breaking a big job into a smaller operations to be fulfilled by the different people We will learn about functions and subroutines later

Classes and Objects For now you can think of Classes as of Data Types and Objects as of Variables

Object properties and methods Almost all objects have properties and methods. To access to the object’s properties or methods use dot sign: Label1.Text = “Hello World” Objects can have a number of variables (properties), methods and other objects.

The Windows components You can access the variables of the windows components at the design time using Properties Window The methods and as well as properties of an object are also accessible in the code view:

The End