80 likes | 160 Views
Chapter one Representing data. variable. constant. Temporary memory location that can change its value during program execution. Can’t change its value during program execution. When you input data into a computer it is stored in the memory.
E N D
Chapter one Representing data variable constant Temporary memory location that can change its value during program execution Can’t change its value during program execution • When you input data into a computer it is stored in the memory. • Computer memory is divided into millions of little boxes. • Each box has a number starting with zero. • Each memory location can hold a byte; each byte can store single character or integer from 1 to 255. • High level languages allow you to set up locations in memory and give each group of locations a name. Data types String(varies) numeric Char(2) Boolean(2) Byte(1) Data(8) Whole number Fractional number Integer(4) Short(2) Long(8) Single(4) Double(8) Decimal(16)
Data types • Naming rules: • How to name a variable or a constant? • Names may consist of letters, digits and under scores. • Names must begin with letters. • Names can't contain any spaces or periods. • Names must not be reserved words. • Notes: it is better to (conventions): • Names must be meaningful. • Capitalize each successive word of the name. • Some programmers like to proceed the variable name by three letters indicating its data type.
constant • IntrinsicNamed constants • Constants are built into are programmer defined • VB .Net framework Constant are declared using the key • Ex: Visual basic provides word const • an easy way to specify 1- Constants must have: • a large numbers of colors 1.name • Color .black 2.data type • Color.red 3.value • 2- Constant declaration: • const constantname as datatype =value • all whole numbers assumed to be integers • all fractional numbers assumed to be double • So, we append a letter to verify the data type specified: • 3- The Advantage of using Named Constants: • The code will be easier to read • If you want to change the value of the constant, you need to change the value in the constant • declaration once; you don’t have to change every reference to it in your code.
variables Declaring a Variable Using Dim Statement Dim VariableName As DataType [= value] [= value] is an optional part If we didn't put the optional part of the value so; a- If the variable was a numeric type, the default value is zero. b- If the variable was a string type, the default value is a zero-length (Empty) string. Declaring Multiple Variables Using One Dim Statement You can declare multiple variables using a single Dim statement. For example, the following three Dim statements can replace the five Dim statements mentioned in the book, Page 13 Dim ChildWeight, Population as Integer Dim UnitPrice as Decimal = 123, MyAddress as String = “102, SalahSalem, Cairo” Dim StudentName as String
The assignment Statements • The correct grammatical form (syntax) is • VariableName = Expression • You have to declare the variable using variable declaration statement • The equal sign is called the assignment operator. • How the assignment statement is executed in the computer? • Replace variables with values. • Perform the arithmetic operation. • Store the value of the expression in the variable whose name is on • the left-hand side of the assignment sign. • The Assignment Statements for Strings • You can use the assignment statement to store the result of string manipulations into a string variable just • as you store the result of arithmetic calculations in a numeric variable. • One of the frequently used operators in string manipulations is the & (ampersand). • It is called the "concatenation operator” because it joins two string values together to form a single string value.
Arithmetic operation • Precedence of operations • The order in which the operations are performed determines theResult. • 1-Operations within parentheses. • 2-Exponentiations. • 3-Multiplication and division operations. • 4-Integer division operations. • 5-Modulus operations. • 6-Addition and subtraction operations.
Seeing the examples of the book on the pages: p. 3 p. 15, 16, 17 p. 24 p. 38 Good luck