ITEC 320 Lecture 5 Scope Exceptions. Scope / Exceptions Review Functions Procedures.

Slides:



Advertisements
Similar presentations
Question Bank. Explain the syntax of if else statement? Define Union Define global and local variables with example Concept of recursion with example.
Advertisements

Sub and Function Procedures
ITEC 320 Lecture 3 In-class coding / Arrays. Arrays Review Strings –Advantages / Disadvantages Input –What two methods are used? Conditionals Looping.
1 CS 201 Compiler Construction Lecture Interprocedural Data Flow Analysis.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 4 Assembly Language Programming 2.
ITEC 320 Lecture 4 Sub-Types Functions. Functions / Procedures Review Types Homework Questions?
Exception Handling Exception handling (EH) allows a programmer to provide code in the program to handle run-time errors or exceptional situations – this.
Chapter 10 Introduction to Arrays
Chapter 7: User-Defined Simple Data Types, Namespaces, and the string Type.
Objectives In this chapter, you will:
Chap-7 Robust_Input. A Package for Robust Input Read input values by calls to procedure Get overloading “Get” procedure for Integer and Float values There.
1 CS 106, Winter 2009 Class 19, Section 4 Slides by: Dr. Cynthia A. Brown, Instructor section 4: Dr. Herbert G. Mayer,
Exceptions (Large parts of these copied from Ed Schonberg’s slides)
Concurrency - 1 Exceptions General mechanism for handling abnormal conditions Predefined exceptions: constraint violations, I/O errors, communication errors,
More Ada Constructs 7 Oct Today’s Constructs Derived types Record types Array types Visibility and scope Subprogram arguments.
Chapter 15 Recursive Algorithms. 2 Recursion Recursion is a programming technique in which a method can call itself to solve a problem A recursive definition.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 12 Imperative Programming I really hate this.
1 CS101 Introduction to Computing Lecture 29 Functions & Variable Scope (Web Development Lecture 10)
ITEC 320 Lecture 16 Packages (1). Review Questions? –HW –Exam Nested records –Benefits –Downsides.
Ada is a structured, statically typed, imperative, wide- spectrum, and object-oriented high-level computer programming language, extended from Pascal.
Chapter 13, Slide 1 Exception Handling Exception handling is a language feature that allows the programmer to handle runtime "exceptional conditions."
Microsoft Visual Basic 2008 CHAPTER NINE Using Arrays and File Handling.
ITEC 320 Procedural Programming Dr. Ray Lecture 1.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 7 Sub and Function Procedures.
Hans-Peter Plag November 6, 2014 Session 4 (Programming Languages) (Data Types and Variables) Expressions and Operators Flow Control.
Dale Roberts Object Oriented Programming using Java - Enumerations Dale Roberts, Lecturer Computer Science, IUPUI Department.
ITEC 320 Lecture 10 Packages (2). Review Packages –What parts do they have? –Syntax?
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Slide: 1 Copyright © AdaCore Subprograms Presented by Quentin Ochem university.adacore.com.
Web Database Programming Week 3 PHP (2). Functions Group related statements together to serve “a” specific purpose –Avoid duplicated code –Easy maintenance.
ADT ITEC 320 Lecture 22. ADT Review Generic lists –Ada compilation workout Recursive algorithms –What would a recursive copy look like? Project 4 is up.
With Python.  One of the most useful abilities of programming is the ability to manipulate files.  Python’s operations for file management are relatively.
Sha Tin Methodist College F.4 Computer Studies Pascal Programming.
Introduction to Programming (in JavaScript) in 10 minutes …hopefully Else.
Chap 7- Control Structures : The WHILE Statement.
C463 / B551 Artificial Intelligence Dana Vrajitoru Python.
Advanced Computer Science Lesson 4: Reviewing Loops and Arrays Reading User Input.
ITEC 320 Lecture 10 Examples. Review Strings –What types are there? –What are the differences? –What should you use where? Homework –Hardest part –Easiest.
ITEC 320 Lecture 11 Application Part Deux Look Ahead.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 8: User-Defined Simple Data Types, Namespaces, and the string Type.
Chapter 6 Counting Loops; Subtypes In preceding chapters, 1.Sequence and 2.Conditional structures In this chapter, 3.Repetition, or iteration.
1 COMS 261 Computer Science I Title: Functions Date: October 12, 2005 Lecture Number: 17.
KIC/Computer Programming & Problem Solving 1.  Header Files  Storage Classes  Scope Rules  Recursion Outline KIC/Computer Programming & Problem Solving.
Functions: Part 2 of /11/10: Lecture 16 CMSC 104, Section 0101 John Y. Park 1.
ITEC 320 Lecture 9 Nested records / Packages. Review Project ?’s Records Exam 1 next Friday.
Recursion A recursive definition is one which uses the word or concept being defined in the definition itself Example: “A computer is a machine.
Higher Computing Science 2016 Prelim Revision. Topics to revise Computational Constructs parameter passing (value and reference, formal and actual) sub-programs/routines,
1 CSC103: Introduction to Computer and Programming Lecture No 16.
C++ Programming Lecture 14 Arrays – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
BY: JAKE TENBERG & CHELSEA SHIPP PROJECT REVIEW: JGIBBERISH.
Programming for GCSE Topic 8.1: Functions T eaching L ondon C omputing William Marsh School of Electronic Engineering and Computer Science Queen Mary University.
ITEC 320 Lecture 6 More on arrays / Strings. Arrays Review Scope Exceptions Arrays –Dynamic arrays How? Typed and anonymous.
EGRE 6311 LHO 04 - Subprograms, Packages, and Libraries EGRE 631 1/26/09.
structured statically typed imperative wide-spectrum object-oriented high-level computer programming language extended from Pascal and other languages.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Preface IIntroduction Course Objectives I-2 Oracle Complete Solution I-3 Course Agenda I-4 Tables Used in This Course I-5 The Order Entry Schema I-6 The.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 8: Namespaces, the class string, and User-Defined Simple Data Types.
Exception Handling Exception handling (EH) allows a programmer to provide code in the program to handle run-time errors or exceptional situations this.
Test 2 Review Outline.
Introduction to Programming
Objectives In this chapter, you will:
Enumeration Type Data type: a set of values with a set of operations on them Enumeration type: a simple data type created by the programmer To define an.
Using local variable without initialization is an error.
Engineering Computation with MATLAB
Covering CWE with Programming Languages and Tools
Chapter 9: Value-Returning Functions
Chapter 8 - Functions and Functionality
Objectives In this chapter, you will:
COMPUTING.
Presentation transcript:

