Case_study_set2
Case_study_set2
Paix-Travail-Patrie Peace-Work-Fatherland
------- -------
MINISTERE DE L’ENSEIGNEMENT SUPERIEUR MINISTRY OF HIGHER EDUCATION
------- -------
COMMISION NATIONALE D’ORGANISATION DE NATIONAL COMMISSION FOR THE ORGANISATION
L’EXAMEN HIGHER NATIONAL DIPLOMA EXAM (HND) OF THE HIGHER NATIONAL DIPLOMA EXAM (HND)
------- -------
b. Display how you can manually execute the above flowchart, after the value of n has been read (2 marks)
as n =5. Display the output obtained.
2. The data below depicts the steps taken by a certain sorting algorithm to sort the list of integers:
88, 46, 25, 11, 18, 11 and 22. Study the data and answer the questions that follow.
INPUT: [88, 46, 25, 11, 18, 11, 22] // (initial list)
Pass 1: [46, 25, 11, 18, 11, 22,| 88] Pass 2: [25, 11, 18, 11, 22, |46, 88]
Pass 3: [11, 18, 11, 22, |25, 46, 88] Pass 4: [11, 11, 18, |22, 25, 46, 88]
Pass 5: [11, 11, |18, 22, 25, 46, 88] Pass 6: [11,| 11, 18, 22, 25, 46, 88]
OUTPUT: [11, 11, 18, 22, 25, 46, 88] // (sorted list)
Page 1 | 6
a. State which of the sorting algorithm is applied on the set of data above, and explain its working (2 marks)
principle.
b. The size of the input is 7 and results in 6 passes. In the first pass we have (7-1) comparisons (3 marks)
and so on… The total running time of this algorithm is obtained by summing up the terms
representing each comparisons. If the size of the input list is now n,
𝒏(𝒏−𝟏)
Show that the total number of comparisons is T(n) = ∑𝒏−𝟏
𝟏 (𝑲) = and Explain why the
𝟐
2
time complexity for the above algorithm is O(n ) or a quadratic complexity.
II- STRUCTURED PROGRAMMING (15 marks)
1. Copy and fill the table below (2 marks)
Expression/Operation Types of operator used Result
A= (2 == 4) && (5!= 1) A=?
B= (7 > 1) || (9 < 1) B=?
C= !(9 == 4) C=?
m = 9, x = m++ m=? x=?
2. The code snippet below shows the definition of a recursive function called mystery. The final line
of code displays the output returned when mystery is called with an argument of 4.
1 function mystery(n) {
2 if (n = = 0)
3 return 1;
4 else return n *mystery(n-1);
5 }
6 // main program
7 printf(“%d”, mystery(4));
a. What makes the function mystery a recursive function? (1 mark)
b. What difference do you make between recursion and iteration? (2 marks)
c. Which value is displayed when the main program calls the mystery function at line 7? (1 mark)
d. Replace the name mystery of the function by an appropriate one, considering the value in c. (1 mark)
e. Write the iterative counterpart of the mystery function. (2 marks)
3. What difference do you make between passing parameters by value and by address? Illustrate (3 marks)
your answer with a code snippet.
4. Write a code snippet that reads and displays the content of a 2-dimenssional array in C language. (3 marks)
4. Consider the incomplete C++ program below. The program request the user to enter a number,
an operator, and another number. It then carries out the specified arithmetical operation: adding,
multiplying, or dividing the two numbers. (It uses a switch statement to select the operation).
Finally it displays the result. When it finishes the calculation, the program ask if the user
wants to do another calculation. The response can be ‘Y’ or ‘N’.
Page 2 | 6
1. #include<iostream>
2. //#include<conio.h>
3. using namespace std;
4. class Calculator {
5. float m,n; // To store the 2 operands
6. char oper; // To store the operator
7. double ans; // To store the answer of the operation
8. void sum();
9. void sub();
10. void mul();
11. void div();
12. void disp(); // To display the answer
13. public:
14. void input(); // to input operands and operator
15. void evaluate();
16. };
17. void Calculator::input() {
18. // code to be implemented out of the class
19.
20. }
21.
22. void Calculator::evaluate() {
23. switch (oper)
24. {
25. // call the function that correspond to the operator switched and display the result.
26. }
27. }
28.
29. void Calculator::disp()
30. {
31. cout<<"Answer = "<<ans;
32. }
33. int main( )
34. {
35.
36. return 0;
37. }
We assuming that the process of writing the member functions sum(), sub(), mul(), div() are the
same.
a. Write the bodies of the member functions input(), sum() and evaluate(). (4 marks)
b. Guess an error message the compiler can generate if we attempt to initialize an object in this (1 mark)
manner: obj.m=10, obj.n=2 and obj.oper =''+'' in the main function.
c. Write the main function, where you create an object of type Calculator, call the appropriate (4 marks)
function to set the member variable of the created object, call another appropriate member
function to perform the calculation and display the result. NB: the process can be repeated
as many times until the user decide to quit the program.
Page 3 | 6
Sample output below:
Enter first number: 3 Enter first number: 4 Enter first number: 5
Enter operator: + Enter operator: / Enter operator: *
Enter second number: 2 Enter second number: 2 Enter second number: 4
Answer = 5 Answer = 2 Answer = 20
Do another (Y/N)? Y Do another (Y/N)? y Do another (Y/N)? N
5. Draw a class diagram representing a book defined by the following statement: “A book is (4 marks)
composed of a number of parts, which in turn are composed of a number of chapters. Chapters
are composed of sections.” Add multiplicity to the class diagram you will produce, and also
include some possible attributes.
Page 4 | 6
b. Based on the above, indicate for each of the following potential functional dependencies, (2 marks)
whether it is indeed a FD or not: 1. {ID}→{title}; 2. {startpage}→{endpage};
3. {journal issue}→{year} 4. {title→ID}; 5. {ID}→{startpage endpage journal issue};
6. {TR-ID}→{ID}
1 2 3 4 5 6
FD
Not a FD
c. Based on (a) and (b), perform normalization into BCNF, and state the resulting relations. (3 marks)
d. Reverse back the Model obtained as result in (c) to design its corresponding ER-Model. (3 marks)
e. Indicate for each of the following queries, how many tuples would be returned if it was run (2 marks)
on the instance of Articles.
1.SELECT ID FROM Articles WHERE year<2006;
2.SELECT DISTINCT ID FROM Articles WHERE year<2006;
3.SELECT AVG(year) FROM Articles GROUP BY journal;
4.SELECT ID FROM Articles WHERE title LIKE'%d';
1 2 3 4
Number of tuples
Page 5 | 6
in the LAN needs access to the Internet”.
d. Name the additional hardware needed to provide access to the Internet. (1 mark)
• “With the Internet connection, I am concerned that we will get unauthorized access to our
LAN.”
e. Name the hardware and/or software needed to prevent unauthorized access. (2 marks)
• “Customer Services staff must be able to get access to a centralized store of customer data.
Our business deals with thousands of customers. They produce millions of transactions.”
f. Explain what hardware and software will be needed to enable this. (2 marks)
Page 6 | 6