Question:
Delegates Assignment ....VB.NET?
2012-07-28 20:45:45 UTC
Delegates Assignment
60 Points (20 points each)

1) Write a program using various procedures to perform the operations listed below. Call these procedures using delegates. Make sure to document your program and have the program print descriptive text along with the numbers in b. and c.
a) Print a text string in reverse word order.
b) Print the number of characters in the string.
c) Print number of words in the string.
2) Write a program that has a class shapes. SquareArea() and RectangleArea() are the two methods that calculates the area of a square and rectangle respectively. Create a delegate named Area, invoke the methods with the help of delegates and add the results produced by both the methods.
3) Write a program using various procedures listed below to perform the operations listed below. Call these procedures using delegates.
a) Print 1 to N odd numbers
b) Print 1 to N even numbers
c) Print 1 to N prime numbers
d) Print 1 to N even numbers which are exactly divisible by 4


Any help with this would be appreciated =]
Four answers:
Jonathan
2012-07-29 02:57:05 UTC
I'll give you some of it. Question (3), for example. In this case I'll write some of it a little more generically, but then just focus on integers as probably required by (3). Hope this makes sense to you:



    Delegate Function isvalid(Of T)(item As T) As Boolean

    Delegate Function makelist(Of T)(count As Integer) As List(Of T)

    Function factor(n As Integer) As Integer

        Dim q As Integer, sqrtn As Integer

        If n < 2 Then Return n - 1

        If n = 3 Then Return n

        If n Mod 2 = 0 Then Return 2

        sqrtn = CInt(System.Math.Sqrt(n))

        For q = 3 To sqrtn Step 2

            If n Mod q = 0 Then Return q

        Next

        Return n

    End Function

    Sub PrintList(Of T)(items As List(Of T), printtest As isvalid(Of T))

        For Each p As T In items

            If printtest(p) Then

                Console.WriteLine(p)

            End If

        Next

    End Sub

    Sub Main()

        Const N as Integer = 100

        Dim intlist As makelist(Of Integer) = Function(n As Integer) As List(Of Integer)

                                                    Dim i As Integer

                                                    Dim a As New List(Of Integer)

                                                    For i = 0 To n - 1

                                                        a.Add(i + 1)

                                                    Next

                                                    Return a

                                                End Function

        PrintList(intlist(N), Function(a) a Mod 2 = 1) ' Print odd

        PrintList(intlist(N), Function(a) a Mod 2 = 0) ' Print even

        PrintList(intlist(N), Function(a) factor(a) = a) ' Print prime

        PrintList(intlist(N), Function(a) a Mod 4 = 0) ' Print divisible by 4

    End Sub



The MSDN link given by Gardner is a TERRIBLE link for understanding delegates and the example code given is nearly as useless.
?
2016-10-14 10:39:14 UTC
i presumed that the branch of delegates based on the share of victory in each and every contest must be extra effective. I dont know how human beings choose caucuses or primaries yet to make it truthful, i might say do a lottery to be certain who does which. Then there is not any 'automated' earnings or disadvantage. As for those date leaping states...i might say, if the democratic management had a hand interior the exchange (like the FL individuals who voted unanimously to pass up their date) then they go through like they did this 12 months. i might additionally make valuable that there grow to be uniformity because it on the subject count of the applicants. If the state doesnt count quantity then no names on the pollperiod. then you definitely dont have somebody asserting "I won vs uncommitted. "
Gardner
2012-07-28 20:59:31 UTC
I will not do your homework for you however I will point you to this



http://msdn.microsoft.com/en-us/library/system.delegate.aspx



Which explains a delegate, how it works, and has a good example program at the bottom of the page.
Noah
2012-07-28 22:00:18 UTC
10 PRINT "Do your own homework."

20 GOTO 10


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Loading...