0% found this document useful (0 votes)
14 views6 pages

CSC - A - L - P3 - CRM - Ipw - Caspa 2024

The document outlines a regional mock examination for Computer Science, detailing practical tasks involving programming and pattern matching. It includes instructions for candidates on problem analysis, algorithm writing, and coding in either Pascal or C. Additionally, it presents a database design task for an e-commerce platform aimed at farmers, requiring the creation of a relational database and SQL queries.

Uploaded by

Darryl Taps
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)
14 views6 pages

CSC - A - L - P3 - CRM - Ipw - Caspa 2024

The document outlines a regional mock examination for Computer Science, detailing practical tasks involving programming and pattern matching. It includes instructions for candidates on problem analysis, algorithm writing, and coding in either Pascal or C. Additionally, it presents a database design task for an e-commerce platform aimed at farmers, requiring the creation of a relational database and SQL queries.

Uploaded by

Darryl Taps
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/ 6

REPUBLICOF CAMEROON

REPUBLIQUE DU CAMEROUN PEACE – WORK – FATHERLAND

A
PAIX – TRAVAIL – PATRIE
…………………..
…………………..

MINISTERE DES ENSEIGNEMENTS MINISTRY OF SECONDARY


SECONDAIRES EDUCATION
………………….. …………………..

SUBJECT CODE PAPER


CENTRE NUMBER NUMBER
REGIONAL MOCK EXAMINATION 795 3
IN PARTNERSHIP WITH CASPA

CANDIDATE NAME: ……………………………………… SUBJECT TITLE


COMPUTER SCIENCE
CANDIDATE NUMBER: ……………………………………
CENTRE NUMBER: …………………………………………

ADVANCED LEVEL DATE: To be scheduled by the school

PRACTICAL

Time Allowed: TWO hours


Carry out ALL the task given. For your guidance, the appropriate marks for each part of a task is indicate in
brackets.
Great importance is attached to the accuracy, layout and labeling of the diagrams and computer generated
outputs.

You are reminded of the necessity for good English and orderly presentation in your answers.

Analyse the problem as well as write algorithms in the answer booklet provided. Also record in your answer
booklet ant information requested or that you believe would make it easier to understand how you carried out
tasks or answered questions.

You are expected to print a single copy of relevant fragments of your work at different times. Please notify
the supervisor of any required printout that was not done!

When an imperative programming language is required to write program code, ether standard (ISO) Pascal or
the standard (ANSI) C programming language may be used.

If need be, supervisors will assist you in recording details of intermediate work carried out on the computer.
Where information is provided is provided as soft copy, notify the supervisor if it is not found in your
machine or has not been made available to you.

©2024/795/CSC/P3/CETA Page 1 of 6 TURN OVER


This document is the property of the CATA and should not be reproduced without the permission of the authors.
PROGRAMMING [35 Marks]
SECTION A: PATTERN MATCHING
Pattern matching is a fundamental problem in computer science that involves finding a pattern within a larger data set.
The pattern can be a sequence of characters, numbers, or symbols, and the data set can be a string, an image, a sound, or
any other type of data.
The goal of pattern matching is to find all occurrences of the pattern within the data set. This problem arises in many
different applications, including text processing, image recognition, speech recognition, DNA sequencing, and network
security.
A simple algorithm can be used to solve the pattern matching problem. The basic idea behind this algorithm is to check
every position in the data set, from the position under consideration in the data set, extract a substring of equal length
as the pattern and see if the substring matches the pattern. Here's how the algorithm works:
1. Start at the beginning of the data set.
2. Compare the pattern to the substring of the data set starting at the current position.
3. If the pattern matches the substring, count it as an occurrence.
4. Move to the next position in the data set and repeat steps 2-3 until the “end” of the data set is reached.
5. Return the number of occurrences found.
For example, suppose we have the data set "000010001010001" and the pattern "0001". Then the number of times the
pattern appears in the data set is: "3"
Task 1: Problem Understanding [8 Marks]
Consider the following declaration representing an array of bits.

− Ch1 : ARRAY[𝑁] OF INTEGER


− Ch2 : ARRAY[M] OF INTEGER

In this problem, array Ch1 represents the pattern while array Ch2 represents the data set. The goal is to find all
occurrences of Ch1 within Ch2. N and M represent the size of Ch1 and Ch2 respectively such that 𝑵 ≤
𝑴. 𝑇ℎ𝑒 𝑣𝑎𝑙𝑢𝑒𝑠 𝑜𝑓 𝑁 𝑎𝑛𝑑 𝑀 𝑎𝑟𝑒 𝑠𝑤𝑎𝑝𝑝𝑒𝑑 𝑖𝑓 𝑵 > 𝑴.
1. Swapping N and M if 𝑵 > 𝑴.
The following code snippet is written to exchange the values of variables N and M.

