Data and Control Abstraction
Data and Control Abstraction
Programming
Languages
Data and Control Abstractions
• Data abstractions
• Strings
• Numbers
• Trees
• Control abstractions
• Loops
• Conditional statements
• Procedure calls.
Basic
Prepared by Dr Ahmed Rafea, Dr Sherif Aly, Adapted by Nada A. GabAllah 4
Data Abstractions –
■ Data structures are the principal method for
Structured abstracting collections of related data.
□ Arrays
■ int a[10] (C, C++)
■ int a[] = new int[10] (Java)
■ typedef int Intarray[10]; (A new non-internal data type called
Intarray. It is an array of ten ints).
□ Class
□ Struct
• Examples:
• Packages in Ada and Java
• Modules in ML and Haskell
Basic
• Example: Assignment
• □ x = x + 10
Divide a program
into groups of Examples:
instructions.
Example (C):
if (x > 0)
{
…
} else
{
…
}
Structured
■Example: Ada gcd declaration
procedure gcd (u, v: in integer; x: out
integer) is y, t, z: integer;
begin Formal
Parameters
z := u;
y := v; loop
exit when y = 0; t := y;
y := z mod y; 14
z := t; end loop;
x := z; end gcd;
15
• Fortran call:
CALL gcd( a, b, d)