SP

NVQ Level 05 - Semester 1 - Information and Communication Technology

Software Programming (Theory) 

Answer any five (05) questions

Question -1

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

A class is simply a representation of a type of object. It is the blueprint, or plan, or template, that describes the details of an object.

public class Main {
  int x = 5;
}

Object can be defined as an instance of a class. An object contains an address and takes up some space in memory. Objects can communicate without knowing details of each other's data or code, the only necessary thing is that the type of message accepted and type of response returned by the objects.

public class Main {
  int x = 5;

  public static void main(String[] args) {
    Main myObj = new Main();
    System.out.println(myObj.x);
  }
}

b) Write 3 Access Modifiers used in programming language (3 M)

1. Public
2. Private
3. Protected

c) What is the output of the following code segment? (Follow Java or C#.Net code) (3 M)

100    null
102    null

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

A function is used to calculate result using given inputs. And a function can be called by a procedure.

A procedure is used to perform certain task in order. And a procedure cannot be called by a function.

e) Write the Psedocode for the method swap (interchange) values of two integer type variables ? (6 M)

Question -2

a) Write two advantages of Object Oriented Programming (4 M)

  1. OOP is faster and easier to execute
  2. OOP makes it possible to create full reusable applications with less code and shorter development time
  3. OOP offers easy to understand and a clear modular structure for programs.

b) What is Polymorphism ? (3 M)

Polymorphism is the concept where an object behaves differently in different situations. There are two types of polymorphism – compile time polymorphism and runtime polymorphism.

c) What are the two methods used to implement Polymorphism ? (2 M)

Polymorphism in Java has two types: Compile time polymorphism (static binding) and Runtime polymorphism (dynamic binding). 

Method overloading is an example of static polymorphism, while method overriding is an example of dynamic polymorphism.

d) Write the answers to i, ii, iii, and iv from the given code segment (Follow Java or C#.Net code)



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

Vehicle

ii. What is the name of Sub Class ? (2 M)  

Bike

 iii. Write the output (4 M)

Bike is running safely

 iv. Identify the OOP concepts re applied in this program. (3M)

Inheritance 

In above program where an object is based on another object. The object that is getting inherited is called superclass and the object that inherits the superclass is called subclass.

Question -3

a) Briefly describe an Array with an example (5 M)

An array is a container object that holds a fixed number of values of a single type. The length of an array is established when the array is created. After creation, its length is fixed.

int [] anArray = new int[10];
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 M)


ii. Write code to print the second element in the following integer array. Array name is "score". (2 M)



iii. Write code to replace the value 2 with the value 6 in the following integer array. Array name is "score". (2 M)


c) What is the output of the following code segment ? (Follow Java or C#.Net code) (3 M) 


Output : error (ArrayIndexOutOfBoundsException)

d) Write answer to question (i) and (ii) by considering the give code segment 

    String x="I Love SLGTI";

i. What is the output of the following code? (Follow Java or C#.Net code) (2 M)

        x.charAt(4); (in JAVA)

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

Output : v

ii. Write the line of code to get the number of characters in the above string. (2 M)

Question -4

a) Briefly explain the term "Variable" and give the three different type of variables (4 M)

variable or scalar is a storage location (identified by a memory address) paired with an associated symbolic name, which contains some known or unknown quantity of information referred to as a value

1. Constants Variables
2. Global Variables
3. Local Variables 

b) What is an algorithm? Explain its two characteristics. (6 M)

An Algorithm is a definitive set of logic statements for solving as specific a task as possible.

  1. Definiteness: Each step must be clear, well-defined and precise. There should be no any ambiguity.
  2. Effectiveness: Each step must be simple and should take a finite amount of time.

c) What is the main difference between while and do-while iterative structures? (3 M)


d) Write the output of the following code segment? (3 M)

Output : Pass

e) Rewrite the given code segment with only one if statement (4 M)


if ((attendance >= 80) && (assignmentMarks >= 40))
eligibility = true;

Question - 5

a) What is an Exception? (2 M)

An exception is an event that occurs during the execution of a program that disrupts the normal flow of instructions.

b) Briefly describe the three types of errors (6 M)

Syntax Errors
They don’t follow a correct sequence in the computer language.

Compilation Errors

A compilation or compile-time error happens when the compiler doesn’t know how to turn code into the lower-level code.

Logical Errors
It causes to “misbehave” in some way, rendering wrong output of some kind.

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 M)

d) What is the function of the check State property of the Check Box control? (4 M)

The CheckState property gets or sets the state of CheckBox. If the ThreeState property is set to false, the CheckState property value can only be set to CheckState.

Checked – The CheckBox displays a check mark. The control appears sunken. 

Unchecked – The CheckBox is empty. The control appears raised. 

Indeterminate – The CheckBox displays a check mark and is shaded.

e) What is a Data Table?

DataTable represents relational data into tabular form. ADO.NET provides a DataTable class to create and use data table independently. It can also be used with DataSet also.

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 cylinder colour, radius and height for each cylinder. Design the cylinder class with the following properties.

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

ii. Constructor of the class to initialize encapsulated variables with passing arguments from calling program. (4 M)

iii. Public getColour method to return the colour of the cylinder (3 M)

iv. Public displayVolume method to calculate the volume of the cylinder and print it. (Volume of a Cylinder = (22/7)*radius*height) (5 M)

v. Write the code segment to create an instance of the cylinder class passing following values for the instance variables. (5 M)

colour = blue, radius = 7.0, height = 20.0

Complete program here:

2 comments: