Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Computer Certification > MCSD > 70-306 Question

Reply
Thread Tools

70-306 Question

 
 
Guest
Posts: n/a
 
      11-05-2003
This is a sample 70-306 question.

There are 2 textboxes textbox1, textbox2 and a button
called button1 on a form. The user enters values in the
textboxes which is a loan amount and number of years. On
clicking button1, the interest is calculated. The
following is the code to calculate interest on clicking
button1.

Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
Dim retvalue As Integer
Try
retvalue = validateloanamount()
If retvalue > 0 Then
MessageBox.Show("calculated succesfully")
End If
Catch ex As OverflowException
MessageBox.Show("Overflow exception")
Catch ex As ArithmeticException
MessageBox.Show("arithmatic exception")
End Try
End Sub

Function validateloanamount() As Integer
Return calculateinterest(CShort(TextBox1.Text),
CShort(TextBox2.Text))
MessageBox.Show("Rate calculated successfully")
End Function

Function calculateinterest(ByVal p As Short, ByVal n As
Short) As Integer

Dim interest As Integer
Dim r As Double
r = 5.6
interest = (p * n * r) / 100

If interest < 0 Then
MessageBox.Show("error while calculating interest")
Else
Return interest
End If
End Function

The question is : What is the output on execution if the
user enters 20000 as loan amount and 5 as years.

The options are
a)Rate calculated successfully
b)Calculated successfully
c)Overflow exception
d)arithmatic exception.

The answer is Overflow exception. Can someone explain why
this throws an overflow exception?

Thanks
H
 
Reply With Quote
 
 
 
 
Kline Sphere
Guest
Posts: n/a
 
      11-05-2003
It is to do with the fact that vb.net does not perform explicit
promotions. This highlights why 'option strict' should NOT be an
'option' at all!
 
Reply With Quote
 
 
 
 
someone
Guest
Posts: n/a
 
      11-07-2003

>-----Original Message-----
>This is a sample 70-306 question.
>
>There are 2 textboxes textbox1, textbox2 and a button
>called button1 on a form. The user enters values in the
>textboxes which is a loan amount and number of years. On
>clicking button1, the interest is calculated. The
>following is the code to calculate interest on clicking
>button1.
>
>Private Sub Button1_Click(ByVal sender As System.Object,
>ByVal e As System.EventArgs) Handles Button1.Click
> Dim retvalue As Integer
> Try
> retvalue = validateloanamount()
> If retvalue > 0 Then
> MessageBox.Show("calculated succesfully")
> End If
> Catch ex As OverflowException
> MessageBox.Show("Overflow exception")
> Catch ex As ArithmeticException
> MessageBox.Show("arithmatic exception")
> End Try
> End Sub
>
>Function validateloanamount() As Integer
> Return calculateinterest(CShort(TextBox1.Text),
> CShort(TextBox2.Text))
> MessageBox.Show("Rate calculated successfully")
>End Function
>
>Function calculateinterest(ByVal p As Short, ByVal n As
> Short) As Integer
>
> Dim interest As Integer
> Dim r As Double
> r = 5.6
> interest = (p * n * r) / 100
>
> If interest < 0 Then
> MessageBox.Show("error while calculating interest")
> Else
> Return interest
> End If
>End Function
>
>The question is : What is the output on execution if the
>user enters 20000 as loan amount and 5 as years.
>
>The options are
>a)Rate calculated successfully
>b)Calculated successfully
>c)Overflow exception
>d)arithmatic exception.
>
>The answer is Overflow exception. Can someone explain why
>this throws an overflow exception?
>
>Thanks
>H
>.
>

the overflow exception occurs in folowing line:
interest = (p * n * r) / 100
------
resume: it is too early for u to take the test
 
Reply With Quote
 
Guest
Posts: n/a
 
      11-12-2003
It's because p and n have been declared as Short. So when
they are multiplied together the answer should still
be 'Short'. However, this is not the case when p=20000
and n=5. Change the declaration of p to Integer and it
will work.
Here's another question for you on the same piece of
code. Which line of code will never be executed ?
Jez
>-----Original Message-----
>This is a sample 70-306 question.
>
>There are 2 textboxes textbox1, textbox2 and a button
>called button1 on a form. The user enters values in the
>textboxes which is a loan amount and number of years. On
>clicking button1, the interest is calculated. The
>following is the code to calculate interest on clicking
>button1.
>
>Private Sub Button1_Click(ByVal sender As System.Object,
>ByVal e As System.EventArgs) Handles Button1.Click
> Dim retvalue As Integer
> Try
> retvalue = validateloanamount()
> If retvalue > 0 Then
> MessageBox.Show("calculated succesfully")
> End If
> Catch ex As OverflowException
> MessageBox.Show("Overflow exception")
> Catch ex As ArithmeticException
> MessageBox.Show("arithmatic exception")
> End Try
> End Sub
>
>Function validateloanamount() As Integer
> Return calculateinterest(CShort(TextBox1.Text),
> CShort(TextBox2.Text))
> MessageBox.Show("Rate calculated successfully")
>End Function
>
>Function calculateinterest(ByVal p As Short, ByVal n As
> Short) As Integer
>
> Dim interest As Integer
> Dim r As Double
> r = 5.6
> interest = (p * n * r) / 100
>
> If interest < 0 Then
> MessageBox.Show("error while calculating interest")
> Else
> Return interest
> End If
>End Function
>
>The question is : What is the output on execution if the
>user enters 20000 as loan amount and 5 as years.
>
>The options are
>a)Rate calculated successfully
>b)Calculated successfully
>c)Overflow exception
>d)arithmatic exception.
>
>The answer is Overflow exception. Can someone explain

why
>this throws an overflow exception?
>
>Thanks
>H
>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
question row filter (more of sql query question) =?Utf-8?B?YW5kcmV3MDA3?= ASP .Net 2 10-06-2005 01:07 PM
Quick Question - Newby Question =?Utf-8?B?UnlhbiBTbWl0aA==?= ASP .Net 4 02-16-2005 11:59 AM
Question on Transcender Question :-) eddiec MCSE 6 05-20-2004 06:59 AM
Question re: features of the 831 router (also a 924 question) Wayne Cisco 0 03-02-2004 07:57 PM
Syntax Question - Novice Question sean ASP .Net 1 10-20-2003 12:18 PM



Advertisments