Type Classification-Computer Programming For Aeronautical Engineering And Sciences-Lecture Slides, Slides of Aeronautical Engineering

Prof. Balamohan Pawar delivered this lecture at Allahabad University for Aeronautical Engineering and Computer Programming course. Its main points are: Scalar, Classification, Type, Elementary, Composite, Component, Attribute, Operation, Discrete, Output

Typology: Slides

2011/2012

Uploaded on 07/20/2012

savitha_48
savitha_48 🇮🇳

3

(1)

109 documents

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Elementary Types : Values are
logically indivisible
Composite Types : Values composed
from components
Type Classification
Elementary
Types Scalar
Types
Access
Types
Discrete
Types
Real
Types
Scalar Types
relational operators are
defined
position number
Scalar
Types
Discrete
Types
Real
Types
Integer
Types
Enumeration
Types
Fixed
Point
Floating
Point
•Ordered
Each value of a discrete type has a
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Type Classification-Computer Programming For Aeronautical Engineering And Sciences-Lecture Slides and more Slides Aeronautical Engineering in PDF only on Docsity!

• Elementary Types : Values are

logically indivisible

• Composite Types : Values composed

from components

Type Classification

Elementary

Types

Scalar

Types

Access

Types

Discrete

Types

Real

Types

Scalar Types

→ relational operators are

defined

position number

Scalar

Types

Discrete

Types

Real

Types

Integer

Types

Enumeration

Types

Fixed

Point

Floating

Point

• Ordered

• Each value of a discrete type has a

Attributes of Scalar Types

range of S. The value of this attribute

is of the type of S.

range of S

Operations on Scalar Types

the value in the type

string

on the scalar type

– S’Succ (Integer) : returns (Integer + 1)

S’First denotes the lower bound of the

S’Last denotes the upper bound of the

S’Range is equivalent to the range

S’First .. S’Last

S’Min returns lower of two elements

S’Max returns higher of two elements

S’Value accepts a string and returns

S’Image converts the value into a

S’Pred and S’Succ – behavior depends

S’Pred (Integer) : returns (Integer -1)

Subtypes

subtype Natural is Integer range 0..Integer’Last;

subtype Positive is Integer range 1..Integer’Last;

subtype NonNegativeFloat is Float range 0.0 .. Float’Last;

subtype SmallInt is Integer range -50..50;

subtype CapitalLetter is Character range ’A’..’Z’; X, Y, Z : SmallInt; NextChar : CapitalLetter; Hours_Worked : NonNegFloat;

X := 25;

Y := 26;

Z := X + Y;

Operations on Discrete Types

of the argument

whose position number equals the

value of S

S’Pos(Arg) returns the position number

S’Val(Arg) a value of the type of S

CQ

Enumeration Types

type Class is (Freshman, Sophomore, Junior, Senior);

type days is (Mon, Tue, Wed, Thu, Fri, Sat, Sun); type colours is type traffic_colours is (green, yellow, red); type suits is (clubs, diamonds, hearts, spades);

words

• The outputs are exactly the same

• There will be no outputs

• The outputs are different

• I don’t know

(white, red, yellow, green, blue, pink, black);

• A data type whose values are a collection of allowed

Derived Types

• age := -20;

• shoe_size := 2 * no_on_bus;

real world.

Derived Integer Types

• derived from INTEGER:

• type ages INTEGER range 0 .. 110;

age : ages;

voting_age : constant ages := 18;

type heights 0 .. 230;

height : heights;

min_enrolment : constant := 6;

max_enrolment : constant := 200;

type class_sizes 0..max_enrolment;

class_size : class_sizes;

height := age - class_size;

• Types help program values reflect the

New data types can be

is new

is range

is range

Type conversion

strong typing: different types cannot

be mixed

  • type length 5 range 0.0 .. 1.0E10;

type area 5 range 0.0 .. 1.0E20;

function area_rectangle (L,H : length) return area is

begin

return area(L) * area(H);

end ;

Benefits of derived types

– age := -20;

– class_size := class_size + 100;

objects

• Ada has

• Explicit type conversion is permitted:

is digits

is digits

• Nonsense rejected by compiler

height := age - class_size;

• "Out of range" rejected by compiler

• “Out of range” run time error

• Enforce distinct nature of different

• Robust, elegant, effective programs

Example

• subtypes[1..3].adb