Sie sind auf Seite 1von 13

UNIVERSITI TENAGA NASIONAL

College of Information Technology




BACHELOR OF MECHANICAL ENGINEERING (HONS.)
BACHELOR OF CIVIL ENGINEERING (HONS.)

MID-SEMESTER TEST
SEMESTER I 2010/2011

PRINCIPLES OF PROGRAMMING
(CSEB113)

January 2011

Time allowed: 2 hours + 10 minutes for reading


INSTRUCTIONS TO CANDIDATES

1. The total marks for this exam is 60 marks.
2. There are TWO (2) SECTIONS to this paper: Section A and Section B.
3. Answer ALL questions in this question paper.
Please fill up the following information:





DO NOT OPEN THIS QUESTION PAPER UNTIL YOU ARE INSTRUCTED TO DO SO
THIS QUESTION PAPER CONSISTS OF 13 PRINTED PAGES INCLUDING THIS PAGE

MARKS


60
Student Name: _________________________________________

Student ID: _____________________ Section: __________

Lecturer Name: _________________________________________

Page 2 of 13
Semester I 2011/2012 Principles of Programming

SECTION A: MULTIPLE-CHOICE (15 QUESTIONS, 30 MARKS)
Instruction: Please select the BEST answer from the given choices.

1. What is 3 main parts in the central processing unit (CPU)?
(a) The control unit, the arithmetic and logic unit (ALU) and registers
(b) The control unit, main memory and the arithmetic and logic unit (ALU)
(c) The arithmetic and logic unit (ALU), main memory and registers
(d) The input and output devices, main memory and registers

2. A (n) ________ are the rules to join words together in forming a correct expression or
phrase.
(a) Programming language
(b) Operating system
(c) Syntax
(d) Psuedocode

3. A _________ is a series of steps or statements that are executed in the order they are
written in an algorithm.
(a) C language
(b) Flowchart
(c) Source Code
(d) Psuedocode

4. Which of the following declares a named constant?
(a) const PI 3.142;
(b) const 3.142;
(c) const double PI 3.142;
(d) double const PI 3.142;






Page 3 of 13
Semester I 2011/2012 Principles of Programming


5. What is the meaning for the following flowchart symbol label-A?








(a) Selection symbol
(b) Printer output symbol
(c) Input-Output symbol
(d) Off-page connector

6. Which of the following conversion identifiers can be used for printing a variable of
type String in the printf() function?
(a) %d
(b) %f
(c) %c
(d) %s

7. Which of the following example causes of Run-time error?
(a) A violation of the C grammar rules
(b) Program that directs the computer to perform an illegal operation
(c) Incorrect algorithm
(d) Use a C keyword/reserve word as variable

8. Which of the following are NOT consider as an input device?
(a) Touch screen monitor
(b) Mice
(c) Microphone
(d) Laser printer

Begin
label-A
Calculate
total=a+b
Age = current
Page 4 of 13
Semester I 2011/2012 Principles of Programming

9. TWO (2) types of arithmetic operators are?
(a) Unary and bit
(b) Unary and binary
(c) Bit and bytes
(d) None of the above

10. What type of programming language will represent for the following code?






(a) Machine language
(b) High-level language
(c) Assembly language
(d) Natural language

11. Which of the following statements is TRUE about looping structure?
(a) If do... while loop condition is false, infinite loop will occur.
(b) In do... while loop, there will be at least one output even if the condition is
false.
(c) A while loop body will never allow infinite loop condition to occur.
(d) Increment operator is only allowed in for loop.

12. Symbol of &&,||, and ! are respectively called ________________.
(a) logical operators AND, OR, and NOT
(b) logical operators AND, NOT and OR
(c) logical operators NOT, OR, and AND
(d) logical operators AND and OR



LOAD varA, 50
LOAD varB, 70
SUB varB
MOV varB, temp
.
.
Page 5 of 13
Semester I 2011/2012 Principles of Programming

13. What is the output for the following program segment?







(a) The value of x is less than 5
(b) The value of x is 5
(c) No output
(d) Compilation error


14. What will be output of the following program?








(a) XX
(b) X
X
X
(c) XXXXXX
(d) None of the above




#include<stdio.h>
int main()
{
int j = 8;
for(;j >= 6;j -= 1)
{
printf("\nX");
}
return 0;
}

