CS706 Assignment No 2 2018 help and guideline video will help you how to detect the defects and errors in given c++ code and to decide what type of cohesion is used in the given cases. in this video Another old sample code is shared and errors are suggested. this video guideline will explain what are type of errors and what are different types of cohesion.
CS706 Assignment No 2 2018 Question
Q# 01: (Marks: 20)
Read the following C/C++ code carefully and identify errors/defects (not syntax/compile time errors) and explain each defect (at most 3 lines each).
1. #include<stdio.h>
2. #include<conio.h>
3. void swap(int* a, int* b)
4. {
5. int t = *a;
6. *a = *b;
7. *b = t;
8. }
9. int partition (int arr[], int low, int high)
10. {
11. int pivot = arr[high]; // pivot
12. int i = (low - 1); // Index of smaller element
13. for (int j = low; j <= high + 1; j++)
14. {
15. if (arr[j] >= pivot)
16. {
17. i--;
18. swap(&arr[i], &arr[j]);
19. }
20. }
21. swap(&arr[i + 1], &arr[high]);
22. return (i + 1);
23. }
24. void quickSort(int arr[], int low, int high)
25. {
26. if (low < high)
27. {
28. int pi = partition(arr, low, high);
29. quickSort(arr, low, pi - 1);
30. quickSort(arr, pi + 1, high);
31. }
32. }
33. void printArray(int arr[], int size)
34. {
35. int i;
36. for (i=0; i < size; i++)
37. printf("%d ", arr[i+1]);
38. printf("\n");
39. }
40. int main()
41. {
42. int arr[] = {10, 7, 8, 9, 1, 5};
43. int n = sizeof(arr)/sizeof(arr[0]);
44. quickSort(arr, n-1,0);
Common errors found in this code are :
- no exception handling
- no comments are used
- no indentation is used
- no pre and post conditon are used
Q# 02: (Marks: 10)
Cohesion is the qualitative indication of the degree to which a module focuses on just one thing. Functional, temporal, procedural and communicational cohesion are some of the Levels/Ranges of cohesion. You are required to identify the type of cohesion that the following statements represent. Justify your answer with solid reason.
- A function/routine that initializes data used by many modules throughout a system. All the parameter which require initialization are set to their starting values irrespective of their functional relationship are initialized in this function/routine. (communication)
- Suppose there is a module which intends to repair the damaged record of the database and then update the maintenance file. (temporal)
- Suppose a complex module A which have numerous sub modules like a1, a2, a3 etc. and all sub module of module A are only performed to carry out the task of the parent module (i.e module A) (Functional
CS706 Assignment No 2 2018 Video