Software Programming Theory
Software Programming Theory
Question ( 1 )
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();
}
}
Question ( 2 )
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();
}
}
Question ( 3 )
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
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.
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)
Question ( 5 )
Question ( 6 )
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.
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)
Page8 | 8