7 Methods: A Deeper Look.

Slides:



Advertisements
Similar presentations
Spring Semester 2013 Lecture 5
Advertisements

What have we learned so far… Preprocessor directives Introduction to C++ Variable Declaration Display Messages on Screen Get Information from User Performed.
 2006 Pearson Education, Inc. All rights reserved Methods: A Deeper Look.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
5 5 Arrays. OBJECTIVES In this lecture we will learn:  Case switch  To use the array data structure to represent a set of related data items.  To declare.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
 2006 Pearson Education, Inc. All rights reserved Arrays.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Introduction to C Programming
 Pearson Education, Inc. All rights reserved Arrays.
Dale Roberts Object Oriented Programming using Java - Class Constructors Dale Roberts, Lecturer Computer Science, IUPUI Department.
Programming Languages -1 (Introduction to C) arrays Instructor: M.Fatih AMASYALI
C++ for Engineers and Scientists Third Edition
CSCI 3327 Visual Basic Chapter 6: Methods: A Deeper Look UTPA – Fall 2011.
Chapter 6: Modularity Using Functions. In this chapter, you will learn about: – Function and parameter declarations – Returning a single value – Returning.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition, Fifth Edition Chapter 7: User-Defined Functions II.
 2005 Pearson Education, Inc. All rights reserved. 1 Methods Called functions or procedures in other languages Modularize programs by separating its tasks.
Dale Roberts Object Oriented Programming using Java - Enumerations Dale Roberts, Lecturer Computer Science, IUPUI Department.
 2005 Pearson Education, Inc. All rights reserved Methods: A Deeper Look.
Functions Modules in C++ are called functions and classes Functions are block of code separated from main() which do a certain task every C++ program must.
CPS120: Introduction to Computer Science Functions.
ECE122 Feb. 22, Any question on Vehicle sample code?
Reformatted slides from the textbook, C++ How to Program, 6/e Pearson Education, Inc. All rights reserved Chapter 3. [Lecture 02] Introduction to.
 2006 Pearson Education, Inc. All rights reserved Arrays.
More About Objects and Methods Chapter 5. Outline Programming with Methods Static Methods and Static Variables Designing Methods Overloading Constructors.
COMPUTER PROGRAMMING. Functions’ review What is a function? A function is a group of statements that is executed when it is called from some point of.
 2007 Pearson Education, Inc. All rights reserved C Structures, Unions, Bit Manipulations and Enumerations.
1 Chapter Four Creating and Using Classes. 2 Objectives Learn about class concepts How to create a class from which objects can be instantiated Learn.
 2006 Pearson Education, Inc. All rights reserved Classes and Objects: A Deeper Look.
Chapter 3 Part I. 3.1 Introduction Programs written in C ◦ All statements were located in function main Programs written in C++ ◦ Programs will consist.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
1 Brief Version of Starting Out with C++, 4th Brief Edition Chapter 6 Functions.
 2009 Pearson Education, Inc. All rights reserved Methods: A Deeper Look.
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
C++ Programming Lecture 13 Functions – Part V The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
Functions  A Function is a self contained block of one or more statements or a sub program which is designed for a particular task is called functions.
計算機程式語言 Lecture 03-1 國立台灣大學生物機電系 林達德 3 3 Introduction to Classes and Objects.
 2006 Pearson Education, Inc. All rights reserved Methods: A Deeper Look.
