Sunteți pe pagina 1din 8

INTERNATIONAL ISLAMIC UNIVERSITY MALAYSIA

FINAL SEMESTER EXAMINATION


SEMESTER I, 2005/2006 SESSION
KULLIYYAH OF ENGINEERING

Programme : ENGINEERING Level of Study : UG 1

Time : 10.00 am – 11.30 am Date : 09/10/2005

Duration : 1 ½ Hr

Course Code : ECE 1113 Section(s) : Five (5)

Course Title : Computing Systems and Programming

This Question Paper Consists of Eight (8) Printed Pages (Including Cover Page) With
Six (6) Questions.

INSTRUCTION(S) TO CANDIDATES

DO NOT OPEN UNTIL YOU ARE ASKED TO DO SO

• The total mark of this examination is 50.


• This examination is worth 20% of the total assessment.
• There are Six (6) questions. Answer ALL questions.
• ALL answers must be written in the answer booklet provided.
• Answers should be clear and intelligible.
• Justify your answers with simplification of intermediate steps for full marks.

Any form of cheating or attempt to cheat is a serious


offence which may lead to dismissal.
Computing Systems and Programming FINAL ECE 1113

Section A [15 marks]


[Answer all the questions. Write your answers in the answer booklet provided]

Q.1) [15 marks] Objectives


Select the best answer for the following questions.

1. In C, the following equation is best representing by which statement? (1 mark)


1 2
Equation: distance = x0 + v 0 t + at
2
1
a) distance = x0 + v 0 * t + * a * pow( 2 , t );
2
1
b) distance = ( x 0 + v 0 ) * ( t + ) * a * pow( 2 , t );
2
1
c) distance = x0 + ( v 0 * t )+ ( * a * pow( t , 2 ));
2
1
d) distance = ( x 0 + v 0 * t) + ( * a * pow( t , 2 ));
2

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)

3. Find the answer for the following statement. (1 mark)


int x = 5, y = 5, z, sum;
z = x++ * y%3;
sum = z + x + --y ;
a) 16
b) 20
c) 21
d) 22

4. Which of these is true if x is 10? (1 mark)


a) (x>=0) && (x<10)
b) (!(x>10)) || (x<=100)
c) !(x>=0) && (x<10)
d) !(x= =10) || (x!=10)

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

function call function definition


a) prog(x , n) double prog(double y, int m)
b) prog(y , m) double prog(double x, int n)
c) prog(y , m) double prog(int x, double n)
d) prog(x , n) double prog(double y, double m)

6. What will be printed when the following code is executed? (1 mark)


#include<stdio.h>
int main()
{ int sum=0;
for(int i=0;i<5;i++);
sum+=i;
printf("Sum=%d\n",sum);
return 0;
}
a) Sum=0
b) Sum=4
c) Sum=5
d) Sum=10

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)

9. An individual element in the array is addressed by specifying (1 mark)


a) the name of the array
b) the number of the element within the array followed by the name of the array
c) the number of the element in the array
d) the name of the array and the number of the element

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

Section B [10 marks]


[Answer all the questions. Write your answers in the answer booklet provided]

Q.2) [5marks] Program Error Correction


Find and fix ten errors in the following code. Please indicate the line number of the error
statement.

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

Q.3) [5 marks] Program Output


Write the output of the following program.

#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;

printf("Data items in original order\n");

for (i=0; i<SIZE; i++)


{
printf("%4d",a[i]);
}
printf("\n\n");

for (pass=0; pass<SIZE; pass++)


{
for (i=0; i<SIZE; i++)
{
if (a[i] > a[i+1])
{
hold = a[i];
a[i] = a[i+1];
a[i+1] = hold;
}
}
}

printf("New arrangement of data items\n");

for (i=0; i<SIZE; i++)


{
printf("%4d",a[i]);
}
printf("\n\n");

return 0;
}

Section C [10 marks]


[Answer all the questions. Write your answers in the answer booklet provided]

Q.4) [5marks] Guided Program Writing


Write a simple program by following the given instructions.

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

1) that declare, define and initialize a structure of Malaysia


2) that has three data members. The data members are the name of the island as
character string, the year the island is discovered as integer and the size of the island
as double.
3) Print data for one of the island only.

6
Computing Systems and Programming FINAL ECE 1113

Q.5) [5 marks] Convert Program


Write again the following program using array notation to replace all pointer notation.

#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;
}

Section D [15 marks]


[Answer all the questions. Write your answers in the answer booklet provided]

Q.6) [15 marks] Program Writing

R1a R2a R3a R4a

R1b R2b R3b R4b

R1c R2c R3c R4c

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

Where, all resistors values are 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.

S-ar putea să vă placă și