1.9 Methods academy.zariba.com 1. Lecture Content 1.What is a method? Why use methods? 2.Void Methods and methods with parameters 3.Methods which return.

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

CSE 1301 Lecture 6B More Repetition Figures from Lewis, “C# Software Solutions”, Addison Wesley Briana B. Morrison.
Introduction to Computers and Programming Lecture 11: Introduction to Methods Professor: Evan Korth New York University.
1 11/05/07CS150 Introduction to Computer Science 1 Functions Chapter 6, page 303.
C Lecture Notes 1 Program Control (Cont...). C Lecture Notes 2 4.8The do / while Repetition Structure The do / while repetition structure –Similar to.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
 2007 Pearson Education, Inc. All rights reserved C Functions.
 2007 Pearson Education, Inc. All rights reserved C Functions.
2.3 Cool features in C# academy.zariba.com 1. Lecture Content 1.Extension Methods 2.Anonymous Types 3.Delegates 4.Action and Func 5.Events 6.Lambda Expressions.
1.10 Strings academy.zariba.com 1. Lecture Content 1.What is a string? 2.Creating and Using strings 3.Manipulating Strings 4.Other String Operations 5.Building.
Subroutines in Computer Programming Svetlin Nakov Telerik Corporation
Subroutines in Computer Programming Svetlin Nakov Telerik Corporation
Reusable parts of Code Doncho Minkov Telerik Software Academy academy.telerik.com Technical Trainer
Lecture Set 5 Control Structures Part D - Repetition with Loops.
Modular Programming. Modular Programming (1/6) Modular programming  Goes hand-in-hand with stepwise refinement and incremental development  Makes the.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. C How To Program - 4th edition Deitels Class 05 University.
1.6 Loops academy.zariba.com 1. Lecture Content 1.While loops 2.Do-While loops 3.For loops 4.Foreach loops 5.Loop operators – break, continue 6.Nested.
1.3 Console Input And Output academy.zariba.com 1.
BUILDING JAVA PROGRAMS CHAPTER 7 Arrays. Exam #2: Chapters 1-6 Thursday Dec. 4th.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
Introduction to Computers and Programming Lecture 14: User defined methods (cont) Professor: Evan Korth New York University.
Functions Reusable Parts of Code SoftUni Team Technical Trainers Software University
Procedural programming in Java Methods, parameters and return values.
1.5 Conditional Statements academy.zariba.com 1. Lecture Content 1.If-else statements 2.If-else-if statements 3.Switch-case statements 2.
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
© 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.
KIC/Computer Programming & Problem Solving 1.  Introduction  Program Modules in C  Math Library Functions  Functions  Function Definitions  Function.
1 Structure of a C Program (continued) Presentation original from Dr. Turner’s class USF - COP C for Engineers Summer 2008.
TMC1414/TMC1413 I NTRODUCTION T O P ROGRAMMING Lecture 06 Function.
Arrays. The array data structure Array is a collection of elements, that have the same data type Integers (int) Floating point numbers (float, double)
Lecture 5 functions 1 © by Pearson Education, Inc. All Rights Reserved.
Functions. What is a function? It’s a group of statements that has a specific purpose and can be be repeatedly executed as needed. By using functions:
 2000 Prentice Hall, Inc. All rights reserved. 5.2Program Modules in C Functions –Modules in C –Programs combine user-defined functions with library functions.
1.2 Primitive Data Types and Variables
Functions Structured Programming. Topics to be covered Introduction to Functions Defining a function Calling a function Arguments, local variables and.
Reusable parts of Code Doncho Minkov Telerik Software Academy academy.telerik.com Technical Trainer
CSCI 161 Lecture 14 Martin van Bommel. New Structure Recall “average.cpp” program –Read in a list of numbers –Count them and sum them up –Calculate the.
Programming Constructs Notes Software Design & Development: Computational Constructs, Data Types & Structures, Algorithm Specification.
CPSC 233 Tutorial 5 February 9 th /10 th, Java Classes Each Java class contains a set of instance variables and methods Instance Variables: Type.
1.8 Multidimensional Arrays academy.zariba.com 1.
Dale Roberts CSCI N305 Functions Declarations Department of Computer and Information Science, School of Science, IUPUI.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
CSE 251 Dr. Charles B. Owen Programming in C1 Pointers and Reference parameters.
Getting Started With Python Brendan Routledge
Functions + Overloading + Scope
Chapter 9: Value-Returning Functions
Functions and Procedures
C++ Basic Syntax – Homework Exercises
2.2 Defining Classes Part 2 academy.zariba.com.
JavaScript OOP academy.zariba.com.
Functions CIS 40 – Introduction to Programming in Python
Subroutines in Computer Programming
Lecture 07 More Repetition Richard Gesick.
Functions.
Chapter 5 - Functions Outline 5.1 Introduction
Functions Declarations CSCI 230
Functions and Procedures
CSCE 206 Lab Structured Programming in C
CS285 Introduction - Visual Basic
CS2011 Introduction to Programming I Methods (I)
Week 4 Lecture-2 Chapter 6 (Methods).
Methods.
The structure of programming
Introduction to Programming
Introduction to Programming
CSCE 206 Lab Structured Programming in C
CPS125.
Presentation transcript:

1.9 Methods academy.zariba.com 1

Lecture Content 1.What is a method? Why use methods? 2.Void Methods and methods with parameters 3.Methods which return a value 4.Overloading 5.Best Practices 2

1. What is a method? 3 A method is a building block that solves a single problem. It combines a part of your code, gives it a name and can be called from other parts of the code. Methods are key for constructing large applications and games from smaller pieces Methods are also known in other languages as functions, procedures and subroutines.

1. Why use methods? 4 They split large problems into small pieces Better organization Improve readability Improve understandability Avoid repetition of code Code reusability

2. Void methods and parameters 5 Each method has a return type, name, parameters (optional) and body. Void methods don’t have return type. They just wrap a piece of code and give it a name.

3. Methods which return a value 6

4. Overloading 7

5. Best practices 8 Each method should perform a single well- defined task. The method’s name should clear and descriptive of the task it performs. Neither too long, nor too short e.g. DrawDwarf(), GenerateRocks(), MovePaddle()… bad e.g. Process(), Task(), DoSomething(), f(), function()

Homework 9 1.Write a method that asks the user for his name and prints “Hello, ” (for example, “Hello, Peter!”). Write a program to test this method. 2.Write a method that counts how many times given number appears in given array. Write a test program to check if the method is working correctly. 3.Write a method that reverses the digits of given decimal number. Example: 256  Write methods to calculate minimum, maximum, average, sum and product of given set of integer numbers. Use variable number of arguments. 5.Modify your last program and try to make it work for any number type, not just integer (e.g. decimal, float, byte, etc.). Use generic method (read in Internet about generic methods in C#).

10 References

11 Zariba Academy Questions