4. Task 1.1
'1 - Declaration of array to hold student records
Dim clsRecords(30) As String
Dim i As Integer
For i = 0 to 29
clsRecords(i) = "---"
Next
'4 and 5 - Writing record to the array
'nextElement - Acts as a pointer for accessing next blocks in the array
'cond - Gives choice to the user whether to continue or quit
Dim nextElement As Integer = 0
Dim cond As String
Do
'2 - User Prompts
Dim name As String
Dim email As String
Console.WriteLine("Enter name: ")
name = Console.ReadLine()
Console.WriteLine("Enter email: ")
email = Console.ReadLine()
'3 - Formatting of string as per the requirement
Dim record As String = name & "#" & email
'Record is getting written to the array
clsRecords(nextElement) = record
nextElement = nextElement + 1
'User prompt for either continuing to add record or stop
Console.WriteLine("Any key to continue, S - stop: ")
cond = Console.ReadLine()
Loop Until cond = "S" or nextElement = 29
'6 - Output
Console.WriteLine("Student Name#Email Address")
Console.WriteLine("--------------------------")
For i = 0 to 29
Console.WriteLine(clsRecords(i))
Next
1
5. Task 1.2
Console.WriteLine("Student Name#Email Address")
Console.WriteLine("--------------------------")
For i = 0 to 29
'Task 1.2 - To display only the current records
If clsRecords(i) <> "---" Then
Console.WriteLine(clsRecords(i))
End If
Next
Task 1.3
'Task 1.3 Searching a record and display its corresponding email
'Conditional variable that will determine whether user wants to keep
'searching or quit the loop
Dim cond1 As String
Do
'Prompt to ask name of the student
Dim name1 As String
Console.WriteLine("Enter name: ")
name1 = Console.ReadLine()
Console.WriteLine("Student Name#Email Address")
Console.WriteLine("--------------------------")
For i = 0 to 29
If clsRecords(i) <> "---" Then
'If name in the record equals name entered, email will be
'displayed
If clsRecords(i).Substring(0, name1.length) = name1 Then
Console.WriteLine(clsRecords(i).Substring(name1.length +1))
End If
End If
Next
'Prompt whether to search for student name again or stop searching
Console.WriteLine("Any key to continue searching, S - Stop")
cond1 = Console.ReadLine()
Loop Until cond1 = "S"
2
6. Task 1.4
'Task 1.4 Searching a record by inputting full or part of the name and
'display the records
'Conditional variable that will determine whether user wants to keep
'searching or quit the loop
Dim cond1 As String
Do
Dim name1 As String
Console.WriteLine("Enter name: ")
name1 = Console.ReadLine()
'Flag variable to indicate whether full or part of name is found
'In a record
Dim flag As Boolean = False
Console.WriteLine("Student Name#Email Address")
Console.WriteLine("--------------------------")
For i = 0 to 29
If clsRecords(i) <> "---" Then
'IndexOf method allows to search full name or part of the name
'Within the contagious records in the array.
'If record(s) found, flag variable is set to True.
If clsRecords(i).IndexOf(name1) <> -1 Then
Console.WriteLine(clsRecords(i))
flag = True
End If
End If
Next
'If no records found, flag not be set to True and will remain False.
'This will indicate no record is found in the array.
If flag = False
Console.WriteLine("No Record found!")
End If
'Prompt whether to search for student name again or stop searching
Console.WriteLine("Any key to continue searching, S - Stop")
cond1 = Console.ReadLine()
Loop Until cond1 = "S"
3
7. Task 1.5 and Task 1.6 - Repeating Tasks 1.1 - 1.4 using 2D array
Task 1.1
'1 - Declaration of 2D Arrays to hold student records
Dim clsRecords(30,4) As String
Dim row, col As Integer
'For accessing inner arrays or rows
For row = 0 to 29
'For accessing elements by each column
For col = 0 to 3
'Each empty block in the array will be represented by “---”
clsRecords(row, col) = "---"
Next
Next
'4 and 5 - Writing all of the details to the empty blocks of array
'nexetRecord - Acts as a pointer for accessing next row. Each row is responsible to
'hold details of a student
'cond - Gives choice to the user whether to continue or quit
Dim nextRecord As Integer
Dim cond As String
Do
'2 - User prompts
Dim name As String
Dim email As String
Dim dob As String
Dim studentID As String
Console.Writeline("Enter name: ")
name = Console.Readline()
Console.Writeline("Enter email: ")
email = Console.Readline()
Console.Writeline("Enter date of birth: ")
dob = Console.Readline()
Console.Writeline("Enter student ID: ")
studentID = Console.Readline()
'3 - All the details of a student are getting added in each of the blocks
'of the inner array
'Name of the student is stored in the first block of the row
clsRecords(nextRecord, 0) = name
4
8. 'Email address of the student is stored in the second block
clsRecords(nextRecord, 1) = email
'Date of birth of the student is stored in the third block
clsRecords(nextRecord, 2) = dob
'StudentID of the student is stored in the fourth block
clsRecords(nextRecord, 3) = studentID
'Pointer is updated to move to the next row
nextRecord = nextRecord + 1
'User prompt for either continuing to add record or stop
Console.Writeline("Any key to continue, S - stop: ")
cond = Console.Readline()
Loop Until cond = "S" or cond = "s" or nextRecord = 29
'6 - Output
Console.Writeline("Student Name#Email Address#Date of Birth#Student ID")
Console.Writeline("---------------------------------------------------")
For row = 0 to 29
For col = 0 to 3
'To display elements of a row in same line followed by a separator - “#”
Console.Write(clsRecords(row, col) & "#")
Next
'Once all details of a student is displayed, we move to the next line for
'Displaying the record of another student
Console.Writeline()
Next
Task 1.2
Console.Writeline("Student Name#Email Address#Date of Birth#Student ID")
Console.Writeline("---------------------------------------------------")
'flag variable - To allow moving to the next line only if a record is found
'This will prevent printing unnecessary blank lines.
Dim flag As Boolean = False
For row = 0 to 29
For col = 0 to 3
'To prevent printing empty slots in the console. Each elements or cells
'are checked if the slot is empty.
If clsRecords(row, col) <> "---" Then
Console.Write(clsRecords(row, col) & "#")
'After record of a student is displayed, flag is set to true
flag = True
End If
5
9. Next
'flag = True represents the record of a student is detected and will only
'allow moving to the next line after record of a student is displayed.
'After moving to next line, flag is then again set to False so that if row of
'are not detected, flag will remain False, and we then do not move to the next
'line.
If flag = True Then
Console.Writeline()
flag = False
End If
Next
Task 1.3
'Conditional variable that will determine whether user wants to keep
'searching or quit the loop
Dim cond1 As String
Do
'Prompt to ask name of the student
Dim name1 As String
Console.Writeline("Enter name: ")
name1 = Console.Readline()
'Column headers
Console.Writeline("StudentName#EmailAddress#DateofBirth#StudentID")
Console.Writeline("----------------------------------------------")
Dim row1, col1 As Integer
Dim flag1 As Boolean = False
For row1 = 0 to 29
For col1 = 0 to 3
If clsRecords(row1, col1) <> "---" Then
'First cell of the row is checked if it equals the name
'that is entered by the user.
'If True, next line is executed and email is displayed of
'the respective student of whose name was entered.
If clsRecords(row1, 0) = name1 Then
Console.Writeline(clsRecords(row1,1))
flag1 = True
'Once email address is displayed, it is necessary to
'exit the inner loop as it will repeat itself, and then
'more than once, same email will be displayed as we
'explicitly pass number 1 to access the second column.
exit for
End if
6
10. End If
Next
If flag1 = True Then
Console.Writeline()
flag1 = False
End if
Next
Console.Writeline("Any key to continue, S - stop: ")
cond1 = Console.Readline()
Loop Until cond1 = "S" or cond1 = "s"
Task 1.4
Dim cond1 As String
Do
Dim name1 As String
Console.Writeline("Enter name: ")
name1 = Console.Readline()
'Column headers
Console.Writeline("StudentName#EmailAddress#DateofBirth#StudentID")
Console.Writeline("----------------------------------------------")
Dim row1, col1 As Integer
Dim flag1 As Boolean = False
For row1 = 0 to 29
For col1 = 0 to 3
If clsRecords(row1, col1) <> "---" Then
'If full name includes part of the name, then record(s)
'Of those students will be displayed.
If clsRecords(row1, 0).IndexOf(name1) <> -1 Then
Console.Write(clsRecords(row1, col1) & "#")
flag1 = True
'Here we don’t need to exit loop in advance as col1
'variable gets incremented at the end of the loop which
'will then allow us to access all of the elements of
'inner row(s) and therefore display details of
'student(s)
End if
End If
Next
If flag1 = True Then
Console.Writeline()
flag1 = False
End if
7