You are on page 1of 10

UNIVERSITI TENAGA NASIONAL

College of Information Technology

MID TERM TEST
SEMESTER II 2015/2016
PRINCIPLES OF PROGRAMMING
(CSEB113)

27th November 2015
Time allowed: 1 hour and 30 minutes

INSTRUCTIONS TO CANDIDATES
1.

The total marks for this exam is 60 marks.

2.

There are THREE (3) SECTIONS to this paper: Section A, Section B and Section C. Answer
ALL questions.

3.

Write all answers in the provided answer booklet. PLEASE ENSURE YOUR SECTION
NUMBER AND LECTURER NAME ARE WRITTEN CORRECTLY.

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

Page 1 of 10

3.SECTION A: MULTIPLE CHOICE QUESTION (20 QUESTIONS. ii. ii. i Page 2 of 10 . (i) The loader loads the executable file into the memory (ii) A compiler translates a high-level language program into machine language (iii) An editor enters a high-level language program into a file. iv. iii. 4. in the provided answer booklet. 1. i (c) iii. Write the letter of your answer in uppercase. 2. 20 MARKS) Instruction: Choose the best answer from the given choices. iv (b) iii. Which of the following is not basic components of a computer? (a) compiler (b) main memory (c) printer (d) hard disk A (n) _________ is a list of instructions that direct the work of a computer (a) register (b) program (c) secondary storage (d) memory The __________________ unit is responsible for copying information from the main memory and putting that information into the registers. with the question number. (a) arithmetic-logic (b) input (c) control (d) switch Arrange the sequence below to become the steps for the computer to prepare the execution of a high-level language program. ii. (iv) The linker links this object program to other objects files and creating executable file (a) i. iv.

(a) an executable file (b) a preprocessor directive (c) object code (d) an input stream Every statement in C must end with a _______. i. (a) the object code is linked with code for functions in other files (b) the C program is translated into machine language code (c) the program is executed one instruction at a time (d) the program is placed in memory The linker creates __________.) (b) semicolon (. (a) Specify the Problem (b) Analyze the Problem (c) Design the Solution (d) Implement the Solution The compile stage is when ____________. 8. 9. 6. iii ___________ is the stage of the software development method in which you write an algorithms. ii.(d) 5. (a) period (. (a) Specify the Problem (b) Analyze the Problem (c) Design the Solution (d) Implement the Solution In which step of the software development method are the problem inputs and outputs identified? 7.) (c) colon (:) (d) backslash (\) Page 3 of 10 . iv.

(c) Comments do not cause any machine language object code to be generated. (a) \tab (b) \t (c) \horizontaltab (d) \T Page 4 of 10 . (c) at preprocessor time. a backslash (\) is printed by enclosing in quotes (a) \ (b) \\ (c) /\ (d) // The escape sequence for horizontal tab is __________. (b) Programmers insert comments to document programs and improve program readability. In a C program. respectively. (b) at compile time. 12. Which statement about comments is FALSE? (a) Comments begin and end with /* and */.10. Lines beginning with a # are processed (a) at execution time. (a) module (b) statement (c) directive (d) function In a printf. (d) Lengthy comments can cause poor execution-time performance. 14. (d) at postprocessor time. 11. the line: int main() the parentheses indicate that main is a program building block called a 13.

17. (a) 150 (b) 151 (c) 149 (d) 152 Page 5 of 10 . 18.15. Which of the following is NOT a keyword? (a) int (b) return (c) if (d) main An if statement implements ___________ control structure. 16. 19. (a) sequence (b) repetition (c) selection (d) duplication The expression (x > y && a< b) is true when: (a) either x > y is true or a < b is true (b) x > y is true (c) a < b is true (d) both x > y and a < b are true What is a compound statement? (a) One or more statements surrounded by braces (b) Mix statement (c) Simple statement (d) Statements ended by semicolons What value is assigned to the int variable ans in this statement if the value of p is 100 and q is 50? ans = p++ + --q.

20. (a) 40.0 (d) 75.0 (b) 35. What value is assigned to fee by the if statement when speed is 75? if(speed < 35) fee = 40.0 Page 6 of 10 .0.0.0 (c) 60. else fee = 60.

number of credits taken so far.” with each word separated by tabs. and the total number of credits required in the degree program. 4. Get the number of credits required for the degree program. Display should include the student name. Get the number of credits the student has taken so far. _____________________________________________________________________ 6. Complete the following pseudocode: Begin 1. 5. [2 marks] (b) Print the message “This is our first test. _____________________________________________________________________ End [3 marks] Question 3 Write a single C statement to accomplish each of the following: (a) Prompt the user to enter an integer. 7. degree name. 20 MARKS) Instruction: Answer ALL questions. 2. _____________________________________________________________________ 3. Get the student name. and credits left to graduate. the degree name. Display the input information in Step 1 and 2. [3 marks] Question 2 Read the following problem: Write a program that will take in basic information from a student. The program will then calculate how many credits are needed to graduate. Question 1 Name the THREE (3) control structures that can be used in a program. [2 marks] Page 7 of 10 . End your prompting message with a colon (:) followed by a space and leave the cursor positioned after the space.SECTION B: STRUCTURED QUESTIONS (6 QUESTIONS. including student name.

0. Initialize them to zero. j = 2. z.2lf\n". z). } [2 marks] Question 5 Write a single C statement to accomplish each of the followings: (a) Declare the variables x and sum from type int. otherwise. k = 3 * 4 * (j + 3) % (i . z = 2 * i / 5 % i + j . k.1).2. y = -1. printf("The value of k is %d\n". sum and total in one statement [2 marks] Question 6 (a) Write a condition expression to test the following: age is from 18 and 21 inclusive. [3 marks] Page 8 of 10 .h> void main(void) { int i = 10. printf("The value of z is %. k).0.Question 4 What is the output for the following program? #include <stdio. inclusive. [2 marks] (b) Print the float values of x. double x = 2. [1 mark] (b) Write C codes for the following: Assign the value 1 to apple if n is in the range –20 to 20. assign a value of 0.

0 and reads the first letter of a single citizen name and his/her category. The below are sample runs of the program: Sample 1: ********************************************** SINGLE CITIZEN ALLOWANCE CALCULATOR ********************************************** Please enter the first letter of your name: T Hai T! Please choose your category 1 .Non-student Category: 1 T. However. while the non-student category is receiving additional 10% of the basic amount for general substance. The basic amount of single citizen allowance has already been approved by the government amounted RM900.Student 2 .Non-student Category: 2 E. 20 MARKS) Instruction: Study the problem carefully before attempting to solve. your allowance is RM990. Every single citizen of a country is given an allowance by the government.00 Sample 1: ********************************************** SINGLE CITIZEN ALLOWANCE CALCULATOR ********************************************** Please enter the first letter of your name: E Hai E! Please choose your category 1 .Student 2 . Write a program that defines a constant named BASIC_ALLOWANCE with the value 900. The program then computes and displays the allowance he/she will receive based on the conditions explained above. there are different amount of allowance given to the two categories of single citizen: the student category is receiving additional RM250 for book allowance. your allowance is RM1150.00 Page 9 of 10 .SECTION C: PROBLEM SOLVING – ALGORTHM AND CODES (1 QUESTION.00.

[12 marks] -.End of Questions --- Page 10 of 10 . [8 marks] (b) Write a C program to implement your algorithm.(a) Write a pseudocode OR draw a flowchart to represent your algorithm to solve the above problem.