Lecture 4 – Function (Part 1) FTMK, UTeM – Sem /2014.
CHAPTER 07 Arrays and Vectors (part II). OBJECTIVES In this part you will learn:  To pass arrays to functions.  Basic searching techniques.
SEQUENTIAL AND OBJECT ORIENTED PROGRAMMING Arrays.
C++ Programming Lecture 13 Functions – Part V By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Introduction to Classes and Objects CS-2303, C-Term C++ Program Structure Typical C++ Programs consist of:– main –A function main –One or more classes.
Introduction to Classes and Objects
7 Methods: A Deeper Look.
7 Methods: A Deeper Look.
Polymorphism, Interfaces & Operator Overloading
Chapter 7: User-Defined Functions II
7 Methods: A Deeper Look.
Introduction to Classes and Objects
7 Methods: A Deeper Look [2014Q2-ME2008].
Introduction to C# Applications
Object Oriented Programming using Java - Class Instance Variables
6 Functions.
C++ for Engineers and Scientists Second Edition
Using local variable without initialization is an error.
C Structures, Unions, Bit Manipulations and Enumerations
7 Arrays.
Introduction to Classes and Objects
Object Oriented Programming in java
6 Methods: A Deeper Look.
7 Arrays.
Functions Imran Rashid CTO at ManiWeber Technologies.
Java Methods: A Deeper Look Academic 2019 Class: BIT23/BCS10 Chapter 06 Abdulaziz Yasin Nageye Faculty of Computing Java How to Program, 10/e 1 © Co py.
Introduction to Classes and Objects
Corresponds with Chapter 5
Classes and Objects Systems Programming.
C++ Object Oriented 1.
Presentation transcript:

7 Methods: A Deeper Look

Outline MaximumFinder.cs (1 of 2)

Outline MaximumFinder.cs (2 of 2)

Outline MaximumFinderTest. cs

Common Programming Error 7.4 Declaring a method outside the body of a class declaration or inside the body of another method is a syntax error.

Common Programming Error 7.5 Omitting the return type in a method declaration is a syntax error.

Common Programming Error 7.6 Placing a semicolon after the right parenthesis enclosing the parameter list of a method declaration is a syntax error.

Common Programming Error 7.7 Redeclaring a method parameter as a local variable in the method’s body is a compilation error.

Common Programming Error 7.8 Forgetting to return a value from a method that should return a value is a compilation error. If a return type other than void is specified, the method must contain a return statement that returns a value consistent with the method’s return type. Returning a value from a method whose return type has been declared void is a compilation error.

Fig. 7.6 | FCL namespaces (a subset) (Part 1 of 2).

Fig. 7.6 | FCL namespaces (a subset) (Part 2 of 2).

Good Programming Practice 7.2 The online .NET Framework documentation is easy to search and provides many details about each class. As you learn each class in this book, you should review the class in the online documentation for additional information.

Good Programming Practice 7.3 Use only uppercase letters in the names of constants. This makes the constants stand out in an application and reminds you that enumeration constants are not variables.

Good Programming Practice 7.4 Using enumeration constants (like Status.WON, Status.LOST and Status.CONTINUE) rather than literal integer values (such as 0, 1 and 2) can make code easier to read and maintain.

Error-Prevention Tip 7.3 Use different names for fields and local variables to help prevent subtle logic errors that occur when a method is called and a local variable of the method hides a field of the same name in the class.

Outline Scope.cs (1 of 2)

Outline Scope.cs (2 of 2)

Outline ScopeTest.cs

Outline MethodOverload.cs

Outline MethodOverload.cs

Outline MethodOverload.cs

Common Programming Error 7.10 Declaring overloaded methods with identical parameter lists is a compilation error regardless of whether the return types are different.

Outline ReferenceAndOutput Parameters.cs (1 of 2)

Outline ReferenceAndOutput Parameters.cs (2 of 2)

Outline ReferenceAndOutput ParamtersTest.cs

Common Programming Error 7.12 The ref and out arguments in a method call must match the parameters specified in the method declaration; otherwise, a compilation error occurs.

Software Engineering Observation 7.6 By default, C# does not allow you to choose whether to pass each argument by value or by reference. Value-types are passed by value. Objects are not passed to methods; rather, references to objects are passed to methods. The references themselves are passed by value. When a method receives a reference to an object, the method can manipulate the object directly, but the reference value cannot be changed to refer to a new object. In Section 8.8, you’ll see that references also can be passed by reference.