0% found this document useful (0 votes)
60 views

S5-COMP-MCE-Q-A

The document is an examination question paper for Senior Five (S5) students in Computer Science, dated 14/06/2024, with a total duration of 3 hours. It consists of three sections: Section A requires answering all 12 questions, Section B requires answering 3 questions, and Section C requires answering 1 question. The paper covers various topics in computer science, including programming concepts, database models, and debugging.
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)
60 views

S5-COMP-MCE-Q-A

The document is an examination question paper for Senior Five (S5) students in Computer Science, dated 14/06/2024, with a total duration of 3 hours. It consists of three sections: Section A requires answering all 12 questions, Section B requires answering 3 questions, and Section C requires answering 1 question. The paper covers various topics in computer science, including programming concepts, database models, and debugging.
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/ 17

COMPUTER SCIENCE

Date: 14/ 06/2024


Period: 8:30 -11:30

END OF TERM III EXAMINATIONS


QUESTION PAPER

GRADE: SENIOR FIVE (S5)

LEVEL: ADVANCED LEVEL


-MATHEMATICS -COMPUTER SCIENCE-
COMBINATIONS:
ECONOMICS (MCE)
- MATHEMATICS -PHYSICS-COMPUTER
SCIENCE (MPC)

DURATION: 3HOURS

.……./100 ….… /70


MARKS: CAMIS

INSTRUCTIONS

1)This paper consists of three sections.


Section A: Attempt all 12 questions. (55marks)
Section B: Attempt 3 questions. (30marks)
Section C: Attempt 1 question. (15marks)

2)Use a blue or black ink pen only to write your answers.

1
Section A: Attempt all 12 questions from this section (55marks)

1. Choose the correct answer, what is the most important safety precaution to
take when cleaning a laptop? (3 marks)
a) Use harsh chemicals.

b) Power it off and unplug it.

c) Clean while it's running.

d) Don't worry about safety precautions.

2. Distinguish clearly between half-duplex and full-duplex in the context of


data transmission. (6 marks)

3. Discuss any 3 Database models. (6 marks)

4. Define many to one relationship and give an example. (5 marks)

5. Explain how functional dependency differ from transitive dependency in


database normalization (5 marks)

6. Differentiate between a class and an object in C++ with examples. (5 marks)

7. List any 5 basic Object Oriented Programming concepts. (5 marks)

8. Define the term debugging (4 marks)

9. What function is used to find the length of a string in Visual Basic?


(3 marks)

a) Len()
b) Length()
c) StrLength()
d) StringLength()

10. Define method overloading and give an example. (5 marks)

11. When running a Java program with multiple classes, how does the Java
Virtual Machine (JVM) identify the main class? (4 marks)

A) By searching for the class with the highest number of methods


B) By searching for the class with the shortest name

2
C) By using the class specified with the -cp option
D) By using the class specified with the public static void main(String[] args)

method

12. What is the purpose of the "new" keyword in Java? (4 marks)


A) It creates a new class definition.
B) It allocates memory for a new object.
C) It initializes instance variables within a class.
D) It defines a new method in a class.

3
Section B: Attempt any (3) three questions from this Section (30marks)

13. Write a C++ Program to find the Fibonacci series up to a given term.
(10 marks)
14. Analyse the program given below and give its output appropriately.
(10 marks)

#include <iostream>
int main() {
int arr[5] = {10, 20, 30, 40, 50};

int *ptr = &arr[4];


std::cout << "Elements of the array accessed using pointer:\n";

for (int i = 0; i < 5; ++i) {


std::cout << "Element " << sizeof(arr)/sizeof(int)-i << ": " << *(ptr-i) << std::endl;

}
std::cout << "\nModified elements of the array using pointer:\n";

for (int i = 4; i >=0; i--) {


*(ptr-i) += 5;
std::cout << "Element " << 5-i << ": " << arr[4-i] << std::endl;

}
return 0;
}

