Modular Programming with Functions

Slides:



Advertisements
Similar presentations
User-Defined Functions Like short programs Can operate on their own data Can receive data from callers and return data to callers.
Advertisements

User Defined Functions
Chapter Five Functions
Introduction to C++ Functions Chapter 6 Sections 6.1 – 6.3 Computer II.
Introduction to Computers and Programming Introduction to Methods in Java.
1 Lecture 6: Input/Output (II) Introduction to Computer Science Spring 2006.
1 9/08/06CS150 Introduction to Computer Science 1 Arithmetic Operators.
1 Lecture 14:User-Definded function I Introduction to Computer Science Spring 2006.
Chapter 3: Input/Output
1 10/30/06CS150 Introduction to Computer Science 1 Functions Chapter 3, page 313.
B. RAMAMURTHY CH.4 IN KERNIGHAN AND RITCHIE C TEXTBOOK C Language: Functions 5/11/2013 Amrita-UB-MSES
Chapter 6: User-Defined Functions I Instructor: Mohammad Mojaddam
FUNCTIONS OVERVIEW.  In real life, we often find ourselves doing the same task over and over  Example: make toast and jam for breakfast in the morning.
Due Dates Quiz 1, 2 : Friday September 11 th Quiz 3 : Friday September 18 th Quiz 4 : Monday September 28 th Lab 1, 2 and 3 : Friday Sep 11 th Project.
Chapter 06 (Part I) Functions and an Introduction to Recursion.
Instructor - C. BoyleFall Semester
Programming in C++ Language ( ) Lecture 5: Functions-Part1 Dr. Lubna Badri.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
Chapter 6 User-Defined Functions I. Objectives Standard (predefined) functions What are they, and How to use them User-Defined Functions Value returning.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Functions Outline 5.1Introduction 5.2Program Modules.
1 10/18/04CS150 Introduction to Computer Science 1 Functions Divide and Conquer.
KIC/Computer Programming & Problem Solving 1.  Introduction  Program Modules in C  Math Library Functions  Functions  Function Definitions  Function.
Chapter 3: Input/Output
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
Simple Functions Writing Reuseable Formulas. Problem Using OCD, design and implement a program that computes the area and circumference of an Australian.
Functions Math library functions Function definition Function invocation Argument passing Scope of an variable Programming 1 DCT 1033.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
Chapter 8 Functions in Depth. Chapter 8 A programmer-defined function is a block of statements, or a subprogram, that is written to perform a specific.
Chapter 3: User-Defined Functions I
Chapter 3: Input/Output. Objectives In this chapter, you will: – Learn what a stream is and examine input and output streams – Explore how to read data.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
Chapter 05 (Part II) Control Statements: Part II.
CHAPTER 4 FUNCTIONS Dr. Shady Yehia Elmashad. Outline 1.Introduction 2.Program Components in C++ 3.Math Library Functions 4.Functions 5.Function Definitions.
Intro. to Computer Programming Eng. Nehal A. Mohamed Spring Semester-2016.
Chapter 3: Input/Output. Objectives In this chapter, you will: – Learn what a stream is and examine input and output streams – Explore how to read data.
TK1924 Program Design & Problem Solving Session 2011/2012
What Is? function predefined, programmer-defined
Chapter 6: User-Defined Functions I
Dr. Shady Yehia Elmashad
CMPT 201 Functions.
CSC113: Computer Programming (Theory = 03, Lab = 01)
Deitel- C:How to Program (5ed)
Writing Reuseable Formulas
Dr. Shady Yehia Elmashad
Math Library and IO formatting
User-defined Functions
Dr. Shady Yehia Elmashad
توابع در C++ قسمت اول اصول كامپيوتر 1.
Extra.
CSC1201: Programming Language 2
User Defined Functions
Chapter 5 Function Basics
User-defined Functions
Chapter 3: Input/Output
Formatting the Output The C++ standard library supplies many manipulators: endl, setw, fixed, showpoint, setprecesion. If we want to use endl, fixed, or.
Modular Programming with Functions
Chapter 6: User-Defined Functions I
Chapter 9: Value-Returning Functions
Functions Divide and Conquer
CS149D Elements of Computer Science
In C Programming Language
Fundamental Programming
Output Formatting Bina Ramamurthy 4/16/2019 BR.
Functions Imran Rashid CTO at ManiWeber Technologies.
Single-Result Functions & Modularity
What Is? function predefined, programmer-defined
Functions Divide and Conquer
Output Formatting Bina Ramamurthy 9/25/2019 BR.
Introduction to Methods and Interfaces
Presentation transcript:

Modular Programming with Functions B. Ramamurthy Chapter 7 12/5/2018 BR

Introduction Complex problems: Divide and conquer Reusability of code Modular design of software to enhance readability and maintenance. Abstraction Information hiding 12/5/2018 BR

Libraries of Functions We have used functions from many libraries: cmath : pow, sin, cos fstream : open, close, get, set iomanip: setw, setprecision iostream : << , >> Programmers can define functions for use in their program: programmer-defined functions. 12/5/2018 BR

Functions Definition Function header Function parameters Function body Function return value In fact main() is a function. int main() { … return 0; } 12/5/2018 BR

Function syntax type functioName (parameters) { declare local variables/constants statements } 12/5/2018 BR

Example int factorial (int n) { int prod =1; for (int i = 1; i <= n; i++) prod = prod *i; return prod; } 12/5/2018 BR

Example: drawRectangle ********* 12/5/2018 BR

Draw a small rectangle *** 12/5/2018 BR

Draw a large rectangle ********************** 12/5/2018 BR

drawRectangle(..) for (int i4 = 1; i4 <= length; i4++) { for (int k = 1; k<= offset; k++) cout<< ' '; for (int j = 1; j<= width; j++) cout <<'*'; cout<< endl; } 12/5/2018 BR

Function Parameters Write a function for rectangle code Parameterize the function: add length and width as parameters to the function Call/Invoke function with different parameters. 12/5/2018 BR

Summary Functions provide basic construct to modularize you solution. Practice writing functions. Read Chapter 7. 12/5/2018 BR