DATA HANDLING - PowerPoint PPT Presentation

1 / 30
About This Presentation
Title:

DATA HANDLING

Description:

DATA HANDLING. WEEK 3 ... A whole number and is stored in the computer's ... c = trim(a)//' '//trim(b) c will have the value of 'James Bond' Named constants ... – PowerPoint PPT presentation

Number of Views:108
Avg rating:3.0/5.0
Slides: 31
Provided by: nuzhet
Category:
Tags: data | handling | and | handles | trim

less

Transcript and Presenter's Notes

Title: DATA HANDLING


1
WEEK 3
  • DATA HANDLING

2
  • There are two fundamental types of numbers in
    both mathematics and programming, which may have
    either a fractional part or not.
  • There are, in F, known as integers and real
    numbers.
  • There is vital importance between them

3
Fundamental types of numbers
  • A whole number and is stored in the computers
    memory without any decimal part.
  • positive/negative/zero
  • Its limits vary from one computer to another.

4
  • Integers
  • Examples
  • 1965
  • 1234
  • 98765432
  • 0
  • -1
  • -567
  • Typical range on a 32-bit computer
  • -2 x 109 to 2 x 109

5
  • Reals
  • /- xxx.yyyyy
  • xxx integer part
  • yyyyy fractional part
  • 0.12
  • -15.16
  • A better representation
  • Sign /-
  • Mantissa a fraction between 0.1 and 1.0
  • Exponent x 10e
  • Typical range on a 32-bit computer
  • -1038 to 1038

6
  • Variables
  • It is usual for people to associate a name or
    phrase with a piece of information.
  • For example, the phrase "today" has an associated
    numeric value which varies day by day.
  • This is similar to the concept of a program
    variable a program variable is some object
    (named by the programmer) which uniquely
    identifies a piece of data stored in memory.

7
real and integer variables
  • Variable declaration
  • type name

Type specifies the data type for which memory
space is to be reserved
Name is chosen by programmer with which to refer
to the variable that has been declared.
8
  • It is possible to be more than one variable of
    the same type being declared
  • type name1, name2, name3,
  • integer number1, number2, number3, ..
  • In a similar way, real variables are declared as,
  • real div1, div2,

9
Arithmetic expressions
  • The arguments of these functions are numbers,
    arithmetic functions or arithmetic expressions.
  • An arithmetic expression is one which is
    evaluated by performing a sequence of arithmetic
    operations to obtain a numeric value, which
    replaces the expression.

10
Assignment
  • name expression
  • replace the content of the variable name with the
    result of the expression

11
a numeric constant a numeric variable, which may
be preceded by a unary or -. an arithmetic
expression in parentheses, i.e.
(arithmetic_expression)
An operand of an arithmetic expression may be
N 1 2.2 K 33.9 time // 1000 3.14159
K (AB)(CD) -1.0/X Y/Z2 2.0
3.14159RADIUS
12
Operator Operation Addition or unary
- Subtraction or unary Multiplication /
Division Exponentiation
13
Aritmetik operator priorities
First Exponentiation Second or
/ Multiplication/Division Third or
- Addition/Subtraction
Evaluation will proceed
Exponentiation From right to left or
/ Multiplication/Division From left to rigt or
- Addition/Subtraction From left to rigt
14
Aritmetik operator priorities
1
5
6
2
XYZ-K/LMKN/J-GH
4
3
7
9
8
15
Aritmetik operator priorities
abcd/e-fg/hijk
  • Calculate fg and save it in temp_1
  • Calculate cd and save it in temp_2
  • Calculate temp_2/e and save it in temp_3
  • Calculate temp_1/h and save it in temp_4
  • Calculate ij and save it in temp_5
  • Calculate btemp_3 and save it in temp_6
  • Calculate temp_6-temp_4 and save it in temp_7
  • Calculate temp_7temp_5 and save it in temp_8
  • Calculate temp_8k and store it in a.

16
List-directed input and output
  • read , var_1, var_2,
  • only variables!
  • print , item_1, item_2,
  • variables, constants, expressions,
  • Value separators
  • Comma (,) 8,6,5
  • Space 8 6 5
  • Slash (/) 8/65
  • End-of-line 8
  • 6
  • 5

17
List-directed input and output
  • Two consecutive commas
  • a null value is read
  • the value of the variable is not set to zero,
    simply its value is not changed!
  • If the terminating character is a slash then no
    more data items are read processing of the input
    statement is ended

18
Character data
  • A B C D E F G H I J K L M N O P Q R S T U W X Y
    Za b c d e f g h i j k l m n o p q r s t u w x y
    z0 1 2 3 4 5 6 7 8 9s - / ( ) , . ' ! "
    lt gt ?
  • (S represents the space or blank, character)

19
Character data
  • Declaration
  • character (lenlength) name1, name2,
  • character (len6) a, b, c
  • character (len103) a
  • character (len10) b
  • Assignmenta "What a lovely afternoon!" a will
    have the value of "What a lovely afternoon!
    "b ab will have the value of "What a lov"