15. Consider the following declarations and answer the questions given
below: (10 marks)
class living_being {

char name[20];

protected:

int jaws; public:

void inputdata(char, int);

void outputdata(); }

4
class animal: protected living_being {

int tail;

protected:

int legs;

public:

void readdata(int, int);

void writedata();

}; class cow: private animal { char horn_size;

public: void fetchdata(char); void displaydata(); };

(i) Name the base class and derived class of the class animal.

(ii) Name the data member(s) that can be accessed from function displaydata.

(iii) Name the data member(s) that can be accessed by an object of cow class.

(iv) Is the member function outputdata accessible to the objects of animal


class.

16. Using label and textbox Write a VB program to calculate cube of an


entered number. you should use vb6.0 or vb.net (10 marks)

17. Write Java program that uses an array to calculate the sum of the first
20 numbers. (10 marks)

5
Section C: Attempt any (1) one question from this Section (15marks)

18. Write a program in Visual Basic that calculate a factorial of a number


received through input box and displays the result in a message box. You
should use vb6.0 or vb.net. (15 marks)

19. Write a Java program that reads data from a file named "source.txt"
using FileInputStream and writes it to a file named "destination.txt"
using FileOutputStream. (15 marks)

20. Observe the IP address192.168.2.143/22 and respond to the


questions below: (15 marks)
a. What class does it belong
b. Write down the network id and host id of the above IP
address c. Which subnet mask does the network above have?
d. How many bits reserved to network?
e. How many hosts does the network above host?

6
COMPUTER SCIENCE

Date: 14/ 06/2024


Period: 8:30 -11:30

END OF TERM III EXAMINATIONS


MARKING GUIDE

GRADE: SENIOR FIVE (S5)

LEVEL: ADVANCED LEVEL


-MATHEMATICS -COMPUTER SCIENCE-
COMBINATIONS:
ECONOMICS (MCE)
- MATHEMATICS -PHYSICS-COMPUTER
SCIENCE (MPC)

DURATION: 3HOURS

.……./100 ….… /70


MARKS: CAMIS

INSTRUCTIONS

1)This paper consists of three sections.


Section A: Attempt all 12 questions. (55marks)
Section B: Attempt 3 questions. (30marks)
Section C: Attempt 1 question. (15marks)

2)Use a blue or black ink pen only to write your answers.

7
Section A: Attempt all 12 questions from this section (55marks)

1. Choose the correct answer, what is the most important safety precaution to
take when cleaning a laptop? (3 marks)
a) Use harsh chemicals.

b) Power it off and unplug it.

c) Clean while it's running.

d) Don't worry about safety precautions.

Answer

b) Power it off and unplug it.

2. Distinguish clearly between half-duplex and full-duplex in the context of


data transmission. (6 marks)
Answer

Half-Duplex: the channel of communications allows alternating transmission


in two directions, but not in both directions simultaneously
both
direction but not the same times

Example:
 Talkie- Walkie
 intercom,
 string phone
Full-Duplex: the communication between sender and receiver can occur
simultaneously. or data flows in both directions at the same time.
both
direction at the same times

Example:

 telephone conversation

3. Discuss any 3 Database models. (6 marks)


Answer
The hierarchical model organizes its data using a tree structure. The root
of the tree is the parent followed by child nodes. The hierarchical model

8
was widely used in the early days of computing, but it has since been
replaced by more flexible models such as the relational model.

In the network model, entities are organized in a graph, in which some


entities can be accessed through several paths. The network model is an
extension of the hierarchical model, where each child node can have
multiple parent nodes.

In the Relational Model, data is organized in two-dimensional tables


called relations.

The tables or relation are related to each other. The relational model is
the most widely used database model.
4. Define many to one relationship and give an example. (5 marks)
Answer
In a many-to-one relationship, multiple entities or records from one
entity can be associated with a single entity or record from another
entity.

For example, in a customer and orders scenario, a customer can place


multiple orders, but each order is associated with only one customer.
Therefore, the relationship between a customer and orders is a many-to-
one relationship

5. Explain how functional dependency differ from transitive dependency in


