1 / 13

ITEC 320

ITEC 320. Lecture 6 In-class coding Functions. Review. Types Homework Website is up Questions?. VIM. Dr. Okie has been providing VIM information Do you want a VI tutorial? What are the advantages of knowing a power editor?. Outline. Procedures Functions Problems. Functions.

star
Download Presentation

ITEC 320

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ITEC 320 Lecture 6 In-class coding Functions

  2. Review • Types • Homework • Website is up • Questions?

  3. VIM • Dr. Okie has been providing VIM information • Do you want a VI tutorial? • What are the advantages of knowing a power editor?

  4. Outline • Procedures • Functions • Problems

  5. Functions • Similar to java methods with a non-void return type • Must have a return type • Must be defined before use • Cannot modify parameters

  6. Syntax function sumArray(a: Int_Array) return integer is s: Integer := 0; -- holds the sum begin for i in a'range loop s := s + a(i); end loop; return s; end sumArray;

  7. Procedures • No return type allowed • Parameters can be changed • In (default) • Out (allows passing back to the caller) • In Out (pass in and out) • What about the get procedure’s parameter? • Structure charts help

  8. Syntax with ada.text_io; use ada.text_io; with ada.integer_text_io; use ada.integer_text_io; procedure inout is procedure vars(a: in Integer; b: in out Integer; c: out Integer) is begin b:= b+a; c:= b+3; end vars; x: Integer; y: Integer; z: Integer; begin x:=2; y:=3; vars(x,y,z); put(x'img & "|" & y'img & "|" & z'img); end inout;

  9. Issues • Assigning to an in parameter • Using an out parameter’s values in the procedure (by default it can be anything) • Forgetting to assign a value to an out parameter • Can’t fool variables • I.e. passing an in mode variable to another procedure where it is an out mode parameter

  10. Discussion • Web example

  11. Problems • Write a function/procedure that returns whether or not a String is a palindrome

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

  13. Summary • Functions • Procedures

More Related