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: Understanding Procedures, Packages, and Data Types, Slides of Aeronautical Engineering

An overview of the ada programming language, focusing on procedures, packages, and data types. It covers the structure of ada programs, the advantages of using procedures and packages, and the common layout conventions. The document also explains the concept of strong typing in ada and provides examples of various data types and their operations.

Typology: Slides

2011/2012

Uploaded on 07/20/2012

savitha_48
savitha_48 🇮🇳

3

(1)

120 documents

1 / 10

Toggle sidebar

Related documents


Partial preview of the text

Download Ada Programming: Understanding Procedures, Packages, and Data Types and more Slides Aeronautical Engineering in PDF only on Docsity! General structure of Ada programs with Ada.Text_Io; procedure Hello_Name is --| Last Modified: June 1998 FirstName: String(1..10); begin Ada.Text_IO.Put (Item => ); Ada.Text_IO.New_Line; Ada.Text_IO.Put (Item => ); Ada.Text_IO.Put(Item => "Hello "); Ada.Text_IO.Put(Item => ". Enjoy studying Ada!"); Ada.Text_IO.New_Line; end Hello_Name; Modules – • – • – • • • • • – • • ------------------------------------------------------------------- --| Requests, then displays, user's name --| Author: Michael Feldman, The George Washington University ------------------------------------------------------------------- -- object to hold user's name -- Hello_Name -- Prompt for (request user to enter) user's name "Enter your first name, exactly 10 letters." "Add spaces at the end if it's shorter.> " Ada.Text_IO.Get(Item => FirstName); -- Display the entered name, with a greeting Ada.Text_IO.Put(Item => FirstName); • Procedure Abstracts an operation Package Collects related operations and data types Advantages of modules Procedures Functional abstraction Top-down development Reduced complexity Parallel development Avoid duplication Packages Shared resources Improved productivity • Improved quality docsity.com Procedure "ADA" in giant letters would be written as a monolithic program. Then we look at it when it is broken into procedures. You can see that a procedure only needs to be written once, and can then be invoked as many times as necessary. The resultant shortening of the program is one of the benefits of procedures. Programs and packages packages • First we see how a program to write • Giant_ada_1.adb, giant_ada_2.adb • Package – Collection of resources – Encapsulated in one unit – Ex: Text_IO, Calendar, user-defined • Used for: – Collection of types and constants – Group of related subprograms – User defined types and allowable operation docsity.com Types of statements Input/Output, Assignment, Control statements Input • Get (argument) values variable Put (Item => “Please enter the first number: “); Get (Item => Number1); Types of statements Input/Output, Assignment, Control statements • Skip_Line Put (Item => “Please enter the first number “); Get (Item => Number1); Skip_Line; Put (Item => “Please enter the second number “); Get (Item => Number2); Skip_Line; Please enter the first number 42 10 Please enter the second number 23 When prompting for values from a user, always follow Get with Skip_Line – Argument is a variable that receives input – Value must be same type (e.g., integer) as – Advance to next line, ignoring unused input docsity.com Types of statements Input/Output, Assignment, Control statements Output • Put(Item => “Please enter the first number: “); Get(Item => Number1); Skip_Line; Please enter the first number: 42 Types of statements Input/Output, Assignment, Control statements Put(int_val, Width => positive_integer); Put ("The sum of the numbers is:"); Put (Number1+Number2, Width=>7); New_Line; Put ("The product of the numbers is:"); Put (Number1*Number2, Width=>3); New_Line; Put ("The sum of the numbers is:"); Put (Number1+Number2, Width=>1); New_Line; The sum of the numbers is: 14 The product of the numbers is: 48 The sum of the numbers is:14 • Put (argument) – Print argument – Leave the cursor on the same line • Formatted output docsity.com Types of statements Input/Output, Assignment, Control statements Put(real_val, Fore => positive_integer, Aft => positive_integer, Exp => positive_integer); Put (23.456); Put (23.456, Exp=>0); Put (23.456, Aft=>3, Exp=>0); Put (23.456, Aft=>2, Exp=>0); Put (23.456, Fore=>3, Aft=>3, Exp=>0); ' 2.34560000000000E+01' '23.45600000000000' '23.456' '23.46' ' 23.456' Types of statements Input/Output, Assignment, Control statements variable – Total_Num := Number1 + Number2; • Assignment – Perform calculation and save result in a docsity.com
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved