0% found this document useful (0 votes)
41 views

Data and Control Abstraction

The document discusses abstractions in programming languages. It describes two main types of abstractions: data abstractions and control abstractions. Data abstractions include basic data types like integers and floating point numbers, as well as structured data types like arrays, classes, and structures. Control abstractions include basic statements like assignment, as well as structured statements like conditionals, loops, and procedure calls that allow dividing a program into logical groups. Procedures are powerful structured control abstractions that must be declared before being invoked.

Uploaded by

abdelrahman12
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Data and Control Abstraction

The document discusses abstractions in programming languages. It describes two main types of abstractions: data abstractions and control abstractions. Data abstractions include basic data types like integers and floating point numbers, as well as structured data types like arrays, classes, and structures. Control abstractions include basic statements like assignment, as well as structured statements like conditionals, loops, and procedure calls that allow dividing a program into logical groups. Procedures are powerful structured control abstractions that must be declared before being invoked.

Uploaded by

abdelrahman12
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Concepts of

Programming
Languages
Data and Control Abstractions

Prepared by Dr Ahmed Rafea, Dr Sherif Aly, Adapted by Nada A.


GabAllah 1
Abstractions in
Programming Languages

• Data abstractions
• Strings

• Numbers

• Trees

• Control abstractions
• Loops

• Conditional statements

• Procedure calls.

Prepared by Dr Ahmed Rafea, Dr Sherif Aly, Adapted by Nada A.


GabAllah 2
Data Abstractions – Simple or Basic

Floating point data values


Abstract the internal Integer data values are are stored using a
representation of usually stored using two's mantissa representation
common data values. complement for example. (mantissa sign, value,
exponent sign, value).

Prepared by Dr Ahmed Rafea, Dr Sherif Aly, Adapted by Nada A. GabAllah 3


Data Memory locations
containing data
The kind of data
value is also
Abstraction values are
abstracted by
giving them names
abstracted using a
data type (int,
double, float, etc.)
s– using variables.

Simple or int x; (C, C++, and


Java)
var x: integer;
(Pascal)

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

Prepared by Dr Ahmed Rafea, Dr Sherif Aly, Adapted by Nada A. GabAllah


5
Data Abstractions – Unit
Abstractions
• In large programs, it is necessary to collect
related code into specific locations within a
program.

• Examples:
• Packages in Ada and Java
• Modules in ML and Haskell

• A class may also be viewed as a unit


abstraction that provides data encapsulation
and information hiding by providing access
conventions and restrictions.
Prepared by Dr Ahmed Rafea, Dr Sherif Aly, Adapted by Nada A.
GabAllah 6
• Unit abstractions facilitate reusability:
the ability to reuse data abstractions in
different programs.
Data Abstractions
– • Such data abstractions represent:

• Components: Operationally complete


Unit Abstractions pieces of a program or user interface.

• Containers: Data structures


containing other user-defined data.

Prepared by Dr Ahmed Rafea, Dr Sherif Aly, Adapted by Nada A. GabAllah 7


Data Abstractions – Unit
Abstractions

• Unit abstractions form the basis for language


library mechanisms.

Prepared by Dr Ahmed Rafea, Dr Sherif Aly, Adapted by Nada A.


GabAllah 8
Control Abstractions -

Basic

• Typical basic control abstractions are


those that combine a few
machine instructions into a more
understandable abstract statement.

• Example: Assignment
• □ x = x + 10

• It abstracts the fetching of the value of x,


performing a computation and storage of
a value into a location denoted by a
variable name.
Prepared by Dr Ahmed Rafea, Dr Sherif Aly, Adapted
by Nada A. GabAllah 9
Control Abstractions - Structured

Divide a program
into groups of Examples:
instructions.

switch (C, C++,


case (Pascal) while
Java)

Prepared by Dr Ahmed Rafea, Dr Sherif Aly, Adapted by Nada A.


GabAllah 10
Control Abstractions - Structured

Example (C):
if (x > 0)
{

} else
{

}

Prepared by Dr Ahmed Rafea, Dr Sherif Aly, Adapted by Nada A.


GabAllah 11
Control Abstractions -
■ Example (Ada):
Structured if x>0.0 then
… Opening a group of
… nested statements is
automatic!

else

end if;

Dr. Sherif G. Aly


12

Prepared by Dr Ahmed Rafea, Dr Sherif Aly, Adapted by Nada A.


12
GabAllah
Control Abstractions - Structured
Structured control structures can be nested.

Procedures, sometimes called subprograms or routines are also


powerful structured control abstractions.

Procedures must be declared, then invoked.

Prepared by Dr Ahmed Rafea, Dr Sherif Aly, Adapted by Nada A. 13


GabAllah
Control Abstractions -

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;

Prepared by Dr Ahmed Rafea, Dr Sherif Aly, Adapted by Nada A.


14
GabAllah
Control Abstractions -
■ Example: Ada gcd call
Structured
gcd(8, 18, d)

Call and Actual


Parameters

15

Prepared by Dr Ahmed Rafea, Dr Sherif Aly, Adapted by Nada A.


15
GabAllah
Control Abstractions - Structured

• Example: Fortran subroutine declaration

SUBROUTINE gcd (u, v, x)


… END

• Fortran call:
CALL gcd( a, b, d)

Prepared by Dr Ahmed Rafea, Dr Sherif Aly, Adapted by Nada A.


GabAllah 16
Control Abstractions - Structured

Procedures are They require storing


more complex information about
mechanisms than the program at the
selection or looping. point of the call.
Prepared by Dr Ahmed Rafea, Dr Sherif Aly, Adapted by Nada A.
GabAllah 17
Control Abstractions - Structured

FUNCTIONS ARE SIMPLY SOME LANGUAGES SUCH AS C AND


PROCEDURES THAT RETURN A C++ HAVE VOID FUNCTIONS
VALUE OR RESULT. (RETURN NO VALUE).

Prepared by Dr Ahmed Rafea, Dr Sherif Aly, Adapted by Nada A.


GabAllah 18
Control Abstractions -
Unit
• Control abstractions can also be grouped into files,
packages, and units exactly like data abstractions.

Prepared by Dr Ahmed Rafea, Dr Sherif Aly, Adapted by Nada A.


GabAllah 19

You might also like