Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming Fundamentals. Floating Point Numbers Scientific notation 98 = 0.98 x 10 2 204.5 = 0.2045 x 10 3 -0.082167 = -0.82167 x10 -1 Sign bit; Fraction.

Similar presentations


Presentation on theme: "Programming Fundamentals. Floating Point Numbers Scientific notation 98 = 0.98 x 10 2 204.5 = 0.2045 x 10 3 -0.082167 = -0.82167 x10 -1 Sign bit; Fraction."— Presentation transcript:

1 Programming Fundamentals

2 Floating Point Numbers Scientific notation 98 = 0.98 x 10 2 204.5 = 0.2045 x 10 3 -0.082167 = -0.82167 x10 -1 Sign bit; Fraction (Mantissa); Exponent SExponentFraction

3 Floating point arithmetic Addition & Subtraction 0.45x10 2 + 0.32x10 -1 = -0.45x10 2 - 0.32x10 -1 = Multiplication & Division 0.45x10 2 ÷ 0.32x10 -1 = 0.45x10 2 * 0.32x10 -1 =

4 Data Types Type of quantities Integer Long Integer Single Double String Byte Boolean Currency Date

5 Integer & Long Integer Integer –Uses 2 bytes ( 2x8=16 bits ) of memory -32768  +32767 range –No commas, like 20,400 –No decimals or fractions, like 2.45 or 4.00 Long Integer –Uses 4 bytes -2147483648  +2147483647 range

6 Single & Double Single –Use 4 bytes (32 bits) –Can have 7 significant digits -3.4 E 38  3.4 E 38 range Double –Uses 8 bytes (64 bits) –Can have 15 significant digits -1.8 D 308  1.8 D 308 range

7 Byte & Currency Byte –Unsigned numbers 0  255 Currency –8 Bytes -922,337,203,685,477.5808  +922,337,203,685,477.5808 –No truncation & rounding

8 String Strings are non-numeric quantities, written within quotes –Examples ‘Islam is the solution to world problems’ ‘CS101’ ‘-423.45’ ‘Rs. 32,400.55’ ‘Osama bin Zaid’ ‘TB stands for Tooni’s Blare & a notorious disease’

9 Constants & Variables Each data type can be a constant or a variable Constant –The contents of the memory remain fixed –Numeric or String pi  3.14.. Speed Of Light  2.998e8 k  1.38e-23 Name Of My Hero  “Muhammad (pbuh)” e  “-1.6e-19”

10 Constants & Variables Variables –The contents of a memory associated with a variable is allowed to change –A & B determine the contents of Sum and Product Read A Read B Sum = A + B Product = A*B

11 Declarations Variables are declared at the beginning of a program using Dim –Reserve appropriate memory Examples –Dim MidtermScore As Integer –Dim h As single, Frequency As Single –Dim Energy As Double –Dim StudentName As String –Dim CourseTitle As String*40

12 Memory Allocation A_Integer A_Single

13 Variable Name Rules A variable name must begin with an alphabet. It should not be longer than 255 characters. Special words, such as, Dim, If, Else, Case, etc. are not permitted.

14 Variable Name Rules Some special characters are allowed within a variable name. A period (full stop), %, # and & are not allowed. –Avoid special characters in a variable name.

15 Variable Name Rules Visual Basic does not distinguish between upper and lower case letters. –AVARIABLE, AVariable, aVariable, avariable, etc. refer to the same memory location.

16 The Longest Variable Name EvenThoughItIsHardToWriteOrReadAndM anyOfUsMayNeverSeeOrWriteSuchLongV ariableNameYetVisualBasicAllowsTheUse OfTwoHundredFiftyFiveCharactersForThe VariableName0123456789012345678901 2345678901234567890123456789012345 6789012345678901234567890123456789 0123456789 255 characters

17 Suffix Notation VariableData Type Index%Integer Counter&Long Integer TaxRate!Single Ratio#Double Name$String

