visual basic

profileasheyk1
csc139_chapter_11_lab_assignment_fa2014.pdf

CSC139 Chapter 11 Lab Assignments

Objectives In this lab assignment, students will learn:

- How to define LINQ statement

- How to use LINQ to query data from object array

Goals

In this lab assignment, students will demonstrate the abilities to: - Define LINQ statement

- Use LINQ to query data from object array

Grading rubric

Category High Proficiency Medium Proficiency Low Proficiency

Define the

LINQ which

get all scores

in ascending

order [40 pts]

Successfully define

the LINQ which get

all scores in

ascending order.

[40ts]

LINQ statement

works, however,

does not generate

correct results. [20–

39 pts]

LINQ statement is

not defined correctly.

[0-19 pts]

Define the

LINQ which

get all students

who passed the

exam [40 pts]

Successfully define

the LINQ which get

all students who

passed the exam.

[40ts]

LINQ statement

works, however,

does not generate

correct results. [20-

39 pts]

LINQ statement is

not defined correctly.

[0-19 pts]

Define the

code to display

the LINQ

results

correctly (20

pts)

Successfully define

the code to display

the LINQ results

correctly. [20 pts]

The results can be

displayed, however,

some data or format

are not correct. [10-

19 pts]

Results can not be

displayed, or most

data or formats are

not correct. [0-9 pts]

1. Create a console application “LINQGradeBook” 2. Add the following class definition:

Public Class GradeBook

Private nameValue As String

Private scoreValue As Integer

Public Sub New(ByVal n As String, ByVal s As Integer)

nameValue = n

scoreValue = s

End Sub

Public Property Name() As String

Get

Return nameValue

End Get

Set(ByVal value As String)

nameValue = value

End Set

End Property

Public Property Score() As Integer

Get

Return scoreValue

End Get

Set(ByVal value As Integer)

scoreValue = value

End Set

End Property

Public Sub displayGradeBook()

Console.WriteLine("Name: " & Name & vbTab & "Score:

" & Score)

End Sub

End Class

3. Rename the file “Module1.vb” to “LINQGradeBookTester.vb” 4. Complete the missing code following the comments. You are required to create

two LINQ statements which will select specific gradeBook object from a

GradeBook objects array.

Option Strict On

Module LINQGradeBookTester

Sub Main()

Dim g1 As New GradeBook("AAA", 70)

Dim g2 As New GradeBook("BBB", 50)

Dim g3 As New GradeBook("CCC", 100)

Dim g4 As New GradeBook("DDD", 80)

'add g1, g2, g3 and g4 in a array and display all

student scores

Dim gradeBooks As GradeBook() = {g1, g2, g3, g4}

display(gradeBooks, "Scores for all students: ")

'create a LINQ which get all scores in ascending order and

display them.

'create a LINQ which get all students who passed

the exam

'display number of passed students, their names and

scores

End Sub

'display gradeBook's information

Private Sub display(ByVal gradeBooks As IEnumerable,

ByVal header As String)

Console.WriteLine(header)

For Each g As GradeBook In gradeBooks

g.displayGradeBook()

Next

Console.WriteLine()

End Sub

End Module

Here is output: (See next page)