ITEC 320 Lecture 5 Scope Exceptions

Scope / Exceptions Review Functions Procedures

Scope / Exceptions Outline Scope Exceptions Variable sized arrays

Scope / Exceptions Problems Given n of 1 or more, return the factorial of n, which is n * (n-1) * (n-2) Compute the result recursively (without loops).

Scope / Exceptions Problem Given a string, compute recursively (no loops) the number of times lowercase "hi" appears in the string.

Scope / Exceptions No- parameters procedure demo is procedure printlines is begin put(" "); end printlines; begin printlines; -- do something printlines; end demo;

Scope / Exceptions Global procedure main is MV: constant Natural := 10; subtype MyRange is Integer range 1.. MV; m1, m2: MyRange; -- procedure p(m: MyRange) is someLocal: Natural; begin... m1 := 2 * m2;... end p; procedure q is begin p(3); end q; begin -- main q; end main;

Scope / Exceptions Exceptions What are they? –Common ones Data input errors End of file errors Constraint errors

Scope / Exceptions Examples procedure demo_exceptions is i: natural; begin get(i); -- do something with i exception when data_error => put_line("found non-numeric input "); when end_error => put_line("end of file reached"); when constraint_error => put_line("integer not a natural"); when others => put_line("integer not a natural"); end demo_exceptions;

Scope / Exceptions Places Handle everything Handle specific parts (Add in a begin / end) Others –Create your own VN:Exception and raise VN –Web example

Scope / Exceptions Questions What is the problem with ADA arrays? Why is this problem important? What are the downsides to the current method of using arrays?

Scope / Exceptions Solution Declaration procedure declare_example is size: natural; begin get(size); declare a: array(1.. size) of Integer; begin for i in a'range loop get(a(i)); end loop; end; end declare_example;

Scope / Exceptions More with ada.text_io; with ada.integer_text_io; use ada.text_io; use ada.integer_text_io; procedure declare_example2 is type My_Array_Type is array(Natural range <>) of Integer; size: natural; begin get(size); declare a: My_Array_Type(1.. size); begin for i in a'range loop get(a(i)); end loop; for i in a'range loop put(i); end loop; end; end declare_example2;

Scope / Exceptions Parameter s with ada.text_io; with ada.integer_text_io; use ada.text_io; use ada.integer_text_io; procedure declare_example3 is type My_Array_Type is array(Natural range <>) of Integer; procedure putArray(a: My_Array_Type) is begin for i in a'range loop put(i); end loop; end putArray; a: My_Array_Type(1.. 10); begin for i in a'range loop get(a(i)); end loop; putArray(a); end declare_example3;

Scope / Exceptions Issue Named type required for passing to functions / procedures procedure demo is values1: array (1.. 50) of integer; values2: array (1.. 50) of integer; begin values1 := (2 => 4, 4 => 16, 5 => 25, 3 => 9, others => 0); - values2 := (others => 0); end demo; What is values 1? Can’t duplicate when passing to a function.

Scope / Exceptions Summary Scope Exceptions