database normalization (5 marks)
Answer
Functional Dependency:

Definition: Functional dependency describes a relationship between two


attributes (or sets of attributes) in a relation such that one attribute's value
determines another attribute's value.

Implication: Functional dependency is a fundamental concept used in


normalization to identify and eliminate redundancy in a relation.

Transitive Dependency:

Definition: Transitive dependency occurs when a non-key attribute in a relation


is functionally dependent on another non-key attribute rather than on a
candidate key.

9
Implication: Transitive dependency violates the second normal form (2NF) in
database normalization.

6. Differentiate between a class and an object in C++ with examples. (5 marks)

Answer
A class is a template for creating objects, whereas an object is an instance of
a class. For example, "Car" is a class, and "BMW" or "Toyota" are objects of
the "Car" class.
7. List any 5 basic Object Oriented Programming concepts. (5 marks)
Answer
Classes.

Objects

Encapsulation

Abstraction

Inheritance

Polymorphism

Interfaces

8. Define the term debugging (4 marks)

Answer
Debugging is the process of identifying, isolating, and fixing errors or bugs in
computer software or hardware. The goal of debugging is to ensure that the
program runs as intended and produces the expected output without errors or
unexpected behavior.

9. What function is used to find the length of a string in Visual Basic?


(3 marks)

a) Len()
b) Length()
c) StrLength()
d) StringLength()
answer
a) Len()

10
10. Define method overloading and give an example. (5 marks)
Answer
Method overloading is a feature in object-oriented programming where a class
can have multiple methods with the same name but with different parameters
or arguments. In method overloading, the methods must have the same name
but can differ in the number, order, or type of parameters.

Here is an example of method overloading in Java:

public class Calculator {

public int add(int num1, int num2) {

return num1 + num2; }

public double add(double num1, double num2) {

return num1 + num2; }

public int add(int num1, int num2, int num3) {

return num1 + num2 + num3; } }

11. When running a Java program with multiple classes, how does the Java
Virtual Machine (JVM) identify the main class? (4 marks)

A) By searching for the class with the highest number of methods


B) By searching for the class with the shortest name
C) By using the class specified with the -cp option
D) By using the class specified with the public static void main(String[] args)

method

Answer

D) By using the class specified with the public static void main(String[] args)
method

12. What is the purpose of the "new" keyword in Java? (4 marks)


A) It creates a new class definition.
B) It allocates memory for a new object.
C) It initializes instance variables within a class.

11
D) It defines a new method in a class.
Answer
B) It allocates memory for a new object.

Section B: Attempt any (3) three questions from this Section (30marks)
13. Write a C++ Program to find the Fibonacci series up to a given term.
(10 marks)
Answer

#include<iostream>
using namespace std;
main() {
int n, c, first = 0, second = 1, next;
cout << "Enter the number of terms of Fibonacci series you want" <<
endl;
cin >> n;
cout << "First " << n << " terms of Fibonacci series are :" << endl;

for ( c = 0 ; c < n ; c++ ) {


if ( c <= 1 )
next = c;
else
{
next = first + second;
first = second;
second = next;
}
cout << next << endl;
}
return 0;
}
14. Analyse the program given below and give its output appropriately.
(10 marks)

#include <iostream>
int main() {
int arr[5] = {10, 20, 30, 40, 50};

12
int *ptr = &arr[4];
std::cout << "Elements of the array accessed using pointer:\n";

for (int i = 0; i < 5; ++i) {


std::cout << "Element " << sizeof(arr)/sizeof(int)-i << ": " << *(ptr-i) << std::endl;

}
std::cout << "\nModified elements of the array using pointer:\n";

for (int i = 4; i >=0; i--) {


*(ptr-i) += 5;
std::cout << "Element " << 5-i << ": " << arr[4-i] << std::endl;

}
return 0;
}
Answer

15. Consider the following declarations and answer the questions given
below: (10 marks)
class living_being {

char name[20];

protected:

int jaws; public:

void inputdata(char, int);

13
void outputdata(); }

