0% found this document useful (0 votes)
17 views4 pages

Computer Science Exam Answers

Uploaded by

lukemakunura2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views4 pages

Computer Science Exam Answers

Uploaded by

lukemakunura2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Computer Science Exam Answers

Binary Tree Representation and Programming (VB)

(a) Binary Tree Table


Exams(i) Data Left Pointer Right Pointer

Exams(0) 50 2 1

Exams(1) 60 -1 -1

Exams(2) 30 4 3

Exams(3) 45 -1 -1

Exams(4) 10 -1 -1

(b) VB Declarations

(i) Declare the Exams array:


Dim Exams(4) As Integer
Exams(0) = 50
Exams(1) = 60
Exams(2) = 30
Exams(3) = 45
Exams(4) = 10

(ii) Declare a 2D array STUDENTS:


Dim STUDENTS(3, 2) As String

(c) VB Code for Linear Search

Dim Exams(4) As Integer


Exams(0) = 50
Exams(1) = 60
Exams(2) = 30
Exams(3) = 45
Exams(4) = 10

Dim valueToFind As Integer


valueToFind = 19
Dim found As Boolean
found = False

For i = 0 To 4
If Exams(i) = valueToFind Then
found = True
Exit For
End If
Next

If found Then
MsgBox("Value has been Found")
Else
MsgBox("Value does not exist")
End If

Object-Oriented Programming (VB)

(i) Inheritance Diagram

Member
/ \
Junior Member Senior Member

(ii) VB Class Definition

Public Class Member


Private memberNumber As Integer
Private memberName As String
Private memberAddress As String

' Constructor
Public Sub New(ByVal num As Integer, ByVal name As String, ByVal address As String)
memberNumber = num
memberName = name
memberAddress = address
End Sub

' Show member details


Public Sub ShowDetails()
MsgBox("Number: " & memberNumber & vbCrLf & _
"Name: " & memberName & vbCrLf & _
"Address: " & memberAddress)
End Sub

' Amend details


Public Sub AmendDetails(Optional ByVal num As Integer = -1, _
Optional ByVal name As String = "", _
Optional ByVal address As String = "")
If num <> -1 Then memberNumber = num
If name <> "" Then memberName = name
If address <> "" Then memberAddress = address
End Sub
End Class

Database and SQL

(a) SQL to Create Tables

CREATE TABLE Examinations (


ExamID INT PRIMARY KEY,
Subject VARCHAR(50),
Date DATE
);

CREATE TABLE Results (


ResultNo INT PRIMARY KEY,
StudentNo VARCHAR(10),
ExamID INT,
Score INT
);

CREATE TABLE ExamAttenders (


StudentNo VARCHAR(10),
ExamID INT,
PRIMARY KEY (StudentNo, ExamID)
);

(b) SQL Queries

(i) Display all fields in examAttenders for StudentNo = 'R0013':


SELECT * FROM examAttenders WHERE StudentNo = 'R0013';

(ii) Delete Computer Science Paper 4:


DELETE FROM Examinations WHERE Subject = 'Computer Science Paper 4';

(iii) Add a duration field:


ALTER TABLE Examinations ADD Duration INT;

(iv) Update score for ResultNo = 138:


UPDATE Results SET Score = 95 WHERE ResultNo = 138;

(c) Key to Link Tables

Suggested Foreign Key: ExamID

ALTER TABLE Results ADD FOREIGN KEY (ExamID) REFERENCES Examinations(ExamID);

You might also like