Functions Overview CSCE 121 J. Michael Moore

Slides:



Advertisements
Similar presentations
Modular Design Using Subroutines (functions later)
Advertisements

Chapter 4 Computation Bjarne Stroustrup
User-Defined Functions Like short programs Can operate on their own data Can receive data from callers and return data to callers.
Partitioning and Divide-and-Conquer Strategies Data partitioning (or Domain decomposition) Functional decomposition.
Unit 6 Assignment 2 Chris Boardley.
Overview of Programming and Problem Solving ROBERT REAVES.
CSCE 121: Introduction to Program Design and Concepts Dr. J. Michael Moore Spring 2015 Set 7: Errors 1 Based on slides created by Bjarne Stroustrup.
CSCE 121: Introduction to Program Design and Concepts Dr. J. Michael Moore Spring 2015 Set 5: Functions 1 Based on slides created by Bjarne Stroustrup.
Programming Logic and Design Fourth Edition, Introductory
ALGORITHMS THIRD YEAR BANHA UNIVERSITY FACULTY OF COMPUTERS AND INFORMATIC Lecture two Dr. Hamdy M. Mousa.
An Object-Oriented Approach to Programming Logic and Design
CSCE 121, Sec 200, 507, 508 Software Engineering Fall 2010 Prof. Jennifer L. Welch.
1 Chapter 1 Overview of Programming and Problem Solving Dale/Weems Slides based on work by Sylvia Sorkin, Community College of Baltimore County - Essex.
C Lecture Notes 1 Program Control (Cont...). C Lecture Notes 2 4.8The do / while Repetition Structure The do / while repetition structure –Similar to.
J. Michael Moore Software Design CSCE 110 Influenced by material developed by James Tam & Jennifer Welch.
J. Michael Moore Software Design CSCE 110 Influenced by material developed by James Tam & Jennifer Welch.
Understanding the Mainline Logical Flow Through a Program (continued)
Program Design Divide and Conquer –Divide the program into separate tasks Functional Decomposition Top-Down Design –Divide an overall problem into discrete.
 2003 Prentice Hall, Inc. All rights reserved Introduction Modules –Small pieces of a problem e.g., divide and conquer –Facilitate design, implementation,
1 Chapter 1 Overview of Programming and Problem Solving Dale/Weems Slides based on work by Sylvia Sorkin, Community College of Baltimore County - Essex.
Benefits of PL/SQL. 2 home back first prev next last What Will I Learn? In this lesson, you will learn to: –List and explain the benefits of PL/SQL –List.
1 Web-Enabled Decision Support Systems Objects and Procedures Don McLaughlin IE 423 Design of Decision Support Systems (304)
Program Design CMSC 201. Motivation We’ve talked a lot about certain ‘good habits’ we’d like you guys to get in while writing code. There are two main.
CSCE 121: Introduction to Program Design and Concepts, Honors Dr. J. Michael Moore Spring 2015 Set 3: Objects, Types, and Values 1 Based on slides.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 3 Simple.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design First Edition by Tony Gaddis.
Chapter 06 (Part I) Functions and an Introduction to Recursion.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 1. Introduction.
Introduction to Method. Example Java Method ( 1 ) The 2 types (kinds) of methods in Java Class methods Instance methods Methods can do more work than.
CSCE 121: Introduction to Program Design and Concepts Dr. J. Michael Moore Spring 2015 Set 4: Computation 1 Based on slides created by Bjarne Stroustrup.
CS Computer Science I. BCPL was developed in 1967 as a language for writing operating systems and software compilers In 1970, the creators of the.
Software Engineering and Object-Oriented Design Topics: Solutions Modules Key Programming Issues Development Methods Object-Oriented Principles.
FUNCTIONS. Topics Introduction to Functions Defining and Calling a Void Function Designing a Program to Use Functions Local Variables Passing Arguments.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
CSCE Introduction to Program Design and Concepts J. Michael Moore Spring 2015 Set 6: Miscellaneous 1 Based on slides created by Bjarne Stroustrup.
Lesson 06: Functions Class Participation: Class Chat:
Chapter 7: Function.
Computational Thinking, Problem-solving and Programming: General Principals IB Computer Science.
Exam #1 You will have exactly 30 Mins to complete the exam.
Programming Fundamentals Lecture #7 Functions
Function There are two types of Function User Defined Function
Understanding the Reasons for Structure
Starting Out with Programming Logic & Design
Programming Goals CSCE 121 J. Michael Moore.
Software Development Process
Anatomy of a Function Part 2
Chapter 3 Simple Functions
Introduction to the Standard Template Library
Program Flow CSCE 121 J. Michael Moore.
Generic Programming CSCE 121 J. Michael Moore.
IO Overview CSCE 121 J. Michael Moore
Manipulators CSCE 121 J. Michael Moore
MSIS 655 Advanced Business Applications Programming
Array & Pointers CSCE 121 J. Michael Moore.
Anatomy of Templates CSCE 121 J. Michael Moore
Anatomy of a Function Part 3
How Functions Work Part 1
Standard Template Library Find
Lesson 06: Functions Class Chat: Attendance: Participation
Unit 6 Assignment 2 Chris Boardley.
Programming Logic and Design Fourth Edition, Comprehensive
Standard Template Library Model
STL: Traversing a Vector
Topics Introduction to Functions Defining and Calling a 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.
Starting Out with Programming Logic & Design
Guidelines for Writing Functions
Modules, Subroutines, Procedures, Functions, or Methods
IO Overview CSCE 121 Strongly influenced by slides created by Bjarne Stroustrup and Jennifer Welch.
Presentation transcript:

Functions Overview CSCE 121 J. Michael Moore Strongly influenced by slides created by Bjarne Stroustrup and Jennifer Welch

Spaghetti Code Code can become cumbersome/long. What to do? Break it up into parts / subroutines A subroutine is a piece of code that accomplishes a task. When the task returns a value it is like a function. But not all subroutines need to return a value…

Functions (i.e. C++ Subroutines) A named sequence of statements Can return a result Standard library provides lots of functions We can write our own functions also

Recall Programming Goals Correctness Efficiency Robustness Readability Reuse Modularity

Benefits of Functions Correctness, Modularity Chop a program into manageable parts Divide and conquer Model problem domain Name logical operations A function should do one thing well Improves readability of program Can be useful in many places in program Avoid having to copy same code Ease testing, maintenance, division of labor Modularity, Robustness Readability Reuse, Correctness, Robustness Correctness, Robustness Zybooks: Reasons for defining functions…

Rules of Thumb Keep functions small (about one screen) Each function should do a single well-defined task Makes them easier to understand, specify, and debug