[All Rights Reserved]
SLIATE
SLIATE SRI LANKA INSTITUTE OF ADVANCED TECHNOLOGICAL EDUCATION
(Established in the Ministry of Higher Education, vide in Act No. 29 of 1995)
Higher National Diploma in Information Technology
First year, Year, First Semester Examination – 2023
HNDIT1012 : Visual Application Programming
Instructions for candidates: No. of questions : 6
Answer five questions only. No. of pages :4
All questions carry equal marks. Time : 3 hours
Question 01 [20 Marks]
i. Define the following terms (6 marks)
a. Computer Program
A computer program is a sequence or set of instructions in a programming
language for a computer to execute
b. Source Code
A computer program in its human-readable form is called source code.
c. EXE File
An EXE file is an executable program you can run in Microsoft Windows
ii. Give three examples for programming languages (3 marks)
C++, Java, Python etc
iii. What is the difference between Compiler and Interpreter (4 marks)
A compiler translates the entire program into machine code before execution, whereas an
interpreter translates and executes the code line by line.
iv. What does IDE stands for? (2 marks)
Integrated Development Environment
v. Define the term CLR ( 2 marks)
The CLR is the runtime environment in .NET that manages program execution,
memory, and other system services.
vi. State whether the following statements are True or False (3 marks)
a. C# source code file ends with .cs extension T
b. In C# you have to declare a variable in the program before you use it to store data T
c. You can declare multiple variables of different data types within one declaration F
Question 02 [20 Marks]
i. Mentions the components you can use in a GUI to perform following tasks (6 marks)
a. For displaying static text to user Label
b. For selecting multiple options independently. CheckBox
c. For triggering actions at specified intervals Timer
ii. Following interface has been created to collect student preferences for SLIATE courses.
a. State four components that are needed to create the above GUI (04 marks)
1*4 marks for any related components
b. Write the code for clear button to clear all text boxes (03 marks)
txtName.Text =” ” or txtName.Clear();
c. Write the code for the exit button (03 marks)
Application.Exit()
d. Write the code segment to obtain the gender choice in to a variable (04 marks)
string gender;
if(rbtMale.Checked)
gender=”male”;
if(rbtFemale.Checked)
HNDIT Year I Semester I 2023 – Visual Application Programming 2
gender=”female”;
Question 03 [20 Marks]
i. Write the syntax of if-else statement (2 marks)
if(Boolean expression){
Statemets-if true;
}else
{
Statements if false;
}
ii. What are the limitations of switch statement when compared with if-else statement?
(4 marks)
Switch can be used to compare for equality only
Switch cannot be used for data types such as float, double
iii. The menu below shows the following drinks with their corresponding prices:
Espresso: Rs. 250 per cup
Latte: Rs.350 per cup
Cappuccino: Rs.300 per cup
Americano: Rs 275 per cup
Mocha: Rs. 400 per cup
HNDIT Year I Semester I 2023 – Visual Application Programming 3
Using switch statement write the code for the txtQuantity_TextChanged( ) event to calculate
the sub total (8 marks)
private void txtQuantity_TextChanged(object sender, EventArgs e)
{
string selectedDrink = comboBoxDrink.SelectedItem.ToString();
int quantity;
double price = 0;
double subtotal = 0;
switch (selectedDrink)
{
case "Espresso":
price = 250;
break;
case "Latte":
price = 350;
break;
case "Cappuccino":
price = 300;
break;
case "Americano":
price = 275;
break;
case "Mocha":
price = 400;
break;
default:
txtSubtotal.Text = "Please select a drink.";
}
subtotal = price * quantity;
txtSubtotal.Text =subtotal.ToString();
}
iv. Write a C# program to find the maximum number among three numbers entered by the
user. Assume the numbers are stored in three variables: num1, num2, and num3. Use
appropriate logic to determine the maximum number and display it to the user.(6
marks)
// give 6 marks for the logic
HNDIT Year I Semester I 2023 – Visual Application Programming 4
Ex:
int max = num1; // 1 mark
if (num2 > max) //2 mark
{
max = num2;
}
if (num3 > max) //2
{
max = num3;
}
// Display the maximum number //1 mark
Console.WriteLine($"The maximum number is: {max}");
Question 04 [20 Marks]
i. State two differences between while loop and Do while loop (4 marks)
While Loop: The condition is checked before executing the loop body. If the condition
is false initially, the loop body will not execute even once.
Do-While Loop: The condition is checked after executing the loop body. This
guarantees that the loop body will execute at least once, even if the condition is false on
the first iteration.
ii. What is an infinite loop? (2 marks)
An infinite loop is a loop that continues to execute indefinitely because its termination
condition is never met
iii. Write the output of following programs ( 9 marks)
a.
for (int i=0;i<=30;i+=5){
Console.WriteLine (i);
}
0
5
10
15
20
25
30
b. int counter = 0;
do
{
Console.WriteLine("Counter: " + counter);
counter++;
HNDIT Year I Semester I 2023if
– Visual Application
(counter == Programming
5) 5
{
break;
}
Counter: 0
Counter: 1
Counter: 2
Counter: 3
Counter: 4
a.
int i=10;
while (i<10){
Console.WriteLine (i);
i++;
}
No output
v. Write a program to display the summation of even numbers between 0 and 100 (5
marks)
int sum = 0;
for (int i = 0; i <= 100; i++)
{
if (i % 2 == 0)
{
sum += i;
}
}
Console.WriteLine("The summation of even numbers between 0 and 100 is: " +
sum);
}
Question 05 [20 Marks]
i. What is an array (2 marks)
a data structure in programming that allows you to store multiple values of the same
type in a single collection.
ii. The following array “vowels” store vowels of English alphabet
HNDIT Year I Semester I 2023 – Visual Application Programming 6
a e i o
a. What is the length of the array? 4 (2 marks)
b. How to get the letter ‘i’ vowels[2] (2 marks)
c. What is the index of the letter ‘e’ 1 (2 marks)
d. How to replace letter ‘o’ with ‘u’ vowels[3]=’u’ (2 marks)
iii. “Dataset class is a disconnected architecture in .NET Framework” Explain
(4 marks)
you connect to the database first time and get all data in an object and use it if
required
iv. State whether the following statements are True or False with related to datasets in C#
(6 marks)
a. Dataset enables to store data from multiple tables and multiple sources T
b. We can create a relationship between the tables in a DataSet T
c. The first record in a dataset has a position property of one F
Question 06 [20 Marks]
i. Mention three methods available in the Graphic class (3 marks)
DrawLine
DrawArc
DrawClosedCurve
DrawPolygon
DrawRectangle
DrawEllipse.
ii. The following code snippet is used to open a file dialog box
(1) OpenFileDialog fileDialog = new OpenFileDialog();
(2) fileDialog.Filter = "txt files (*.txt)|*.txt|All files
(*.*)|*.*";
(3) fileDialog.FilterIndex = 0;
(4) fileDialog.InitialDirectory = @“C:\asp c#";
(5) fileDialog.showDialog();
(6) if (fileDialog.ShowDialog() == DialogResult.OK{
(7) txtFile.Text = fileDialog.FileName;
(8) string readBuffer =
System.IO.File.ReadAllText(fileDialog.FileName);
}
a. By default which type of files will be displayed in the dialog box? (2 marks)
HNDIT Year I Semester I 2023 – Visual Application Programming 7
Text files
b. What is the purpose of @ sign in line 4 (3 marks)
Then the text becomes a verbatim string and allows \ symbol
c. In this code snippet ReadAllText method is used to read the content of the text file.
What are the other two methods we can use to read content of a file? (4 marks)
ReadAllLines
ReadAllBytes
iii. List two types of comments used in C# (2 marks)
Single line comments
Multi line comments
iv. How can you increase the readability of a program? (6 marks)
Using meaningful identifiers
Using comments
Indenting properly
HNDIT Year I Semester I 2023 – Visual Application Programming 8