1 / 8

CSCI 3328 Object Oriented Programming in C# Chapter 6: Methods – Exercises

CSCI 3328 Object Oriented Programming in C# Chapter 6: Methods – Exercises. Xiang Lian The University of Texas – Pan American Edinburg, TX 78539 lianx@utpa.edu. Multiple Choices. A method is invoked with a(n) __________.

jcook
Download Presentation

CSCI 3328 Object Oriented Programming in C# Chapter 6: Methods – Exercises

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSCI 3328 Object Oriented Programming in C# Chapter 6: Methods – Exercises Xiang Lian The University of Texas – Pan American Edinburg, TX 78539 lianx@utpa.edu

  2. 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

  3. 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

  4. 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 p, 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.

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

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

  7. 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.

  8. 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, a1 and a2) • n-th number an, n >= 3, of this sequence is given by: an = an-1 + an-2

More Related