Đề thi học kỳ II môn Kỹ thuật lập trình - Mã đề: F18201 - Năm học 2017-2018

Q.1. The source code of a C program is written and stored in the “program.c” file. What

needs to be done to see the execution of this C program?

a. Translate the C source code into its corresponding machine code using a C compiler

and then execute the machine code.

b. Rewrite the C source code to obtain its corresponding machine code, compile the

machine code using a machine compiler and then execute the machine code.

c. Draw a flowchart corresponding to the C source code and then view the flowchart.

d. Rewrite the C source code to obtain its corresponding pseudo code and then execute

the pseudo code.

e. Others

Đề thi học kỳ II môn Kỹ thuật lập trình - Mã đề: F18201 - Năm học 2017-2018 trang 1

Trang 1

Đề thi học kỳ II môn Kỹ thuật lập trình - Mã đề: F18201 - Năm học 2017-2018 trang 2

Trang 2

Đề thi học kỳ II môn Kỹ thuật lập trình - Mã đề: F18201 - Năm học 2017-2018 trang 3

Trang 3

Đề thi học kỳ II môn Kỹ thuật lập trình - Mã đề: F18201 - Năm học 2017-2018 trang 4

Trang 4

Đề thi học kỳ II môn Kỹ thuật lập trình - Mã đề: F18201 - Năm học 2017-2018 trang 5

Trang 5

Đề thi học kỳ II môn Kỹ thuật lập trình - Mã đề: F18201 - Năm học 2017-2018 trang 6

Trang 6

Đề thi học kỳ II môn Kỹ thuật lập trình - Mã đề: F18201 - Năm học 2017-2018 trang 7

Trang 7

Đề thi học kỳ II môn Kỹ thuật lập trình - Mã đề: F18201 - Năm học 2017-2018 trang 8

Trang 8

Đề thi học kỳ II môn Kỹ thuật lập trình - Mã đề: F18201 - Năm học 2017-2018 trang 9

Trang 9

Đề thi học kỳ II môn Kỹ thuật lập trình - Mã đề: F18201 - Năm học 2017-2018 trang 10

Trang 10

Tải về để xem bản đầy đủ

pdf 16 trang xuanhieu 10920
Bạn đang xem 10 trang mẫu của tài liệu "Đề thi học kỳ II môn Kỹ thuật lập trình - Mã đề: F18201 - Năm học 2017-2018", để tải tài liệu gốc về máy hãy click vào nút Download ở trên

Tóm tắt nội dung tài liệu: Đề thi học kỳ II môn Kỹ thuật lập trình - Mã đề: F18201 - Năm học 2017-2018

Đề thi học kỳ II môn Kỹ thuật lập trình - Mã đề: F18201 - Năm học 2017-2018
 Vietnam National University - Ho Chi Minh City 
 Ho Chi Minh City University of Technology 
 FINAL EXAMINATION 
Course: Programming Fundamentals CourseID: CO1003 
Date: Friday, June 01, 2018 Exam Code: 
Time: 90 minutes 
Type: closed-book examination with no electronic equipment F18201 
Student Name: Student Identifier: 
General information: 
 - This examination includes three parts. Part A consists of 24 multiple choice questions 
 each of which has a max grade of 0.25. Part B consists of 2 writing questions. Part C is 
 your answer area. 
 - For the questions in Part A, please use a mark (check or cross-check) for an answer with 
 a, b, c, or d. If you have another answer that does not match any among a, b, c, and d, 
 please choose e. Others and then write your answer in the Others answer section. If you 
 make another choice, please delete your previous choice by marking a deletion on it. If 
 you choose an answer and then delete it multiple times, please write your final answer to 
 that question explicitly in Part C. 
 - For the questions in Part B, programs in your answers must be written in the C language 
 and the coding style must be considered. 
 - For any comments or suggestions on the examination, please feel free to write them down 
 at the end of Part C. 
