2.1 Structuring The Data, Computations and Program
2.1 Structuring The Data, Computations and Program
2.1 Structuring The Data, Computations and Program
SE Computer Engineering
(2019 Pattern)
1
UNIT-
UNIT-II
Structuring the Data, Computations and Program
2
Good Thought
3
Unit II Contents
• Elementary Data Types :Primitive data Types, Character String types, User
Defined Ordinal Types, Array types, Associative Arrays, Record Types, Union Types,
Pointer and reference Type.
• Expression and Assignment Statements: Arithmetic expression, Overloaded
Operators, Type conversions, Relational and Boolean Expressions, Short Circuit
Evaluation, Assignment Statements, Mixed mode Assignment.
• Statement level Control Statements: Selection Statements, Iterative Statements,
Unconditional Branching.
• Subprograms: Fundamentals of Sub Programs, Design Issues for Subprograms,
Local referencing Environments, Parameter passing methods.
• Abstract Data Types and Encapsulation Construct: Design issues for
Abstraction, Parameterized Abstract Data types, Encapsulation Constructs, Naming
Encapsulations.
Elementary Data Types
1. Numeric Types-
Integer,
Floating-Point
Complex
Decimal
2. Boolean Types
3. Character Types
Character String types
Design Issues:
• Should strings be a special kind of character array or a primitive type?
• Should strings have static or dynamic length?
2
User Defined Ordinal Types
Enumeration Type:
• An enumeration type is one in which all of the possible values, which are
named constants, are provided, or enumerated, in the definition
• Defining and grouping collections of named constants, which are called
enumeration constants. The definition of a typical enumeration type is
shown in the following C# example:
Array types
Design Issues
• What types are legal for subscripts?
• Are subscripting expressions in element references range checked?
• When are subscript ranges bound?
• When does array allocation take place?
• Are ragged or rectangular multidimensional arrays allowed, or both?
• Can arrays be initialized when they have their storage allocated?
• What kinds of slices are allowed, if any?
Arrays and Indices
Specific elements of an array are referenced by means of a two-level syntactic
mechanism, where the first part is the aggregate name, and the second part is a
possibly dynamic selector consisting of one or more items known as subscripts or
indices.
array_name(subscript_value_list) → element
Sum := Sum + B(I);
Array types
Subscript Bindings and Array Categories
1. static array
4. Heap-dynamic array
Array types
Array Initialization:
int list [] = {4, 5, 7, 83};
char name [] = "freddie";
char *names [] = {"Bob", "Jake", "Darcie"};
String[] names = ["Bob", "Jake", "Darcie"];
Array Operations:
• The C-based languages do not provide any array operations, except through
the methods of Java, C++, and C#.
• Perl supports array assignments but does not support comparisons.
• F# includes many array operators in its Array module. Among these are
Array.append, Array.copy, and Array.length.
Array types
Array Operations (cont….):
• In APL, the four basic arithmetic operations are defined for vectors (single-
dimensioned arrays) and matrices, as well as scalar operands.
• For example,
A+B
A×B
is a valid expression, whether A and B are scalar variables, vectors, or matrices.
• APL includes a collection of unary operators for vectors and matrices, some of
which are as follows (where V is a vector and M is a matrix):
ϕV reverses the elements of V
ϕM reverses the columns of M
θM reverses the rows of M
ØM transposes M (its rows become its columns and vice versa)
÷M inverts M
Array types
Rectangular and Jagged Arrays
• A rectangular array is a multidimensioned array in which all of the rows
have the same number of elements and all of the columns have the same
number of elements. Rectangular arrays model rectangular tables exactly.
• A jagged array is one in which the lengths of the rows need not be the
same. For example, a jagged matrix may consist of three rows, one with 5
elements, one with 7 elements, and one with 12 elements
• C, C++, and Java support jagged arrays but not rectangular arrays.
Array types
Slices
• A slice of an array is some substructure of that array.
• For example, if A is a matrix, then the first row of A is one possible slice, as
Definitions of Records
• A record is an aggregate of data elements in which the individual
elements are identified by names and accessed through offsets from the
beginning of the structure.
Record Types
which all intermediate record names, from the largest enclosing record to the
specific field, are named in the reference.
Employee_Record.Employee_Name.Middle
2. elliptical references :
• C and C++, the union construct is used to specify union structures. The
unions in these languages are called free unions, because
programmers are allowed complete freedom from type checking in their
use.
Pointer Type
• A pointer type is one in which the variables have a range of values that
consists of memory addresses and a special value, nil.
Reference Type