0% found this document useful (0 votes)
23 views7 pages

2024 APDB101 MajorTheoryTest2 QuestionPaper

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

2024 APDB101 MajorTheoryTest2 QuestionPaper

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

FACULTY OF ACCOUNTING AND INFORMATICS

Department of Information Technology

Major Theory Test 2


INSTRUCTIONAL PROGRAMME(S): DIPLOMA IN ICT IN APPLICATIONS DEVELOPMENT
(DIIAD1)
DIPLOMA IN ICT IN BUSINESS ANALYSIS (DIIBA1)
DIPLOMA IN ICT IN APPLICATIONS DEVELOPMENT 4-
YEAR (DIIAF1)
INSTRUCTIONAL OFFERING: APPLICATIONS DEVELOPMENT 1B
SUBJECT CODE: APDB101
DATE: 12 SEPTEMBER 2024
DURATION: 90 MINUTES
TIME: 14:00-15:30
TOTAL MARKS: 50 MARKS
EXAMINER: MISS Z. MAGUBANE
MODERATOR: MR. B NGXATA, MRS. J DWARIKA, MR. G MOHAMED

INSTRUCTIONS:

1. Answer all questions on the answer sheet provided


2. Begin answering on the first page
3. Use the mark allocation as a guideline to estimate the amount of time to spend on a
question.

Do not turn the page before permission is given


Question One [15 Marks]

On the answer sheet, write only the letter (A, B, C, or D) that best corresponds to the most
appropriate answer for each of the multiple-choice questions from 1.1 to 1.15 below.

1.1 Which of the following statement(s) correctly describes Streams in C#?


A. Streams must be opened before use and closed afterward
B. Streams are used for reading data from and writing data to various devices or
programs
C. All of these options are correct
D. Streams are ordered sequences of bytes

1.2 What is the name of the IDE to develop Windows Forms Applications in C#?
A. Visual Code
B. Visio
C. Visual Basic
D. Visual Studio

1.3 Which of the following methods reads a single line of text from the stream and returns
null when the end of the file is reached?
A. ReadToEnd()
B. Close()
C. new StreamReader()
D. ReadLine()

1.4 Which of the following methods reads all the text until the end of the stream?
A. Close()
B. ReadLine()
C. ReadToEnd()
D. new StreamReader()

1.5 Which of the following automatically calls the Close() method for a text file stream after
the execution is completed?
A. None of these options are correct
B. try..catch
C. while()
D. using()
1.6 Which stream class provides methods for writing lines of text and sequences of
characters to a text file?
A. StreamReader
B. StreamRead
C. StreamWrite
D. StreamWriter

1.7 __________ block specifies the type of exceptions that is caught.


A. try
B. catch
C. using
D. finally

1.8 Which of the following statement(s) correctly describes the properties of an array?

A. All these options are correct


B. Has a fixed size (Array.Length)
C. All elements are of the same type
D. The order of the elements is fixed

1.9 A variable that is used to store the length of an array must be of type __________.
A. string
B. int
C. double
D. class

1.10 Which of the following array declarations will store the highest temperature for

each day of one full week?

A. int temp[7] = new int[7];


B. int[ ] temp = new int[7];
C. temp int[ ] = new temp[7];
D. int temp1, temp2, temp3, temp4, temp5, temp6, temp7;

1.11 How many elements are allocated by the following array declaration?

double[ ] values = new double[3];

A. 32
B. 3
C. 4
D. 2
1.12 For an array of 10 elements, the highest index is __________.
A. 10
B. 9
C. 11
D. 2

1.13 Assume that an array is declared as:

int[ ] anArray = new int[5] {10, 20, 30, 40, 50};

Which of the following statements will double the value stored in anArray[2]?

A. anArray[2] *= 2;
B. anArray = anArray * 2;
C. anArray[2] = anArray[5] * 2;
D. anArray[2] *= anArray[2] * 2;

1.14 Which of the following C# code correctly declares an array of 4 integers?


A. int arr[4];
B. int[ ] arr = new int[4];
C. int[ ] arr = 4;
D. int[4] arr;

1.15 Array indexes always start at __________.


A. None of these options are correct
B. 1
C. 0
D. 2
Question 2 [20 Marks]

Assume that the following DUT student results for Semester 2 are contained in the Text File
StudentResults.txt for some of the students registered for APDB101:

Figure 1

You are required to examine and complete the C#.NET button/driver code below that uses the
MT1, MT2, and Quiz1 marks stored in the StudentResults.txt text file to calculate the average
mark for each student and determine whether the student has passed or failed. The student will
pass if he/she obtained the average mark of 50 and above. Display the student number, MT1
mark, MT2 mark, Quiz1 mark, average mark, and result, each separated by a tab (as shown in
Figure 1).
Driver code
private void Button1_Click(object sender, EventArgs e)
{
string lineRec = "";
double average = 0;
2.1_____Results; [1mark]

string[] lineArray = new 2.2 _________ ; [1 mark]

StreamReader file = new 2.3____(@"C:\Users\Zibuyisile


Magubane\Desktop\StudentResults.txt"); [1 mark]

using (file)
{
2.4 _______ = file.ReadLine(); [1 mark]

while (lineRec != null)


{
lineArray = 2.5________; [1½ marks]
average =(________2.6____________________________); [5 marks]
if (__2.7_________) [1½ marks]
{
2.8______________; [1 mark]
}
else
{
2.9_______________; [1 Mark]
}
lstOutput.Items.Add (_____2.10___________________); [6 marks]
lineRec = file.ReadLine();
}
}
}

Question 3 [15 Marks]

Writing to a text file using the StreamWriter class.

Examine the following C# code and answer the questions (3.1 to 3.6 ) below:

private void Button1_Click(object sender, EventArgs e)


{
string[] studentNames = { "Kyle", "Amahle", "Willow", "Sifiso", "Jane" };
string filePath = "StudentNames.txt";
StreamWriter objSW = new StreamWriter(filePath);
using (objSW)
{
for (int i = 0; i < studentNames.Length; i++)
{
objSW.WriteLine(studentNames[i]);
}
}
}
3.1 After the code above has executed, how will the data be presented or appear in the
StudentNames.txt text file? Provide the expected output on your answer sheet. [1]
3.2 How would you modify this code to append new student names to the text file
instead of overwriting it, write the complete line of code? [1]
3.3 What is the length of the studentNames array? [1]
3.4 What data type is studentNames [1 ]
3.5 Add a line of code to display a message box indicating that the file has been
written to successfully. [1]
3.6 Write the C# Windows application which will use the StreamReader class to read a text file
named “StudentNames,” located at @”StudentNames.txt.” The application should display the
output on the list box which is named as “lstOutput,” as shown in Figure 2 below. [10]

Figure 2

You might also like