Part A. Multiple choice questions 
Q.1. The source code of a C program is written and stored in the “program.c” file. What 
needs to be done to see the execution of this C program? 
a. Translate the C source code into its corresponding machine code using a C compiler 
and then execute the machine code. 
b. Rewrite the C source code to obtain its corresponding machine code, compile the 
machine code using a machine compiler and then execute the machine code. 
c. Draw a flowchart corresponding to the C source code and then view the flowchart. 
d. Rewrite the C source code to obtain its corresponding pseudo code and then execute 
the pseudo code. 
e. Others 
 1 
 Vietnam National University – Ho Chi Minh City 
 Ho Chi Minh City University of Technology 
Q.2. Which device is not an input device? 
a. network connection b. a file in the hard disk c. keyboard d. printer 
e. Others 
Q.3. Which definition is valid for a constant variable that keeps an integer value for the 
maximum number of products in a shop? 
a. const int pro_Max_Num = 10000; c. int max_number1 = 10000; 
b. float _Number_of_Products = 10000; d. const int _pro_Max# = 10000; 
e. Others 
Q.4. Given two variables: aVar1 of the int data type and aVar2 of the double data type, 
which expression has been determined with truncation? 
a. aVar1 = aVar2-10; c. aVar1 + aVar2/10 
b. aVar2 = aVar1-10; d. aVar2 + aVar1/10
e. Others 
Q.5. Given variables: aPtr, aVal, and anExp, which expression is incorrect? 
a. ('A' + 32)*5/aVal b. (aVal/10 + *aPtr)*10-'2'/anExp
c. (aVal'p' + 's')/2 - *aPtr d. (anExp - aVal)/8 + 'B' 
e. Others 
Q.6. Given a variable a of struct location defined as follows: 
struct location { 
 int x, y; 
} a; 
Which function call allows receiving the values of the members of this variable input by 
a user from the keyboard? 
a. scanf("%d%d", (&a).x, (&a).y); c. scanf("%d%d", &a.x, &a.y); 
b. scanf("%d%d", a.x, a.y); d. scanf("%d%d", *a.x, *a.y); 
e. Others 
 2 
Q.7. Which function call allows printing two integer numbers in variables var1 and var2 
with their signs and separated from each other by a horizontal tab? 
a. printf("%+d\t%+d", var1, var2); c. printf("%+d\t+d", var1, var2); 
b. printf("%+d%+d", var1, var2); d. printf("%d\t%d", var1, var2);
e. Others 
Q.8. Given the following flowchart, what are its corresponding statements? 
a. if (grade>=5.0) sum += grade; c. if (grade>=5.0) { 
 else printf("%f", sum); printf("%f", sum); 
 scanf("%f", &grade); } 
b. if (grade>=5.0) else { 
 sum += grade; sum += grade; 
 scanf("%f", &grade); scanf("%f", &grade); 
 else printf("%f", sum); } 
 d. if (grade>=5.0) sum += grade; 
 printf("%f", sum); 
 scanf("%f", &grade); 
e. Others 
 3 
Q.9. Given that a, b, and c are input as even integer numbers, what is printed on screen? 
 if (a%3+1) 
 if (b%2) printf("***"); 
 else if (c%2) printf("&&&"); 
 else printf("###"); 
 else printf("$$$"); 
a. *** b. &&& c. ### d. $$$ 
e. Others 
Q.10. Given a switch statement as follows, what is printed on screen? 
 int m = 4; 
 switch (m) { 
 case 2: printf("%d", m+2); break; 
 case 4: printf("%d", m+4); 
 case 6: printf("%d", m+6); break; 
 case 8: printf("%d", m+8); 
 default: printf("%d", m); 
 } 
a. 4 b. 8 c. 10 d. 810 
e. Others 
Q.11. Given the following statements, what should be written at (11) to print 
all the numbers that are equal to 3*k + 1 for any integer number k >= 0 on screen? 
 int i, N=100; 
 for (i=0; i<=N; i++) (11) 
a. if (i == 3*k+1) printf("%d\n", i); c. printf("%d\n", 3*i+1); 
b. if (3*i+1) printf("%d\n", 3*i+1); d. if (i%3==1) printf("%d\n", i); 
e. Others 
Q.12. Given the following statements, what is the value of sum after the execution of the 
for statement? 
 4 
 int j, M=100, sum=0; 
 for (j=0; j<M; j++) { 
 if (j%3) continue; 
 if (j*j>=M) break; 
 sum += j*j; 
 } 