class animal: protected living_being {

int tail;

protected:

int legs;

public:

void readdata(int, int);

void writedata();

}; class cow: private animal { char horn_size;

public: void fetchdata(char); void displaydata(); };

(i) Name the base class and derived class of the class animal.
(ii) Name the data member(s) that can be accessed from function
displaydata.
(iii) Name the data member(s) that can be accessed by an object of cow
class.
(iv) Is the member function outputdata accessible to the objects of
animal class.
Answer

(i) Base class: living_being Derived class: cow

(ii) horn_size, legs, jaws

(iii) fetchdata() and displaydata()

(iv) No

16. Using label and textbox Write a VB program to calculate cube of an


entered number. you should use vb6.0 or vb.net (10 marks)
Answer

14
Vb6.0 Vb.net
Private Sub Public Class Form1
Command1_Click()
Dim a As Integer Private Sub
Dim result As Button1_Click(sender As Object,
Integer e As EventArgs) Handles
a = Val(Text1.Text) Button1.Click
result = a * a * a
Label1.Caption = Dim a As Integer
result Dim result As Integer
End Sub
a = Val(TextBox1.Text)

result = a * a * a

Label1.Text = result

End Sub

End Class

17. Write Java program that uses an array to calculate the sum of the first
20 numbers. (10 marks)
Answer

public class SumOfFirst20Numbers {

public static void main(String[] args) {

int[] numbers = new int[20];

int sum = 0;

for (int i = 0; i < 20; i++) {

numbers[i] = i + 1; }

for (int i = 0; i < 20; i++) {

sum += numbers[i]; }

System.out.println("The sum of the first 20 numbers is: " + sum); } }

15
Section C: Attempt any (1) one question from this Section (15marks)

18. Write a program in Visual Basic that calculate a factorial of a number


received through input box and displays the result in a message box. You
should use vb6.0 or vb.net. (15 marks)
VB 6.0 VB.net

Private Sub Form_Load() Public Class Form1

Dim n As Integer Private Sub


Form1_Load(sender As Object,
Dim fact As Long
e As EventArgs) Handles
fact = 1 MyBase.Load

n = InputBox("enter a number Dim n As Integer


here:", "Input Menu")
Dim fact As Long
For i = 1 To n
fact = 1
fact = fact * i
n = InputBox("enter a
Next number here:", "Input Menu")

MsgBox (n & "!=" & fact) For i = 1 To n

End Sub fact = fact * i

Next

MsgBox(n & "!=" & fact)

End Sub

End Class

19. Write a Java program that reads data from a file named "source.txt"
using FileInputStream and writes it to a file named "destination.txt" using
FileOutputStream. (15 marks)
Answer
import java.io.*;
public class Filecopy {

16
public static void main(String[] args) {
// Step 1: Define the input and output filepaths
String sourceFile = "source.txt";
String destinationFile = "destination.txt";
// Step 2: Create FileInputStream and FileOutputStream objects
try (FileInputStream inputStream = new
FileInputStream(sourceFile);
FileOutputStream outputStream = new
FileOutputStream(destinationFile)) {
// Step 3: Read data from the source file and write it to the
destination file
int data;
while ((data = inputStream.read()) != -1) {
outputStream.write(data); }
// Step 4: Display a message indicating successful copy
System.out.println("File copied successfully!");
} catch (IOException e) {
// Step 5: Handle any exceptions that may occur during file
operations
e.printStackTrace();
}
}
}
20. Observe the IP address192.168.2.143/22 and respond to the questions
below: (15 marks)
a. What class does it belong
b. Write down the network id and host id of the above IP address
c. Which subnet mask does the network above have?
d. How many bits reserved to network?
e. How many hosts does the network above host?

Answer

a. IT BELONG TO CLASS C
b. NETWOR ID: 192.168.2 HOST ID 143
c. SUBNET MASK 255.255.252.0
d. 22 bits
e. HOSTS: 210-2=1022 HOSTS

17

You might also like