Temp ← N
M ← Temp
N←M

a) Assume N = 5 and M = 3. State the values of N and M after execution of the code snippet above.
(1 Mark)
b) Suggest how the code snippet above would need to be modified to successfully exchange the values of
variables N and M. (1 Mark)

©2024/795/CSC/P3/CETA Page 2 of 6 TURN OVER


This document is the property of the CATA and should not be reproduced without the permission of the authors.
c) Write another code snippet that would exchange the values of N and M without the use of a third variable
Temp (2 Marks)
2. Generation of the array of bits Ch1 and Ch2
The generation of bits will be done using the predefined function random(). This function randomly generates
a natural number, A such that 𝑨 ∈ [𝟎; +∞[. For example, the instruction B←random(); assigns to the variable
B a random natural number in the interval [0;+∞[. To generate N natural numbers, the random() function will
be called N times. We are going to restrict all values generated to be binary that is either 0 or 1.
a) Using the modulus operator MOD, explain how the the instruction B←random(); can be modified
such that the random value assigned to the variable B is either 0 or 1. (2 Marks)
3. Finding the pattern Ch1 within the data set Ch2.
Consider Ch1 and Ch2 given below:
Pattern: Values 0 0 … 1 Ch1
Figure 1
Index [0] [1] … [N-1]

i
N

Data Set: Ch2 Values 0 0 0 0 1 0 0 0 1 0 1 0 0 …. 1

Index [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] …. [M-1]

Figure 2
Ch1 occurs in Ch2 if there exists a value of s as shown in figure 2 such that Ch1[i] = Ch2[i + s] for i starting from 0
to N-1(i traversing Ch1 as shown in figure 1). That is, there exist a value of s in figure 2 such that a substring of equal
length as Ch1 can be extracted from Ch2 which is identical to Ch1.
The number of occurrences of Ch1 in Ch2, NoOccur, is the number of positions s such that ch1[i] = ch2[i + s] (with i
traversing ch1). The variable s traverses the data set Ch2 and varies from 0 to a certain maximum value, MAX.
a) Determine the value of MAX as described above. (2 Marks)

Task 2: Program Development [24 Marks]


Choose either the PASCAL or the C programming language for the rest of the problem.
1. Using a suitable editor, write the following subroutines:
a) read() which receives an array Ch and a natural number n as parameters. It initializes the array Ch with n bits,
n passed as an argument. This subroutine uses the predefined function rand() in the C Programming Language
and Random() in PASCAL. Ensure the rand() is seeded with srand() so that a unique sequence of bits is
generated on each run (3 Marks)
b) display() which receives an array of bits, Ch and the size of the array as parameters. It displays the elements of
the array. (2 Marks)

©2024/795/CSC/P3/CETA Page 3 of 6 TURN OVER


This document is the property of the CATA and should not be reproduced without the permission of the authors.
c) is_equal() which receives two arrays of bits, ChA and ChB(ChA represents the pattern while ChB represents
the data set), the size of the pattern and the current position in the data set as parameters. The subroutine
returns TRUE if the pattern and the substring from the data set are identical ; is_equal() returns FALSE
otherwise. (3 Marks)
d) match() which receives two arrays of bits, Ch1 and Ch2 and the sizes of the arrays N and M as parameters. It
finds the number of occurrences NoOccur, of positions s such that ch1[i] = ch2[i + s] (with i traversing ch1).
This subroutine uses a single loop and the previous is_equal() subroutine. (6 Marks)
e) first_match() which receives two arrays of bits, Ch1 and Ch2 and the sizes of the arrays N and M as
parameters. It modifies the subroutine match() so that it returns the first position s of pattern ch1 in ch2; it returns
-1 if ch1 does not appear in ch2. (3 Marks)
2. Main Function [7 Marks]
Write the execution part of the main program which:
a) Reads 2 integers from the keyboard N and M and swaps the values of N and M if N > M; (3 Marks)
b) Calls the read() subroutine twice to initialize Ch1 (resp. Ch2) with N (resp. M) bits; (1 Mark)
c) Calls the display() subroutine twice to display the array of bits Ch1 and Ch2; (1 Mark)
d) Calls the match() subroutine to display the number of times Ch1 appears in Ch2. (1 Mark)
e) Calls the first_match() subroutine to display the first position s of pattern Ch1 in Ch2 or -1 if Ch1 does not
appear in Ch2. ; (1 Mark)
Task 3: Program Execution [3 Marks]
1. Run your program for N=4, M =15 and also for N=14, M =3. Test it to make sure it works correctly. Screenshot
the outputs after each execution and save both outputs in files named tast3a and task3b. Print both screenshots
(2 Marks)
2. Print a copy of your PROGRAM SOURCE CODE and attach it to your answer booklet (1 Mark)

