CSCI 3328 Object Oriented Programming in C# Chapter 6: Methods – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539

Slides:



Advertisements
Similar presentations
CPSC 388 – Compiler Design and Construction
Advertisements

CSCI 3328 Object Oriented Programming in C# Chapter 9: Classes and Objects: A Deeper Look 1 Xiang Lian The University of Texas – Pan American Edinburg,
Chapter 5 C Functions The best way to develop and maintain a large program is to divide it into several smaller program modules, each of which is more.
An Introduction to Programming with C++ Fifth Edition
© 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.
Chapter 3 Using Classes and Objects. 2 Creating Objects  A variable holds either a primitive type or a reference to an object  A class name can be used.
CSCI/CMPE 4341 Topic: Programming in Python Chapter 3: Control Structures (Part 1) – Exercises 1 Xiang Lian The University of Texas – Pan American Edinburg,
CSCI/CMPE 4341 Topic: Programming in Python Chapter 6: Lists, Tuples, and Dictionaries – Exercises Xiang Lian The University of Texas – Pan American Edinburg,
Methods Chapter 6. 2 Program Modules in Java What we call "functions" in C++ are called "methods" in Java Purpose Reuse code Modularize the program This.
Operator Precedence First the contents of all parentheses are evaluated beginning with the innermost set of parenthesis. Second all multiplications, divisions,
The University of Texas – Pan American
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. C How To Program - 4th edition Deitels Class 05 University.
 2007 Pearson Education, Inc. All rights reserved C Functions.
Chapter 12 Recursion, Complexity, and Searching and Sorting
 2005 Pearson Education, Inc. All rights reserved. 1 Methods Called functions or procedures in other languages Modularize programs by separating its tasks.
