30.07.2013 Views

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

238 Procedures Chapter 6<br />

b) Math method Exp is the exponential method that calculates e x .<br />

c) A recursive procedure is one that calls itself.<br />

d) Conversion from type Single <strong>to</strong> type Double requires a widening conversion.<br />

e) Variable type Char cannot be converted <strong>to</strong> type Integer.<br />

f) When a procedure recursively calls itself, it is known as the base case.<br />

g) Forgetting <strong>to</strong> return a value from a recursive procedure when one is needed results in a<br />

logic error.<br />

h) Infinite recursion occurs when a procedure converges on the base case.<br />

i) <strong>Visual</strong> <strong>Basic</strong> supports Optional arguments.<br />

j) Any problem that can be solved recursively also can be solved iteratively.<br />

6.3 For the program in Fig. 6.27, state the scope (either class scope or block scope) of each of the<br />

following elements:<br />

a) The variable i.<br />

b) The variable base.<br />

c) The method Cube.<br />

d) The method FrmCubeTest_Load.<br />

e) The variable output.<br />

6.4 Write an application that tests whether the examples of the Math class method calls shown<br />

in Fig. 6.7 actually produce the indicated results.<br />

6.5 Give the procedure header for each of the following:<br />

a) Procedure Hypotenuse, which takes two double-precision, floating-point arguments,<br />

side1 and side2, and returns a double-precision, floating-point result.<br />

b) Procedure Smallest, which takes three integers, x, y and z, and returns an integer.<br />

c) Procedure Instructions, which does not take any arguments and does not return a<br />

value.<br />

d) Procedure IntegerToSingle, which takes an integer argument, number, and returns<br />

a floating-point result.<br />

6.6 Find the error in each of the following program segments and explain how the error can be<br />

corrected:<br />

1 ' Fig. 6.27: CubeTest.vb<br />

2 ' Printing the cubes of 1-10.<br />

3<br />

4 Public Class FrmCubeTest<br />

5 Inherits System.Windows.Forms.Form<br />

6<br />

7 Friend WithEvents lblOutput As Label<br />

8<br />

9 ' <strong>Visual</strong> Studio .<strong>NET</strong> generated code<br />

10<br />

11 Dim i As Integer<br />

12<br />

13 Private Sub FrmCubeTest_Load(ByVal sender As System.Object, _<br />

14 ByVal e As System.EventArgs) Handles MyBase.Load<br />

15<br />

16 Dim output As String = ""<br />

17<br />

Fig. Fig. 6.27 6.27 Printing the results of cubing 10 numbers (part 1 of 2).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!