18 Constants Constants can be named like variables –Or remain un-named Const Name As String=“Muhammad (pbuh)” Const c As Single = 2.998E8 Const e As Double = -1.6D-19 22.5 6/7 –An effort to change the contents of a named constant will result in an error Assignment to constants not permitted

19 Operators + (plus)AdditionShift + = - (minus)Subtraction- * (asterisk)MultiplicationShift + 8 / (slash)Division/ ^ (caret)ExponentiationShift + 6 \ (back slash) Integer division\ ModInteger remainder

20 Operations 2^3 = 8 10/8 = 1.25 10\8 = 1 8.6\2.7 = 3 10 Mod 8 = 2 2.3 Mod 2.1 = 0 2.3/1.2^2 = 2.3/1.44 = 1.5972

21 Hierarchy of Operations 1.(^) Exponentiation 2.(* or /)Multiplication & Division 3.(\)Integer Division 4.(Mod)Integer Remainder 5.(+ or -)Addition & Subtraction Parentheses are used to change the order of operation.

22 Expressions  (2*(a+b)^2 + 3*c^2)^(3/2) (2*(a+b)^2 + 3*c^2)^3/2   -x + y^2 -2^4 = -(2^4) = -16 (-2)^4 = 16

23 String Expressions Amount = “Ten” Denomination = “Thousand” Amount & “ “ & Denomination & “ Rupees”  Ten Thousand Rupees Amount + “ “ & Denomination + “ Rupees”  Ten Thousand Rupees

24 Expressions How u n = u^n is computed when n≠0? Is n an integer? n > 0 Compute a=u |n| by multiplying u, n times Ans=1/a Ans=a Compute ans=n*log(u) Yes No Yes No Logarithm of –ive numbers is not defined Is u > 0? Error Message Yes No u can be +ive or -ive

25 Assignment Salary = 12000 Tax = 4/100*Salary HouseRent = 1200 NetSalary = Salary - Tax - HouseRent

26 Library Functions Abs Y=Abs(-2)  Y = 2 Chr Y=Chr(65)  Y = “A” Exp Y=Exp(2)  Y = e^2 Int Y=Int(-2.9)  Y = -2

27 Library Functions Rnd Y=Rnd  Y gets a random number 0≤Y<1 Sgn Y=Sgn(x)  Str Y=Str(4.2)  Y = “4.2” Val Y=Val(“-3”)+Val(“2”)  Y = -3.1+2=-1.1 »The string within the Val must appear like a number

28 Library Functions Sin, Cos, Tan –Trigonometric functions Arguments must be in RADIANS –Sin(x), Cos(u), Tan(w) Date Y=Date  Current date mo/dy/Year Sqr Y=Sqr(4)  Y = 2 =

29 Library Functions Lcase Y=Lcase(“MyName”)  Y=“myname” Ucase Y=Ucase(“MyName”)  Y = “MYNAME” Len Y=Len(“MyName”)  Y=6

30 Library Functions Left Y=Left(“MyName”,3)  Y=“MyN” Right Y=Right(“MyName”,3)  Y=“ame” Mid Y=Mid(“MyName”,2,3)  Y=“yNa” Log Y=Log(72.4)  Y=log e (72.4)

31 User-Defined Data Type User can define new data types by using standard data types Example Type Member Name As String ID As String DateOfBirth As Date Dues As Single End Type

32 User-Defined Data Type Then we could declare & use variables of type Customer as follows Dim OldMember As Member Dim NewMember As Member OldMember.Name  Name of the Old Member NewMember.DateOfBirth NewMamber.Name NewMember.Dues


Download ppt "Programming Fundamentals. Floating Point Numbers Scientific notation 98 = 0.98 x 10 2 204.5 = 0.2045 x 10 3 -0.082167 = -0.82167 x10 -1 Sign bit; Fraction."

Similar presentations


Ads by Google