4-Methods Dr. John P. Abraham Professor UTPA. Common ways of packaging code Properties Methods Classes Namespaces (related classes are grouped into a.
Lecture 5 Methods. Sometimes we want to perform the same sequence of operations multiple times in a program. While loops allow us to do this, they are.
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley.
CSCI/CMPE 4341 Topic: Programming in Python Review: Exam I Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX.
CSCI 3328 Object Oriented Programming in C# Chapter 6: Methods 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
A FIRST BOOK OF C++ CHAPTER 6 MODULARITY USING FUNCTIONS.
Chapter 6: Repetition Continued. 2 Validity Checks What’s weak about the following code ? do { s1 = JOptionPane.showInputDialog (“Enter a number: ”);
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
CSCI 3328 Object Oriented Programming in C# Chapter 9: Classes and Objects: A Deeper Look – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley.
CSCI 3328 Object Oriented Programming in C# Chapter 8: LINQ and Generic Collections – Exercises 1 Xiang Lian The University of Texas – Pan American Edinburg,
CSCI 3328 Object Oriented Programming in C# Chapter 12: Databases and LINQ – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg,
5.3 EVALUATION OF POSTFIX EXPRESSION For example, consider the evaluation of the following postfix expression using stacks: abc+d*f/- where, a=6, b=3,
CSCI 4333 Database Design and Implementation – Exercise (1) Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley.
Recursion Chapter What is recursion? Recursion occurs when a method calls itself, either directly or indirectly. Used to solve difficult, repetitive.
CSCI/CMPE 4341 Topic: Programming in Python Chapter 7: Introduction to Object- Oriented Programming in Python – Exercises Xiang Lian The University of.
CSCI/CMPE 4341 Topic: Programming in Python Chapter 5: Functions – Exercises Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
Methods Chapter 6.
Chapter 5 Functions DDC 2133 Programming II.
CSCI 3328 Object Oriented Programming in C# Review: Final Exam
The University of Texas – Pan American
The University of Texas Rio Grande Valley
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays
The University of Texas Rio Grande Valley
The University of Texas – Pan American
The University of Texas – Pan American
Chapter 6 Methods: A Deeper Look
MSIS 655 Advanced Business Applications Programming
CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I – Exercises UTPA – Fall 2012 This set of slides is revised from lecture.
CSCI 3328 Object Oriented Programming in C# Review: Exam I
CSCI 3328 Object Oriented Programming in C# Chapter 9: Classes and Objects: A Deeper Look – Exercises UTPA – Fall 2012 This set of slides is revised from.
The University of Texas – Pan American
The University of Texas – Pan American
CSCI 3328 Object Oriented Programming in C# Review: Exam I
The University of Texas Rio Grande Valley
CSCI 3328 Object Oriented Programming in C# Review: Exam II
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II – Exercises UTPA – Fall 2012 This set of slides is revised from.
The University of Texas – Pan American
CSCI 3328 Object Oriented Programming in C# Chapter 3: Introduction to Classes and Objects – Exercises UTPA – Fall 2012 This set of slides is revised.
Unit 3 Test: Friday.
The University of Texas – Pan American
CSCI 6307 Foundation of Systems – Exercise (1)
CSCI 3328 Object Oriented Programming in C# Review: Exam II
CSCI 3328 Object Oriented Programming in C# Review: Final Exam
The University of Texas – Pan American
CSCI 3328 Object Oriented Programming in C# Chapter 6: Methods
Chapter 9: Value-Returning Functions
CSCI 3328 Object Oriented Programming in C# Review: Final Exam
CSCI 3328 Object Oriented Programming in C# Chapter 8: LINQ and Generic Collections – Exercises UTPA – Fall 2012 This set of slides is revised from lecture.
Corresponds with Chapter 5
CSCI 3328 Object Oriented Programming in C# Review: Exam II
CSCI 6307 Foundation of Systems – Exercise (5)
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays – Exercises UTPA – Fall 2012 This set of slides is revised from lecture slides of Prof.
Presentation transcript:

CSCI 3328 Object Oriented Programming in C# Chapter 6: Methods – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX

Multiple Choices A method is invoked with a(n) __________. – A. method call B. method declaration C. class declaration D. class call A variable known only within the method in which it is declared is called a(n)__________. – A. global variable B. local variable C. random variable D. private variable The statement of _______ in a called method can be used to pass the value of an expression back to the calling method. – A. assigning value to parameters passing by values B. break C. return D. continue The keyword ________ indicates that a method does not return a value. – A. return B. public C. private D. void Data can be added to or removed from the ______ of a stack. – A. bottom B. top C. middle D. random position 2

Multiple Choices (cont'd) An object of class ______ produces pseudorandom numbers. – A. Math B. randomNum C. Random D. randomNumber Assuming randomNumbers is an object for generating pseudorandom numbers, which of the following statements generates a random number between 1 and 4 (inclusive)? – A. randomNumbers.Next(4)+1; – B. randomNumbers.Next(0, 5); – C. randomNumbers.Next(1, 4); – D. randomNumbers.Next(); A method that calls itself either directly or indirectly is a(n) __________method. – A. static B. dynamic C. public D. recursive 3

True/False Statements The following two methods can exist in the same class: – void Method1(int x, float y); – int Method1(int x, float y); If we want to use the constant , we can write Math.pi in the C# program. It holds that method Math.Floor(4.5) returns value 4. It holds that method Math.Ceiling(4.0) returns value 4. 4

Debugging Errors int G() { Console.WriteLine("Inside method G"); void H() { Console.WriteLine("Inside method H"); } 5

Debugging Errors (cont'd) void F(float a) { float a; Console.WriteLine(a); return a; } int G(int x) { return x*G(x-1); } 6

Write a Program Write a method in C# to return the larger value of two decimal numbers. Write another program in C# to return the largest value among 3 decimal numbers, by invoking the method above. 7

Write a Program (cont'd) Write a recursive method in C# to compute the Fibonacci number: – 1, 1, 2, 3, 5, 8, 13, 21, 34,.... – Given the first two numbers of the sequence (say, a 1 and a 2 ) – n-th number a n, n >= 3, of this sequence is given by: a n = a n-1 + a n-2 8