0% found this document useful (0 votes)
40 views8 pages

Software Programming Theory

The document is a past paper for an Information and Communication Technology exam, containing 6 questions on software programming concepts. It tests knowledge of object-oriented programming principles like classes, objects, inheritance and polymorphism. It also addresses arrays, strings, variables, algorithms, exceptions, control structures, and designing classes to model real-world entities like cylinders. Students are asked to write code snippets, explain concepts, and determine output for code examples testing their understanding of fundamental programming topics.

Uploaded by

Ernest
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
40 views8 pages

Software Programming Theory

The document is a past paper for an Information and Communication Technology exam, containing 6 questions on software programming concepts. It tests knowledge of object-oriented programming principles like classes, objects, inheritance and polymorphism. It also addresses arrays, strings, variables, algorithms, exceptions, control structures, and designing classes to model real-world entities like cylinders. Students are asked to write code snippets, explain concepts, and determine output for code examples testing their understanding of fundamental programming topics.

Uploaded by

Ernest
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 8

TERTIARY AND VOCATIONAL EDUCATION COMMISSION

COMMON WRITTEN EXAMINATION

All rights reserved


NVQ Level 05 - Semester I
Information and Communication Technology

SOFTWARE PROGRAMMING K72C001M04 Three Hours


(THEORY)

* Answer any five (05) questions

Question ( 1 )

a) Briefly explain class and object with examples. (4 marks)


b) Write 3 access modifiers used in programming language. (3 marks)
c) What is the output of the following code segment? (3 marks)
(Follow Java or C#.Net code)
Java Code:-

class Student
{
intIndexNo;
String name;
Student(intid,String name)
{
IndexNo = id;
name = name;
}
void display()
{
System.out.println(IndexNo +" "+name);
}
public static void main(String[]args)
{
Student objl=newStudent(100,"Juree");
Student obj2=new Student(102,"Newsy");
objl.display();
obj2.display();
}
}

Page2 | 8
C#.Net Code:-

class Student
{
intIndexNo;
String name;
Student(intid,String name)
{
IndexNo = id;
name = name;
}
void display()
{
Console.WriteLine(IndexNo +" "+name);
}
static void main(String[]args)
{
Student objl=newStudent(100,"Juree");
Student obj2=new Student(102,"Newsy");
objl.display();
obj2.display();
}
}

d) What is the main difference a Function and a Procedure? (4 marks)


e) Write the Pseudo code for the method swap (interchange) values of two
integer type variables? (6 marks)

Question ( 2 )

a) Write two advantages of Object Oriented Programming. (4 marks)


b) What is polymorphism? (3 marks)
c) What are the two methods used to implement polymorphism? (2 marks)
d) Write the answers to i, ii, iii,andiv from the given code segment.
(Follow Java or C#.Net code)

Page3 | 8
Java Code:-

class Vehicle
{
void run()
{
System.out.println("Vehicle is running");
}
}
class Bike extends Vehicle
{
void run()
{
System.out.println("Bike is running safely");
}
public static void main(String[]args)
{
Vehicleobj = new Bike();
Obj.run();
}
}

Page4 | 8
C#.NetCode:-

class Vehicle
{
void run()
{
Console.WriteLine("Vehicle is running");
}
}
class Bike : Vehicle
{
void run()
{
Console.WriteLine("Bike is running safely");
}
staticvoid main(String[]args)
{
Vehicleobj = new Bike();
Obj.run();
}
}

i. What is the name of Supper Class? (2 marks)


ii. What is the name of Sub Class? (2 marks)
iii. Write the output. (4 marks)
iv. Identify the OOP concepts are applied in this program. (3 marks)

Question ( 3 )

a) Briefly describe an Array with an example. (5 marks)


b) Write the code segments to perform following tasks.
i. Write code to create a char array named “vowels”which can hold vowels
letters and initialize it. (Either capital letters or simple letters) (4 marks)

ii. Write code to print the second element in the following integer array. Array
name is “score”. (2 marks)
7 5 2 9 1 4 8

Page5 | 8
iii. Write code to replace the value 2 with the value 6 in the following integer
array. Array name is “score”. (2 marks)

7 5 2 9 1 4 8

c) What is the output of the following code segment? (3 marks)


(Follow Java or C#.Net code)

int index=10;
long[] Student =new long[index];
System.out.println(Student[10]); (in JAVA)
Console.WriteLine(Student[10]); (in C#.Net)

d) Write answers to question (i) and (ii) by considering the given code segment.

String x="I love SLGTI";

i. What is the output of the following code? (2 marks)


(Follow Java or C#.Net code)

x.charAt(4);(in JAVA) x[4]; (in C#.Net)

ii. Write the line of code to get the number of characters in the above string.

(2 marks)

Question ( 4 )

a) Briefly explain the term “Variable” and give the three different type of variables.(4 marks)
b) What is an algorithm? Explain its two characteristics. (6 Marks)
c) What is the main difference between while and do-while iterative structures?
(3 marks)
d) Write the output of the following code segment?

Page6 | 8
(Follow Java or C#.Net code)

intEnd_Mark=15;
intAss_Mark=50;
if((End_Mark>=35) || (Ass_Mark>=35))
System.out.println(“Pass”); (in JAVA)
Console.WriteLine(“Pass”); (in C#.Net)
else
System.out.println(“Fail”); (in JAVA)
Console.WriteLine(“Pass”); (in C#.Net) (3 marks)

e) Rewrite the given code segment with only one ifstatement

if(attendance >= 80)


if(assignmmentMarks>= 40)
eligibility = true; (4 marks)

Question ( 5 )

a) What is an Exception? (2 marks)


b) Briefly describe the three types of errors. (6 marks)
c) Write a code using try catch blocks to handle the exception when trying to
access the element which is out of bounds in an array (4 marks)
d) What is the function of the Check State property of the Check Box control?
(4 marks)
e) What is a Data table? (4 marks)

Question ( 6 )

Consider the following scenario.

You are asked to design a “Cylinder” class using JAVA or C#.Net to keep
records on cylinders manufactured by a company. The company needs to
store the cylindercolour, radius and height for each cylinder. Design the
cylinder class with following properties.

i. Encapsulated instance variables: colour, radius and height (3 marks)

Page7 | 8
ii. Constructor of the class to initialize encapsulated variables with passing
arguments from calling program. (4 marks)
iii. Public getColour method to return the colour of the cylinder. (3 marks)
iv. Public displayVolume method to calculate the volume of the cylinder and
print it. (Volume of aCylinder = (22 / 7)*radius*height) (5 marks)
v. Write the code segment to create an instance of the cylinder class passing
following values for the instance variables. (5 marks)

colour = blue, radius = 7.0, height = 20.0

Page8 | 8

You might also like