You are on page 1of 5

CONFIDENTIAL EE/DEC 2022/ECE128

UNIVERSITI TEKNOLOGI MARA


WRITTEN TEST

COURSE : COMPUTER PROGRAMMING


COURSE CODE : ECE128
EXAMINATION : 8 DECEMBER 2022
TIME : 1.5 HOURS

INSTRUCTIONS TO CANDIDATES

1. This question paper consists of 3 Questions

2. Answer ALL questions in the Answer Sheet.

NAME
STUDENT ID GROUP
LECTURER
QUESTION CLO-PLO MARKS
1a CLO1-PLO1
1b CLO1-PLO1
2a CLO1-PLO1
2b CLO1-PLO1
3a CLO1-PLO1
3b CLO1-PLO1

TOTAL MARKS

DO NOT TURN THIS PAGE UNTIL YOU ARE TOLD TO DO SO


This examination paper consists of 5 printed pages
© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL
CONFIDENTIAL 2 EE/JAN 2021/ECE128

QUESTION 1
a) Answers True or False for the following statements;

i. The statement that defines an integer variable called is;


int var1;
ii. The statement below is correct;
int a = b = c = 3;
iii. The following program code will display only “IM HERE” regardless of the condition
result;
if (~condition result is TRUE~)
printf (“IM HERE”);
printf (“IM OUT”);
iv. The default case is optional while using switch selection structure.
v. The repetition statement below will repeat only 1 time;
for(i=0;i<1;i++)
vi. The break statement causes the iteration of the enclosing for, while, or do...while
statement terminates the loop immediately.

(6 marks)

b) Refer to the Listing Q1b, identify the missing statement or expression inside each of the
following programs. The corresponding output is given in the Figure Q1b.
(4 marks)

Source Code
void main()
{
int val;
printf(“ (i) ”);
scanf (“%d”,___(ii)___);

//Selective structure
if(___(iii)___)
printf(“\nYou have enter even number”);
else
printf(“\nYou have enter odd number”);
___(iv)___
;
}
Listing Q1b

Please enter number between 1 to 10:5


You have enter odd number

Figure Q1b

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 3 EE/JAN 2021/ECE128

QUESTION 2

a) Listing Q2a shows the program that is used to identify students’ intake year based on
matrix number. Illustrate the flowcharts that represent the selective statement only from
the source code given below.
(4 marks)

Source Code
#include <stdio.h>
#include <stdlib.h>

int main()
{
int matrixFirst;
int matrixLast;

printf("Please enter your 10 digit matrix number: ");


scanf("%4d%6d",&matrixFirst,&matrixLast);

//selective statement start from here


if (matrixFirst==2021)
printf("Your intake is 2021\n");
if (matrixFirst==2022)
printf("Your intake is 2022\n");
else
printf("Invalid!\n");

return 0;
}

Listing Q2a

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 4 EE/JAN 2021/ECE128

b) Modify program shown in Listing Q2b with the equivalent program by replacing switch
with if…else..if statement.
(6 marks)

int main()
{
char input;
printf( “Choose ‘r’ to turn right\n” );
printf( “Choose ‘l’ to turn left \n” );
printf( “Choose ‘s’ to stop \n” );
scanf( “%c”, &input );

switch ( input )
{
case ‘r’:
printf( “Go Right!\n” );
break;
case ‘l’:
printf( “Go Left!\n” );
break;
case ‘s’:
printf( “Stop Here!\n” );
break;
default:
printf( “Invalid!\n” );
break;
}
return 0;
}

Listing Q2b

QUESTION 3

a) Write the output for the code shown in Listing Q3a.


(5 marks)

#include <stdio.h>
int main()
{
char alpha='D';
int count=0;
char i;
for(i='A';i<=alpha;i++) {
printf("%c",i);
printf("%d\n",count);
count+=1;
}
printf("Number of alphabet is %d\n", count);
return 0;
}

Listing Q3a.
© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL
CONFIDENTIAL 5 EE/JAN 2021/ECE128

b) Complete the programming code in Listing Q3b using a continue statement to produce
an output as shown in Figure Q3b.
(5 marks)

#include <stdio.h>
int main()
{ int count;
for(count=0;count<=10;count++) {

-------------------
-------------------
-------------------
}
return 0;
}

Listing Q3b

0 2 4 6 8 10

Figure Q3b

END OF QUESTION PAPER

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL

You might also like