CT243 lab8
http://geminga.it.nuigalway.ie/~gettrick/courses/CT243/labs/l8.html
-
For this lab you must submit
-
Handwritten development notes, including statement of the problem, analysis of the problem, algorithm design (which may include flow charts).
-
A printout of form, image and code of your program, and any numerical answers requested.
-
The above material should be given to David or left in the cardboard box marked CT243 in the mail room (room IT415) on the 4th floor of the IT Building
before
the deadline of 5pm
Monday 7th April 2008. You will lose 20% for each day
(or part of day) the lab is late.
In this lab we look at various overloaded functions in VB .NET,
using a Console Application and command line parameters.
Open up VB .NET (visual studio) and select under New Project
"Console Application". As in the previous lab, start with
Sub Main(ByVal args As String())
so that your Console Application will read command-line
parameters. The overloaded function we will write is called
add()
and the different versions of it will have signatures
-
<Integer, Integer>
-
<Double, Integer>
-
<Double, Double>
-
<Integer, Integer, Double>
-
<Double, Integer, Double>
For each function
add()
make sure the function returns a different answer (it need not really
add numbers!), e.g. if the input is i, j, k, for (1.) return
i + j + 1
for (2.) return
i + j + 2
for (3.) return
i + j + 3
for (4.) return
i + j + k + 1
for (5.) return
i + j + k + 2
In your
main()
program, you can call the functions using lines like
Console.WriteLine(add(CInt(args(0)), CInt(args(1))))
Console.WriteLine(add(CDbl(args(0)), CInt(args(1))))
Console.WriteLine(add(CInt(args(0)), CInt(args(1)), CInt(args(2))))
You should pass the three (3) numbers 3.0 4.0 5.0 as command line arguments
to your program. (Note here that args(0), args(1) etc. are ALWAYS strings:
we use the methods CInt() (convert to integer), CDbl() (convert to double)
etc. to do the conversions.)
-
What happens if you call
add()
using
Console.WriteLine(add(CInt(args(0)), CDbl(args(1))))
given that there is no
add()
matching this signature?
-
What about
Console.WriteLine(add(CInt(args(0)), CInt(args(1)), CInt(args(2))))
? (i.e. explain which one of the add() functions 1., 2., 3., 4., or
5. above is called & explain why)
-
What about
Console.WriteLine(add(CDbl(args(0)), CInt(args(1)), CInt(args(2)))
?
-
Write another function
Function add(Optional ByVal k As Double = 0.0)
which takes an OPTIONAL parameter (k) and just returns the value of k.
-
What happens if you
call this function from your main program using
Console.WriteLine(add(CDbl(args(0))))
?
-
What happens if you
call this function from your main program using no parameters
Console.WriteLine(add())
?
-
Can you write a function
Function add(ByVal i As Double, Optional ByVal k As Double = 0.0)
along with the other add() functions you have written? Why does the
compiler complain?
©
NUI, Galway