int x = 3;int y = 6;
if ((x < y) && (x > 0))
x = x + 2;
if (x < 5)
printf(" The value of x is less than 5", x);
else
if (x > 5)
printf(" The value of x is %d", x);
Page 6 of 13
Semester I 2011/2012 Principles of Programming

15. What will be output of the following program?








(a) 1 2 3
(b) 1
2
3
(c) 2 3
(d) None of the above

16. What will be output of the following program?








(a) 6
(b) 2
(c) 4
(d) Infinite loop





#include<stdio.h>
int main()
{
int i = 2;
do{
printf(\n%d,i);
i++;
}while(i<3);
printf(\n%d,i);
return 0;
}

#include<stdio.h>
int main()
{
int i=1,j=5;
for(i=j;i>=i;i-=2)
{
printf("%d\n",i);
}
return 0;
}

Page 7 of 13
Semester I 2011/2012 Principles of Programming

17. What will be output of the following program?











(a) 11
5.11
2.5
0.5
(b) 11 5 2 1
(c) 11
5
2
1
(d) None of the above

18. What will be output of the following program?








(a) 0
3
6


#include<stdio.h>
int main()
{
int c = 11;
while(c != 0)
{
printf("\n%d ",c);
if(c % 2 == 0)
c = c / 2;
else
c = (c - 1) / 2;
}
printf("\n%d",c);
return (0);
}

#include<stdio.h>
int main()
{
int c;
for(c = 0; c < 5; c++)
{
printf("\n%d",c);
c + = 2;
}
printf("\n%d",c);
return (0);
}

Page 8 of 13
Semester I 2011/2012 Principles of Programming

(b) 0
3
3
(c) 0
3
(d) None of the above

19. What will be output of the following program?












(a) A+
(b) BGood Luck
(c) B
(d) Good Luck

20. What will be output of the following program?






(a) 5
(b) 6
(c) 7
(d) No output
main()
{
int markah = 65;
if (markah >= 80)
printf(A+ );
else if (score >= 70)
printf(B );
else if (score >= 60)
printf(C );
else if (score >= 50)
printf(D )
else
printf(F );
printf(Good Luck.\n);}

#include<stdio.h>
int main()
{ int i = 2;
for(i = 6;i <= 7;i += 2)
{ printf("%d\n",i);}
return 0;
}
Page 9 of 13
Semester I 2011/2012 Principles of Programming

SECTION B: SHORT ANSWERS (4 QUESTIONS, 30 MARKS)
Instruction: Please answer ALL the questions. DO NOT show any working unless stated
by the question.

Question 1
(a) Fill in the FIVE (5) blanks with the correct C condition code for the examples of
equality and relational operator below.
MEANING EXAMPLE
x is greater than y x > y
x is not equal to y
x is equal to y
x is equal to or greater than y
x is equal to or less than y
x is less than y

[5 marks]

(b) Define the meaning of input device and provide one example of input device







[1 marks]








Page 10 of 13
Semester I 2011/2012 Principles of Programming

Question 2
Draw a flowchart for the following program:
A program that will take one input, the amount of total working hour and then calculate the
salary of the employee. If the total working hour is less than 8 hour, the amount of salary is
working hour multiply RM 2.00, otherwise if more than 8 hour, the amount of salary is
working hour multiply RM 3.00. Display the salary he/she earns.









[5 marks]



























Page 11 of 13
Semester I 2011/2012 Principles of Programming

Question 3
(a) What is the result produce for the following expressions?
(Note: Please show how you get the result)
Assume the following initial value for each variable is as follows:
int a=1; b=2; c=3; d=4;
int x;

(i) x = 3 * a++ - ++b / 2 + a;









\



[4 marks]
(ii) x = 3 * a++ - --b / 2 + b;







[4 marks]




Page 12 of 13
Semester I 2011/2012 Principles of Programming

Question 4
(a) Study the following C code?















(i) What output produced when the input value for variable number is 1?




[2 marks]
(ii) What output produced when the input value for variable marks is 4?




[2 mark]








void main()
{
int number;
printf(please enter your number:);
scanf(%d, &number);
switch(number)
{
case 1:
printf("The number is ONE\n");
break;
case 2:
printf("The number is TWO\n");
break;
case 3:
printf("The number is THREE\n");
break;
}
printf("Good luck for the exam!!!\n");

Page 13 of 13
Semester I 2011/2012 Principles of Programming

(b) Modify the above C code with using if..else statement.





















[7 marks]

---End of Questions---

Das könnte Ihnen auch gefallen