20
Character data
  • Concatenation
  • Operator //
  • Example
  • character (len10) a, b, c
  • a "James"
  • b "Bond"
  • c trim(a)//"?"//trim(b)
  • c will have the value of "James Bond"

21
Named constantsThe constants, which are no need
to be altered, are called named constand. They
are used by the parameter attribute in a
declaration statement.
  • type, parameter name1constant_expression1,
  • real, parameter pi3.1415926, pi_by_2 pi/2.0
  • integer, parameter max_lines 200

22
! Name ! Tel ! Address !
Purpose ! Date ! Comments..... ! pro
gram Cel_Fah real CEL, FAH print ,
"Please Enter Celsius Temperature" read ,
CEL FAH 9.0CEL/5.032.0 print,"Celsius
",CEL," Fahrenheit ", FAH end program
Cel_Fah
23
! Name ! Address !! Date !
Comments ! program Sin_Cos_Tan real
angle,S,C,T,RAD real, parameter PI
3.1415926 print , "Please Enter Value of
Angle in degrees" read , angle RAD
angle/(180.0/PI) S sin(RAD) C cos(RAD)
T tan(RAD) print,"angle ",angle," Sinx
",S," Cosx ",C," Tanx ",T end program
Sin_Cos_Tan
24
program list_directed_input_example!integersinte
gerint_1, int_2, int_3realreal_1, real_2,
real_3!initial valuesint_1-1int_2-2int_3-3
real_1-1.0real_2-2.0real_3-3.0!read
dataread, int_1, real_1, int_2, real_2,int_3,
real_3!print new valuesprint, int_1, real_1,
int_2, real_2,int_3, real_3end program
list_directed_input_example
Example
25
!this program is calculates area of a
rectangle program area_calculation use
rec reala,b,al print , "enter two edges of the
rectangle" read , a,b alarea (a,b) print ,
"a",a print,"b",b print , "area_of_rectangle"
,al endprogram area_calculation
26
  • program exercise_1
  • ! A program to convert a Celsius temperature
    to Fahrenheit
  • ! Variable declarations
  • real temp_c, temp_f
  • ! Ask for Celsius temperature
  • print , "What is the Celsius temperature ?"
  • read , temp_c
  • ! Convert it to Fahrenheit
  • temp_f9temp_c/5 32
  • ! print both temperatures
  • print ,"C ",temp_c," F",temp_F
  • end program exercise_1

27
  • program exercise_2
  • ! Variable declarations
  • real a,b,p,q,r
  • integer x,y,z
  • a 2.5
  • b 4.0
  • p a b
  • x a b
  • q a b
  • y a b
  • r p / q
  • z x / y
  • print , p,q,r
  • print , x,y,z
  • end program exercise_2

28
  • program exercise_3
  • ! Variable declarations
  • real x, y1, y2, y3
  • character(len3) ch_1,ch_2
  • character(len8) ch_3
  • ! Ask for x value
  • print , "Enter the value of x gt"
  • read , x
  • ! Calculate the polinomials with the character
    assignments
  • ch_1"x-1"
  • y1 x - 1.0
  • ch_2"x1"
  • y2 x 1.0
  • ch_3"xxx-2"
  • y3 x2 x - 2.0
  • ! print results
  • print ,ch_1,y1
  • print ,ch_2,y2
  • print ,ch_3,y3

29
  • program exercise_4
  • real, parameter apple675, butter75,
    sugar150
  • real, parameter breadcrumbs100, cream150
  • integer, parameter m4 ! the recipe prepared
    for 4 people
  • character(len3) , parameter blank" "
  • character(len11), parameter apple_p"g
    of apples"
  • character(len11), parameter butter_p"g
    of butter"
  • character(len10), parameter sugar_p"g
    of sugar"
  • character(len17), parameter
    breadcrumbs_p"g of breadcrumbs"
  • character(len11), parameter cream_p"ml
    of cream"
  • integer n
  • real apple_1, butter_1, sugar_1
  • real breadcrumbs_1, cream_1
  • ! Ask for number of people
  • print , "Enter the number of people ""n"" in
    integer"
  • read , n
  • ! Calculate the recipe
  • ! first divide all ingredients by recipe
    scale which is 4 (4 people)

30
  • program exercise_5
  • ! parameter declaration
  • real, parameter l1.6e-19, pi3.1415927,
    eps8.86e-12
  • real, parameter four_pi4.0pi
  • ! variable declaration
  • integer z
  • real phi_r, r , temp_1, temp_2
  • ! Ask for the distance r
  • print , "Enter the distance ""r"" in meters"
  • read , r
  • ! Ask for the charge z
  • print , "Enter the charge ""z"" "
  • read , z
  • ! first calculate the nominator and store it
    in temporary variable named temp_1
  • ! second calculate the dnominator and store
    it in temporary variable named temp_2
  • ! Calculate the coulomb potential phi_r
  • temp_1 z l
  • temp_2 four_pi eps r
  • phi_r temp_1 / temp_2
Write a Comment
User Comments (0)
About PowerShow.com