a. 0 b. 9 c. 45 d. 126
e. Others 
Q.13. Complete the following statements with (13.1)  and (13.2)  to print all the 
prime numbers less than 100. Using: int i, j; 
 for (i=2; i<100; i++) { 
 for (j=2; j<=i/2; j++) 
 (13.1) .. 
 if (13.2). 
 }
a. (13.1) if (i%j) break; 
 (13.2) if (i==2 || j>i/2) printf("%d\n", i); 
b. (13.1) if (i%j==0) break; 
 (13.2) if (j==2 || j>i/2) printf("%d\n", i); 
c. (13.1) if (i%j==0) break; 
 (13.2) if (j>i/2) printf("%d\n", i); 
d. (13.1) if (i%j) break; 
 (13.2) if (j>i/2) printf("%d\n", i);
e. Others 
Q.14. Given the following code segments, rearrange them into a sequence from the left to 
the right to obtain a valid function checking if a digit aDigit is contained in an integer 
number aNumber. 
 5 
 int isContained(int aNumber, int aDigit) { 
 . 
 return 0; 
 } 
(i). while (aNumber>0); 
(ii). int curDigit; 
(iii). do { 
 curDigit = aNumber%10; 
 if (curDigit == aDigit) return 1; 
 aNumber /=10; 
 } 
(iv). aNumber<0?-aNumber:aNumber; 
a. (i), (ii), (iii), (iv) b. (ii), (iv), (iii), (i) c. (iv), (ii), (i), (iii) d. (ii), (iii), (i), (iv) 
e. Others 
Q.15. What is a valid function call to invoke the aforementioned function isContained? 
a. int d = 3, num = 12345, result = isContained (num, d); 
b. int d = 0, num = -12345, result = isContained (num; d); 
c. int d = 3, num = -12345, result = isContained (&num, &d); 
d. int d = 0, num = 12345, result = isContained (*num, *d); 
e. Others 
Q.16. Which definition gives us an array of 10 integer numbers? 
a. int array[] = {-5, -10, 5, 10, 15, 20}; c. int array[] = {2, 4, 6, 8, 0, 1, 3, 5, 9, -1}; 
b. int array[][10] = {{0}, {1, 2, 3}}; d. Unknown due to lack of descriptions 
e. Others 
Q.17. What is returned by sizeof(array) whereas array is defined in Q.16? Given 
sizeof(int) returns 4. 
a. 4 b. 10 c. 40 d. Unknown
e. Others 
 6 
Q.18. Given the following statements, complete the code at (18)  to print all the 
elements in the array of 10 integer numbers in Q.16 that are greater than another integer 
number q. 
 int i, q; 
 for (i=0; i<10; i++) (18) . 
a. if (array[i] > q) printf("%d\n", array[i]); c. if (array[i] <= q) printf("%d\n", array[i]); 
b. if (array[i] > q) printf("%d\n", q); d. if (array[i] <= q) printf("%d\n", q); 
e. Others 
Q.19. Given the following function that can sort the elements of an array in ascending 
order, what is a valid function call to sort the elements of the array in Q.16? 
 void sort(int a[], int n) { 
 int i, j; 
 for (i=0; i<n-1; i++) { 
 int t = i+1, temp = a[i]; 
 for (j=i+1; j<n; j++) 
 if (a[j]<a[t]) t = j; 
 a[i] = a[t]; 
 a[t] = temp; 
 } 
 }
a. sort (array, 10); c. sort (*array, 10); 
b. sort (array[10], 10); d. sort (array; 10);
e. Others 
Q.20. Which definition gives us a pointer that points to a memory location of 5 integer 
numbers in the heap memory? 
a. int* pInt = (int*) malloc(5*sizeof(int)); 
b. int a[5]; 
 int* pInt = a; 
 7 
c. int** pInt = (int**) calloc(5, sizeof(int*)); 
d. int* pInt; 
e. Others 
Q.21. Given the following program, what is printed on screen? 
 #include 
 int func(int n) { 
 if (n<=1) return n; 
 return func(n-1) + func(n-2); 
 } 
 void main() { 
 int result = func(8); 
 printf("%d", result); 
 }
