LAB-05 Function I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals.

Slides:



Advertisements
Similar presentations
Chapter 7 Introduction to Procedures. So far, all programs written in such way that all subtasks are integrated in one single large program. There is.
Advertisements

Chapter 3 Top-Down Design with Functions. 3-2 Outline 3.1 BUILDING PROGRAMS FROM EXISING INFORMATION –CASE STUDY: FINDING THE AREA AND CIRCUMFERENCE OF.
LAB-04 IF Structure I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals.
1 ICS 101 – LAB 2 Arithmetic Operations I Putu Danu Raharja kfupm.edu.sa Information & Computer Science Department CCSE - King Fahd University.
LAB-03 Logical Operations I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum.
CS 201 Functions Debzani Deb.
Chapter 6 Programming with Functions. FUNCTIONS Intrinsic Functions (or called library functions) Function Subprograms: programmer-defined functions.
Department of Computer Science University of Maryland, College Park
SUB-PROGRAMS MET 50. Using sub-programs The codes we/you have written so far are teeny ( lines). In science & engineering, many codes are huge.
Basic Building Blocks In all ways of life, the easiest way to solve most problems is to break them down into smaller sub_problems and then to deal with.
CS 201 Functions Debzani Deb.
Top-Down Design with Functions 4 What do programmer’s (not programs!) use as input to the design of a program? –Documentation Problem definition Requirements.
1 CSC 1401 S1 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University
Algorithms. Introduction Before writing a program: –Have a thorough understanding of the problem –Carefully plan an approach for solving it While writing.
LAB-03 Logical Operations I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum.
ICS 101 – Introduction to Computer Programming I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University.
LAB-12 2-D Array I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals.
Chapter 9 Introduction to Procedures Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul -
FORTRAN PROGRAMMING BASICS MET 50. Programming Basics The basic layout of all programs is as follows (p.33) PROGRAM name = heading (i.e., title) Specifications.
LAB-10 1-D Array I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals.
Introduction to Methods
Functions. Program complexity the more complicated our programs get, the more difficult they are to develop and debug. It is easier to write short algorithms.
Large problems can be divided into smaller sub - problems ♦ each sub - problem can be solved separately in order to reach to the solution of the original.
Fortran- Subprograms Chapters 6, 7 in your Fortran book.
CP104 Introduction to Programming Top-down design with functions Lecture 6-8 __ 1 Top-Down Design with Functions C Library functions Case studies Top-down.
1 Introduction to Computers II Lecture 4 Dr. Mehmet Demirer Dr. Seniha Esen Yuksel.
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
Computer Science Department Data Structure & Algorithms Lecture 8 Recursion.
CSE 131 Computer Science 1 Module 1: (basics of Java)
Functions. Type of Subprograms Fortran 90/95 allows for two types of subprograms: –Functions, and –Subroutines. In general, there are two forms of subprograms:
Functions Manesh T 2 Chapter Topics Define Function Standard (Predefined) Functions User-Defined Functions Parts of functions.
CHAPTER 9 SUBPROGRAMS Subprograms are useful in the following cases: long complicated program  Subprograms make it readable and simple by dividing it.
Writing Program Code in BASIC Write a program to prompt for and accept values into TWO variables, numx and numy. The program should square the value stored.
Week 3 Let's review! Fundamental data types List-directed input/output.
1 ICS103 Programming in C Lecture 7: Introduction to Functions.
FUNCTIONS AND STRUCTURED PROGRAMMING CHAPTER 10. Introduction A c program is composed of at least one function definition, that is the main() function.
Chapter 6 User-Defined Functions I. Objectives Standard (predefined) functions What are they, and How to use them User-Defined Functions Value returning.
Procedural programming in Java Methods, parameters and return values.
A First Book of ANSI C, Fourth Edition1 Functions for Modularity 04/24/15.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Week 4: Organizational matters Register yourself to CIMS (Course Information and Management System) by clicking on Homework at hidiv.cc.itu.edu.tr/~F90.
C++ Programming Lecture 9 Functions – Part I By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Chapter 9 Functions Dept of Computer Engineering Khon Kaen University.
User defined functions
KIC/Computer Programming & Problem Solving 1.  Header Files  Storage Classes  Scope Rules  Recursion Outline KIC/Computer Programming & Problem Solving.
Check Your Homework Answers with a Partner & Around the Room… Unit Circle Quiz Day!
FUNCTIONS IN FORTRAN For a complex program difficulties like writing it and debugging are encountered. These can be minimized by breaking main program.
Solving Complex Problems. Review A subroutine is a set of instructions to perform a particular computation –used to solve subproblems of more complex.
1 MODULAR DESIGN AND ABSTRACTION. 2 SPECIFYING THE DETAILS OF A PROBLEM INTO A RELATED SET OF SMALLER PROBLEMS.
Subroutines. Harder Problems  Examples so far: sum, sum between, minimum –straightforward computation –small number of intermediate variables –single.
Chapter 3 : Top Down Design with Functions By Suraya Alias.
LAB-09 DO WHILE loop I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Procedures and Modular Programming
FIGURE 4-10 Function Return Statements
Chapter 4 Procedural Abstraction and Functions That Return a Value 1
Lesson 11-7 Ratios of Areas (page 456)
Math Library and IO formatting
Chapter 8: Introduction to High-Level Language Programming
FIGURE 4-10 Function Return Statements
User Defined Functions
Computer Programming.
FIGURE 4-10 Function Return Statements
LAB-06 IF + Functions I Putu Danu Raharja
A function is a group of statements that exist within a program for the purpose of performing a specific task. We can use functions to divide and conquer.
Output Formatting Bina Ramamurthy 4/16/2019 BR.
FIGURE 4-10 Function Return Statements
Chapter 4 Procedural Abstraction and Functions That Return a Value 1
Top-Down Design with Functions
Output Formatting Bina Ramamurthy 9/25/2019 BR.
Presentation transcript:

