PDF Google Drive Downloader v1.1


Report a problem

Content text exercise for test2.pdf

2 Part A: ANSWER ALL SUBJECTIVE QUESTIONS (50 MARKS) 1. An array in C is a fixed-size collection of similar data items stored in contiguous memory locations. a) Declare a single dimension of floating point array, named ECG_record, which could store total of 1000 data. [2 marks] b) Declare a 2-dimension array, named matrix, with size as shown below and initialize its values accordingly. � 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 � [3 marks] c) Write a C code segment to sum up all the elements in matrix using for loop. [5 marks] 2. The structure in C is a user-defined data type that can be used to group items of possibly different types into a single type. a) Define a structure data type, named patient_info where it consists of three (3) data members as listed below: i. Name, with character array that could store 30 alphabets ii. age with integer datatype iii. medical_bill with float datatype. [5 marks] b) Declare an array of structure patient_info, named ICU_patients, which could store total of 30 patient records. [2 marks] c) Assume now there is an ICU patient who is stored as the second (2nd) record in ICU_patients is charged RM 15000 for his medical bill, write the correct C statement to perform this action. [3 marks]
SEBB 2033 Computer Programming for Biomedical Engineer Test 2 2023/2024-1 3 3. C programming supports multiple user-defined datatype, such as union, typedef and enum. a) JH is trying to write a code for her project but it would not compile. Identify at least three (3) syntax errors with line number stated and suggest the correct statement. [6 marks] b) Assume the user key in the value of 1001, what is the expected printf() output in line 25? [2 marks] c) What is the return value of sizeof(device)? [2 marks] 1. #include 2. #include 3. 4. int main() 5. { 6. union stock 7. { 8. char model[20]; 9. int qty; 10. } 11. 12. typedef stock item; 13. item device; 14. union stock *ptr = device; 15. 16. enum KPI (PASS, FAIL); 17. enum KPI status; 18. 19. printf("Please key in the quantity: "); 20. scanf("%d", &device.qty); 21. 22. if (ptr.qty > 1000) status = PASS; 23. else status = FAIL; 24. 25. printf("status = %d", status); 26. } 27.
SEBB 2033 Computer Programming for Biomedical Engineer Test 2 2023/2024-1 4 4. A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. Given the C code and memory content mapping shown in Figure 1, complete the Table 1 after program execution. Figure 1 Table 1 Variable Value a) &commission b) ptr1 c) *ptr2 d) *(price+1) e) price+2 [10 marks] price[1] qty #include int main() { int qty = 20, *ptr1 = NULL; float commission, *ptr2 = NULL; float price[3] = {30.0, 40.0, 50.0}; ptr1 = &qty; ptr2 = &commission; *ptr2 = *ptr1 * price[1]; return 0; } commission 6422016 price[0] price[2] ... ... ptr2 6422044 ptr1 6422028 ... ... RAM 6422032 6422004 ...
SEBB 2033 Computer Programming for Biomedical Engineer Test 2 2023/2024-1 5 5. Function is useful to manage a program by divide and conquer, source code reusability and modularity. On the other hand, variable scope refers to the accessibility of a variable in a given program or function. By referring to the coding given in Listing 1, provide the printf output from (a) to (e) by referring to the comments. Listing 1 [10 marks] #include int variable = 100; void update_variable1 (void); int update_variable2 (int x); int main() { int result = 0; printf("variable = %d\n", variable); //(a) { int variable = 50; update_variable1(); printf("variable = %d\n", variable); //(b) } printf("variable = %d\n", variable); //(c) result = update_variable2(variable); printf("variable = %d\n", variable); //(d) } void update_variable1 (void) { variable = variable + 100; } int update_variable2 (int x) { int variable = 0; variable = x * 3; printf("variable = %d\n", variable); //(e) return variable; }

Related document

x
Report download errors
Report content



Download file quality is faulty:
Full name:
Email:
Comment
If you encounter an error, problem, .. or have any questions during the download process, please leave a comment below. Thank you.