Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Ada Programming: Arrays, Records, Types, Access, and Control Structures, Slides of Programming Languages

An introduction to various programming concepts in ada, including arrays, record declaration, discriminated types, access types, and control structures such as if statements and case statements. It explains the differences between union types in c and discriminated types in ada, and demonstrates how to declare and use access types. The document also covers the syntax and usage of if statements, case statements, and other control structures.

Typology: Slides

2011/2012

Uploaded on 11/10/2012

omni
omni 🇮🇳

4.6

(9)

46 documents

1 / 11

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Arrays
type Int_Buffer is array (1..10) of Integer;
type Normalized_Distribution is array(-100..100) of Natural;
type String is array (Positive range <>) of Character;
Last_Name : String(1..20);
type Days is (Monday, Tuesday, Wednesday, Thursday,
Friday, Saturday, Sunday);
type Daily_Sales is array(Days) of Float;
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Ada Programming: Arrays, Records, Types, Access, and Control Structures and more Slides Programming Languages in PDF only on Docsity!

Arrays

type Int_Buffer is array (1..10) of Integer;

type Normalized_Distribution is array (-100..100) of Natural;

type String is array (Positive range <>) of Character; Last_Name : String(1..20);

type Days is (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday); type Daily_Sales is array (Days) of Float;

Record Declaration

type Address is record Street : Unbounded_String; City : Unbounded_String; Postal_Code : String(1..10); end record ;

My_Address : Address; My_Address.Postal_Code := “00000-0000”;

Instead, Discriminated Types

• A record can have discriminants:

type IF is (Int, Float); type Int_Float (V : IF := Int) is record case V is when Int => Int_Val : Integer; when Float => Float_Val : Float; end case ; end record ;

  • Now the value of the discriminant V shows what type is currently present

Puzzle : Int_Float; … Puzzle := (Float, 1.0); F := Puzzle.Float_Val; -- OK I := Puzzle.Int_Val; -- raises exception … Puzzle.V := SomeIntValue; -- not allowed!

Statement Forms

  • Assignment statement (its not an expression)
    • Variable := expression ;
  • If statements
  • Loops
  • Exit statement
  • Case statements
  • Return statement
  • Block Statement
  • Raise statement

If Statement – Fully Blocked

if condition then -- any number of statement(s) end if ;

if condition1 then -- statement(s) elsif condition2 then if condition3 then -- statements end if -- statement(s) … else -- statement(s) end if ;

Boolean expression

Case Statements

case expression is when choice list => sequence-of-statements when choice list => sequence-of-statements when others => sequence-of-statements end case;

Case Statements

case TODAY is when MON .. THU => WORK; when FRI => WORK; PARTY; when SAT | SUN => REST; end case;