LAB-06 IF + Functions I Putu Danu Raharja

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

1 Chapter 2 Basic Elements of Fortran Programming.
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.
1 ICS102: Introduction To Computing King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science.
1 Lab Session-XIV CSIT121 Spring 2002 b Namespaces b First Class Travel b Lab Exercise 14 (Demo) b Lab Exercise b Practice Problem.
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.
LAB-05 Function I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals.
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.
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.
Introduction to Computers and Programming Lecture 13: User defined methods Instructor: Evan Korth New York University.
CS241 PASCAL I - Control Structures1 PASCAL I - Control Structures Philip Fees CS241.
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.
1 BIL106E Introduction to Scientific & Engineering Computing Organizational matters Fortran 90 ( subset F ): Basics Example programs in detail.
Introduction to Methods
Military Time Uses a 24-hour clock Standard time uses a 12 hour clock Military Minutes Regular and military time use the same number of minutes per hour.
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.
Introduction to Engineering MATLAB – 1 Introduction to MATLAB Agenda Introduction Arithmetic Operations MATLAB Windows Command Window Defining Variables.
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.
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.
A First Book of ANSI C, Fourth Edition1 Functions for Modularity 04/24/15.
Chapter 8: Introduction to High-level Language Programming Invitation to Computer Science, C++ Version, Third Edition.
C++ Programming Lecture 9 Functions – Part I By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
CSCI 125 & 161 / ENGR 144 Lecture 8 Martin van Bommel.
User defined functions
KIC/Computer Programming & Problem Solving 1.  Header Files  Storage Classes  Scope Rules  Recursion Outline KIC/Computer Programming & Problem Solving.
FUNCTIONS IN FORTRAN For a complex program difficulties like writing it and debugging are encountered. These can be minimized by breaking main program.
17 November 2015Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.
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.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to.
Computer Programming Basics Assistant Professor Jeon, Seokhee Assistant Professor Department of Computer Engineering, Kyung Hee University, Korea.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Computer Programming - Key Concepts and Terms Computer Program – A computer program is a set of instructions for computer, arranged in logical order, using.
Today Variable declaration Mathematical Operators Input and Output Lab
Chapter 9: Value-Returning Functions
1-1 Logic and Syntax A computer program is a solution to a problem.
Procedures and Modular Programming
FIGURE 4-10 Function Return Statements
Introduction to Programming
Math Library and IO formatting
Chapter 8: Introduction to High-Level Language Programming
FIGURE 4-10 Function Return Statements
User Defined Functions
Chapter 4 Functions Objectives
Programming Right from the Start with Visual Basic .NET 1/e
Introduction to Fortran 90/95
Computer Programming.
FIGURE 4-10 Function Return Statements
Function.
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.
Introduction to C++ Programming Language
Introduction to Computing Lecture 08: Functions (Part I)
FIGURE 4-10 Function Return Statements
Function.
Output Formatting Bina Ramamurthy 9/25/2019 BR.
UNITS OF TIME QUESTIONS.
Presentation transcript:

LAB-06 IF + Functions I Putu Danu Raharja raharja @kfupm.edu.sa Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals

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-LAB06-Term063

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-LAB06-Term063

Terminologies Main program Sub-program Call & return Function Subroutine ICS101-LAB06-Term063

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

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 ICS101-LAB06-Term063

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-LAB06-Term063

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

Exercises A year with 366 days is called a leap year. A year is a leap year if it is divisible by 4 (for example, 1980), except that it is not a leap year if it is divisible by 100 (for example, 1900); however, it is a leap year if it is divisible by 400 (for example, 2000). There were no exceptions before the introduction of the Gregorian calendar on October 15, 1582 (for example, 1500 was a leap year). Write a logical function to determine whether the given year is a leap year. ICS101-LAB06-Term063

Exercise Write a function that takes month and year as arguments and returns the number of days of that month. Write a function that takes two real numbers and tests whether they are the same up to two decimal places. Write a function that takes two times (hour and minute) in military format (09:00, 17:30) and computes the number of hours between the two times. You have to consider the case that the first time is later than the second time. ICS101-LAB06-Term063