Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

EXECUTIVE GARDEN INSTITUTE (EGI) Batch -12

Name: Subject: Computer Science

Date: 30-May-2024 Time: 1:20 hour

Instructions

• Use Black ink or ball-point pen.


• Fill in your Name correctly.
• Answer all questions.
• Answer the questions in the space provided.
• Color the box in Multiple Choice question.
• You must not use the internet during the test.

Information

• The total mark for this test is 40.


• The marks for each question are shown in brackets.

Advice

• Read each question carefully before you start to answer it.


• Try to answer every question.
• Check your answer if you have time at the end.
1. Answer the following questions.

(a) How do you understand having consistency in your program? 1

………………………………………………………………………………………………………………………………………………………

………………………………………………………………………………………………………………………………………………………

………………………………………………………………………………………………………………………………………………………

(b) State the meaning of logic. How do you understand the term logic errors

in your program? 2

……………………………………………………………………………………………………………………………………………………………

……………………………………………………………………………………………………………………………………………………………

……………………………………………………………………………………………………………………………………………………………

……………………………………………………………………………………………………………………………………………………………

(c) Describe the difference between local variables and global variables in a 2

computer system.

…………………………………………………………………………………………………………………………………………………………..….

…..………………………………………………………………………………………………………………………………………………………….

(d) What happens when a global variable and a local variable share the same name? 1

………………………………………………………………………………………………………………………………………………………………

………………………………………………………………………………………………………………………………………………………………

………………………………………………………………………………………………………………………………………………………………

………………………………………………………………………………………………………………………………………………………………

(e) Compare linear search algorithms based on binary search algorithms. 14

………………………………………………………………………………………………………………………………………………………………

………………………………………………………………………………………………………………………………………………………………

………………………………………………………………………………………………………………………………………………………………

………………………………………………………………………………………………………………………………………………………………

………………………………………………………………………………………………………………………………………………………………

………………………………………………………………………………………………………………………………………………………………

Total for Question 1 = 10 Marks


2. (a) Anna has written a program that manipulates text.

Open Q02a in the code editor.

Use the code to answer these questions.

(i) Identify a line number where the code includes a relational operator. 1

………………………………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………………………………

(ii) Identify a line number where a variable is set to a numeric value entered by a 1
user.

………………………………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………………………………

(iii) Identify the name of a variable passed from the main program to the 1
subprogram.

………………………………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………………………………

(iv) Identify the name of a variable that receives the value calculated by the 1
subprogram.

………………………………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………………………………

(v) State the value returned by the subprogram when the input values are 2
educational, 3, 6

………………………………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………………………………

(vi) State the purpose of the subprogram. 2


………………………………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………………………………

(vii) Differences between the term ‘program’ and ‘algorithm’. 2

………………………………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………………………………

Total for Question 2 = 10 Marks


3. A software engineer is working with some algorithm.

(a) An algorithm needs to be developed. 2

The algorithm must:

• Check for a change of hour every minute.

• use the library subprogram getHour () to get the hour part of the current time.

• in the 24-hour clock (0 to 23)

• output “Good morning” when the hour is between 3 and 12, inclusive.

• output “Good afternoon” when the hour is between 13 and 19, inclusive.

• output “Good night” at all other times.

• Complete the flowchart to represent this algorithm, in the space provided on the

• next page.

The call to the library subprogram getHour () has already been included.
Use this subprogram symbol to show waiting for 1 minute. 6
Draw your flow chat here.
(b) Another algorithm determines when to change the flavored syrups for a drinks

dispensing machine.

Figure-1 shows this algorithm written in pseudocode.

11 SET flavours TO [“anise”, “mango”, “cola”, “apple”, “papaya”, “strawberry”,


“lychee”, “banana”]
12
13 SET volume TO [0.7, 0.2, 0.6, 0.1, 0.05, 0.8, 0.4, 0.6]
14
15 SET i TO 0
16
17 WHILE i < 8 DO
18
19 IF (volume[i] < 0.1) THEN
10 SEND (flavours[i] & “ needs changing”) TO DISPLAY
11
12 ELSE
13 IF (volume[i] >= 0.3) AND (volume[i] <= 0.5) THEN
14 SEND (flavours[i] & “ needs ordering”) TO DISPLAY
15 END IF
16 END IF
17
18 SET i TO i + 1
19
20 END WHILE

Figure-1
(i) Give the output produced by the algorithm. 2

…………………………………………………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………………………………………………

………………………………………………………………………………………………………………………………………………………….

………………………………………………………………………………………………………………………………………………………….

The algorithm works with a fixed number of flavours.


(ii) Give the number of the line in the algorithm that would need to be amended to allow 1
for any number of flavours.

…………………………………………………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………………………………………………

………………………………………………………………………………………………………………………………………………………….

………………………………………………….……………………………………..…………….…………………………………………………
(iii) State how the pseudocode needs to be changed to make this amendment. 1
…………………………………………………………………………………………………………………………………………………………

…………………………………………………………………………………………………………………………………………………………

………………………………………………………………………………………………………………………………………………………….

………………………………………………….……………………………………..…………………………….…………………………………

Total for Question 3 = 10 Marks

4. Different algorithms can be used to manipulate data.

Open Q04 in the code editor.

Write a program to display the square and cube of a number between 1 and 50
entered by a user.

Th code must:
ask the user to enter a number between 1 and 50 inclusive
• display the number, the square of the number and the cube of the number,
appropriate labels
• stop when a number outside the range 1 to 50 is entered.

Save your code as Q04FINISHED with the correct file extension for the
programming language.

Total for Question 4 = 10 Marks

You might also like