Documente Academic
Documente Profesional
Documente Cultură
Duration : 1 ½ Hr
This Question Paper Consists of Eight (8) Printed Pages (Including Cover Page) With
Six (6) Questions.
INSTRUCTION(S) TO CANDIDATES
2. The difference between the source program and the object program is
a) the source program can be executed, and the object program cannot be executed.
b) the source program is the original code and the object program is a modified
code.
c) the object program is also a source program.
d) the source program is specified in a high- level language, and the object program
is specified in machine language. (1 mark)
5. A program is written with programmer define function that take double data type x and int
n to control the for loop. x and n is in the actual parameter and y and m is in the formal
parameter. The function is referred by call_by_value. Which C statement is best describe
the above statements? (1 mark)
2
Computing Systems and Programming FINAL ECE 1113
7. What is the new value of count after the following statements is executed. (1 mark)
int count = 750;
……
if (count>0)
if (count>=1000)
count=0;
else
if (count <500)
count*=2;
else
count*=10;
else
count+ =3;
a) 0
b) 1500
c) 7500
d) 753
8. Which of the following will generate a floating random number between -5.5 and 5.5
a) ((double)rand()/RAND_MAX)*(11)-5.5
b) ((double)rand()/RAND_MAX)*(-11)-5.5
c) ((double)rand()/RAND_MAX)*(12)-5.5
d) ((double)rand()/RAND_MAX)*(12)+5.5 (1 mark)
3
Computing Systems and Programming FINAL ECE 1113
10. A 2-D array with the size of A[5][4]. The array element of A[ 3 ][ 2 ] can be refer by
pointer variable with which statement? (1 mark)
a) *(ptr + 17);
b) *(ptr + 11);
c) *(ptr + 14);
d) *(ptr + 24);
11. Find the equivalent statement for declaring and initializing the character string
filename = sensor;
a) char filename[ 12 ] = “sensor”;
char filename[ 12 ] = {‘s’,’e’,’n’,’s’,’o’,’r’};
b) char filename[ 12 ] = (‘s’,’e’,’n’,’s’,’o’,’r’,’\0’);
char filename[ 12 ] = “sensor”;
c) char filename[ ] = “sensor”;
char filename[ 12 ] = {“sensor”};
d) char filename[ 12 ] = “sensor”;
char filename[ ] = {‘s’,’e’,’n’,’s’,’o’,’r’,’\0’}; (1 mark)
12. Which statements are invalid statement while working with variable pointer? (1 mark)
I. ptr_1 = &y;
II. &y = ptr_1;
III. *ptr_1 = ptr_2;
IV. *ptr_1 = *ptr_2;
a) I and II only
b) I and III only
c) II and III only
d) III and IV only
13. Assume that y and z are pointers to integers and that y points to the variable score.
Choose the sentence that best describes the effect of this statement: z = y;
a) The value of score is copied into z.
b) The memory address stored in y is copied into z.
c) The memory address stored in z is copied into y.
d) The pointer y is now pointing to a different variable. (1 mark)
14. By referring to the following statement, what are the values of a1, a2,*p1,*p2?
int a1, a2;
int *p1, *p2;
…..
a1 = 5;
p1 = &a1;
a2 = *p1/2 + 10;
p2 = p1;
a) 5,13,5,5
b) 5,13,13,13
c) 5,12,5,5
d) 5,12,12,12 (1 mark)
4
Computing Systems and Programming FINAL ECE 1113
15. In structure there are two way of initializing the data members. The data members
can be initialized using (1 mark)
a) address statements and program statements
b) structure statements and data statements
c) initialization statements and declaration statements
d) program statements and declaration statements
1 //This program uses a function to find the maximum of two values entered by user.
2 #include<stdio>
3 int Max(int value1:int value2);
4 int main()
5 {
6 int inputValue1,inputValue2,maxValue;
7
8 printf("Please enter a number and press Enter:");
9 scanf("%lf",&inputValue1);
10 printf("Please enter another number and press Enter:");
11 scanf("%d",inputValue2);
12
13 maxValue=Max(InputValue1,inputValue2);
14 printf("\n");
15 printf("The maximum of the two values you typed");
16 printf("in was: %d\n",);
17 return 0;
18
19 int Max(int value1,int value2);
20 {
21 int maxValue;
22 if(value1>value2);
23 {
24 maxValue=value1;
25 }
26 else
27 {
28 maxValue=value2;
29 }
30 return Max;
31 }
5
Computing Systems and Programming FINAL ECE 1113
#include <stdio.h>
#define SIZE 10
int main()
{
int a[SIZE]={2, 6, 4, 8, 10, 12, 89, 68, 45, 37};
int pass, i, hold;
return 0;
}
Malaysia has a few tourist islands. As a programmer you want to develop a program to
keep some of the data about the island. Develop a program
6
Computing Systems and Programming FINAL ECE 1113
#include<stdio.h>
int main()
{
int data1[3][5]={{2,4,6,8,10},{1,3,5,7,9},{5,10,15,20,25}};
int sum=0;
int *p_data=&data1[0][0];
for(int h=0;h<15;h++)
{
printf("%2d ",*(p_data+h));
if(h= =4||h= =9||h= =14)
printf("\n");
sum+=*(p_data+h);
}
printf("Sum=%d\n",sum);
return 0;
}
Figure 1
The circuit in Figure 1 is a series parallel circuit. The total resistance of any one branch is
RTb1 = R1a + R1b + R1c , RTb1 = Total branch 1 resistance in ohms
RTb2 = R2a + R2b + R2c , RTb2 = Total branch 2 resistance in ohms
RTb3 = R3a + R3b + R3c , RTb3 = Total branch 3 resistance in ohms
RTb4 = R4a + R4b + R4c , RTb4 = Total branch 4 resistance in ohms
7
Computing Systems and Programming FINAL ECE 1113
The total resistance of any parallel branch is found by first determining the total resistance
of that branch and then using the parallel resistance formula for finding the total resistance.
The formula is
RT = 1/(1/ RTb1 + 1/ RTb2 + 1/ RTb3 + RTb4)
Where
RT = Total resistance in ohms
RTb1 , RTb2 , RTb3 and RTb4 are total branch resistance in ohms
Write a program to ask a user to input the values of all resistors for all branches. Input the
values in 1-D array, each array for each branch. You are required to
a. Write a programmer defined function to calculate for the total resistance of each
branch. Print the result to the screen using the main function.
b. Write another programmer defined function to calculate for the total parallel
resistance using the parallel resistance formula. Print the result to the screen using
the main function.
c. Ask the user whether he/she wants to enter for new values of resistance, in which
case you have to calculate for the new total resistance of each branch and the new
total parallel resistance, and print the results to the screen.