a. 13 b. 21 c. 34 d. 54 
e. Others 
Q.22. Given the following statements, what are incorrect? 
 int anInt = 5; 
 char aChar = 'A'; 
 const int* pInt = &anInt; 
 void* pVoid = &aChar; 
 int** ppInt = &pInt; 
 *pVoid += *pInt; //(i) 
 *pInt += 2; //(ii) 
 pInt = pVoid; //(iii) 
 **ppInt += **pInt - 3; //(iv)
a. (i), (ii), (iii), (iv) b. (i), (ii), (iv) c. (i), (ii) d. (ii), (iii) 
e. Others 
 8 
Q.23. Given the following function, what can be done from the execution of this function 
if the function is invoked using array1 and array2 which are two arrays each of which 
contains 10 integer numbers: func(array1, array2, 10)? 
 int func (int *a, int *b, int n) { 
 int i; 
 for (i=0; i<n; i++) 
 if (*(a+i)!=*(b+i)) return 0; 
 return 1; 
 } 
a. Check if two arrays have the same indices. 
b. Check if two arrays have the same addresses. 
c. Check if two arrays have the same elements. 
d. Check if two arrays have the same size. 
e. Others 
Q.24. Given the following function calls, which one writes a character and an integer 
number contained in variables aChar and anInteger, respectively, into a formatted text 
file controlled by pFile? 
a. fprintf (pFile, "%c%d", aChar, anInteger); 
b. fwrite (aChar, anInteger, sizeof(aChar) + sizeof(anInteger), 1, pFile); 
c. fscanf (pFile, "%c%d", &aChar, &anInteger); 
d. fputs ("%c%d", aChar, anInteger, pFile); 
e. Others 
Part B. Writing questions 
Q.25. Given the following formula to approximate the value of 1/(1-x) where x is a 
floating-point number in [0, 1) (i.e. x is greater than or equal to 0 and x is less than 1): 
 9 
You are asked to: 
25.a. Write a recursive function to implement this approximation with the first N 
elements in the series. (1 points) 
25.b. Write a program to approximate the value of 1/(1-x) with the first N elements in the 
series where N is a positive integer number and x is a floating-point number input by the 
user and checked in [0, 1) using your recursive function defined above. (1 points) 
Q.26. It is supposed that a supermarket keeps track of the shopping of each customer 
with respect to each product in the warehouse. The supermarket knows how many items 
of the same product each customer has bought so far. The manager of the supermarket 
wants to examine what product is the best sold and what not. Therefore, you are asked to 
write a program to support this manager as follows. 
26.a. Define a multi-dimensional array to keep the number of items of each product that 
each customer has bought so far. (0.5 points) 
26.b. Write a function to extract the products that have not yet been bought by any 
customer using pseudo code and C code as follows: 
26.b.1. Write a function using your pseudo code (0.5 points) 
26.b.2. Write a function using the real code in C (1 points) 
26.c. Write a function to extract the products that have been bought by the largest number 
of the customers using pseudo code and C code as follows: 
26.c.1. Write a function using your pseudo code (0.5 points) 
26.c.2. Write a function using the real code in C (1 points) 
26.d. Write a program with a menu for this manager to select the calculation in either 
26.b.2 or 26.c.2 and view the corresponding result. (0.5 points) 
 Faculty/Department: Lecturer: Dr. Vo Thi Ngoc Chau 
 10 
 Name: . ID:  Exam Code: F18201 
 Part C. Answer section 
 C.1. Answers for the multiple choice questions: 
Answer 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 
 a 
 b 
 c 
 d 
Others 
 C.2. Area for writing the Others answers of the multiple choice questions (1-24) that are 
 different from a, b, c, and d choices and the answers of the writing questions (25-26): 
 11 
12 
13 
14 
15 
16 

File đính kèm:

  • pdfde_thi_hoc_ky_ii_mon_ky_thuat_lap_trinh_ma_de_f18201_nam_hoc.pdf