LAB-05 Function I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals

ICS101-LAB05-Term073 2 Rationale If you work on a program to solve a bigger problem, your program will become larger (more lines of code). A large program is harder to debug (so far we have written programs < 100 lines but we still make mistakes) Some of the code may be used several times.

ICS101-LAB05-Term073 3 Subprogram A big problem can be solved by dividing it into smaller sub-problems and conquering the sub-problems A large program can be divided into simpler sub-programs that can be implemented and tested independently Sub-programs can be reused

ICS101-LAB05-Term073 4 Terminologies Main program Sub-program Call & return Function Subroutine

ICS101-LAB05-Term073 5 Function A function consists of: Function header Function body Function header type FUNCTION fname (list of arguments) Function body Declaration statements Executable statements Must have at least one RETURN statement Must be ended with an END statement

ICS101-LAB05-Term073 6 Example: Area of a triangle REAL FUNCTION TRAREA (A, B) REAL A, B TRAREA = A * B / 2 RETURN END REAL X, Y, AREA READ*, X, Y AREA = TRAREA(X, Y) PRINT*, 'Area = ', AREA END

ICS101-LAB05-Term073 7 Intrinsic Functions Functions which are available from the FORTRAN language (p. 63) SQRT(X) ABS(X) SIN(X) COS(X) TAN(X) EXP(X) LOG(X) LOG10(X) INT(X) REAL(K) MOD(M, N)

ICS101-LAB05-Term073 8 Statement Function Expressed as: fname (list of arguments) = expression Example: TRA (BASE, HEIGHT) = BASE * HEIGHT * 0.5

ICS101-LAB05-Term073 9 Exercises Write a function to calculate the area of a circle; a function to calculate the circumference of a circle and the main program to test both of them. Write a function to calculate the area of a rectangle. Write a function called ISODD that checks if an integer X is odd or even. If X is odd, it returns.TRUE. Otherwise, it returns.FALSE.

ICS101-LAB05-Term QUIZ ………….. now