SECTION B: DATABASES [25 Marks]


FARMERS’ E-COMMERCE DATABASE
Farmers currently face significant challenges in selling their farm produce efficiently due to the absence of a dedicated
online platform. This lack of an online platform hampers their ability to connect with potential buyers, showcase their
products effectively, and maximize their sales potential.
A cooperative union of farmers has tasked a programmer to build an e-commerce website to address this problem. The
website will display details of the products that the farmers sell and allow customers to place orders. Customers must
register on the website before they can place an order and each order can be for one or more different products. This
website needs a database. The product, customer and order details will be stored in a relational database.
TASK 4: DESIGN [6 Marks]
It was originally proposed that the following three relations were required:

− Product(Product_ID, Product_Name, Unit_Price, QuantityInStock)


− Order(Order_ID, Order_Date, Customer_ID, Product_ID, Quantity)
©2024/795/CSC/P3/CETA Page 4 of 6 TURN OVER
− Customer(Customer_ID, F_Name, L_Name, MoMo_Phone_No)
This document is the property of the CATA and should not be reproduced without the permission of the authors.
The computer programmer identified a problem with the Order relation
a) In your answer booklet, draw an Entity-Relationship diagram that shows entities, relationships and the degree of
each relationship for the database (3 Marks)
b) Describe the problem that the programmer identified with the Order relation and explain what the cause of this
problem was. (2 Marks)
c) Propose a solution to the identified problem above (1 Mark)
TASK 5: IMPLEMENTATION [19 Marks]
[Note: for the following subtasks, first write in your answer booklet the SQL queries (or statements) used to
implement its activities in your DBMS]
1. Using SQL statements, do the following using your favorite database management system (DBMS)
a) Create a database called FARMDB. (1 Mark)
b) In FARMDB, create all the relations obtained above including appropriate versions of all primary and foreign
key integrity constraints. The customer relation must be created with a constraint that the telephone number must
be 9 digits long and start with either 67, 65, 68 or 62. (4 Marks)
2. Using SQL commands:
a) Consider the data given below. Use it to populate each relation in the FARMDB database. Print all tables
(6 Marks)
− CUSTOMERS [ Record 1: {"Customer_ID": 1001, "F_Name": "Ngwa", "L_Name": "Ngosu", “MoMo_Phone_No":
67100100},
Record 2: {"Customer_ID": 1002, "F_Name": "Nji", "L_Name": "Jonasu", “MoMo_Phone_No": 67150115},
Record 3: {"Customer_ID": 1003, "F_Name": "Sone”,"L_Name": “Elvis", “MoMo_Phone_No ":
67190104}]
− ORDERS [ Record 1: {"Order_ID": 2001, "Customer_ID": 1001, "products": [{" Product_ID”: 1002, "quantity": 2}],
"Order_Date": "2023-08-05"},
Record 2: {"Order_ID": 2002, "Customer_ID": 1003, "products": [{" Product_ID”: 1001, "quantity": 1},{
“Product_ID”: 1003, "quantity": 2}], "Order_Date": "2023-08-04"}]
− PRODUCTS [ Record 1: {"Product_ID": 1001, "Product_Name": "Yams", "Unit_Price": 1500, “QuantityInStock": 30},
Record 2: {" Product_ID ": 1002, "Product_Name": "Plantains", "Unit_Price": 3000, “QuantityInStock ": 50},
Record 3: {" Product_ID ": 1003, "Product_Name": "Cassava", "Unit_Price": 1000, “QuantityInStock ": 20}]
b) Customer_ID 1002’s phone number was inaccurate. Write an SQL command to modify it from 67150115 to
671501150. Print the customer table after this modification (2 Marks)
3. Using SQL commands, write an SQL statement to query the database tables for each of the following:
a) Customer ID, First Name, Last Name along with the total amount spent by each customer since they started
buying from the website. Print the result (3 Marks)

©2024/795/CSC/P3/CETA Page 5 of 6 TURN OVER


This document is the property of the CATA and should not be reproduced without the permission of the authors.
b) Customer ID, First Name, Last Name for customers who have not placed any orders in the last 6 months. Print
the results (3 Marks)

©2024/795/CSC/P3/CETA Page 6 of 6 TURN OVER


This document is the property of the CATA and should not be reproduced without the permission of the authors.

You might also like