Você está na página 1de 6

UNIVERSITI TENAGA NASIONAL

College of Information Technology

B. SC & B.ENG
MID TERM TEST
SEMESTER I 2006/2007
PRINCIPLES OF C PROGRAMMING
(CCSB163/CSEB113)

25th August 2006

Time allowed: 1 hour 45 minutes

INSTRUCTIONS TO CANDIDATES.
1.

The total marks for this exam is 100 marks.

2.

There are total of 5 sections (A, B, C, D and E).

3.

Answer ALL questions in the answer booklet given.

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

SECTION A (TRUE/FALSE) [2 marks per question]


1.

Operators are tokens that result in some kind of computation or action when
applied to variable in an expression.

2.

The conditional expression in C can be any expressions including an arithmetic


expression that results in an integer value.

3.

Visual C++ is an Integrated Development Environment where it provides all that


are necessary tools to write compile and execute a C or a C++ program.

4.

Implementation is a phase in the Software Development Method where we run


(execute) our programs with as many test data in order to make sure it is perfect.

5.

Operator =< is a relational operator in C

SECTION B (MULTIPLE-CHOICE) [2 marks per question]


1.

The C operator that has the lowest precedence level among the following
operators is:
(a)
*
(b)
+
(c)
%
(d)
=

2.

Which of the following statements about C language is INCORRECT?


(a)
C directly supports the Boolean data type.
(b)
C allows the identifiers to start with an underscore.
(c)
The scanf format specifier for integer variables is %d.
(d)
The C language is case sensitive.
Assume the following declarations for Question (3) and (4):
int
i = 1, j = 2, k = 3, m = 4;

3.

The statement i += j + k; will result in the following changes to the variables


(a) i = 6, j = 5, k = 3
(b) i = 6, j = 2, k =3
(c) i = 5, j = 5, k = 5
(d) i = 5, j = 2, k = 3

4.

The statement i *= (m j) + k++; will result in the following changes to the


variables
(a) i = 5, j = 2, k = 3, m = 4
(b) i = 6, j = 2, k =3, m = 4
(c) i = 5, j = 2, k = 4, m = 4
(d) i = 6, j = 2, k = 4, m= 4

5.

What is the value of the expression 12 - 10 - 8 * 6 % 4 + 2 % 1


(a) 2
(b) 0
(c) 7
(d) 2
Page 2 of 6

Semester 1 2006/2007

Principles of C Programming

SECTION C (DESIGN)
Question 1
Design a program using the pesudocoding technique (pseudocode) that will find the sum
of all the integers between two integers that are given by the user. An example of your
output will probably look like the following, if the user enter 5 and 7:
Enter the first integer: 5
Enter the second integer: 7
Total sum of all the integers between 5 and 7 is 18.
The calculation for the answer was obviously 5+6+7 = 18. You may assume the first
number will always be smaller than second.
[10 marks]
Question 2
A new Gallery Smart Shop owned by Robin sells items below:
Item
Pensonic Cordless Steam Iron
Toaster Ebba
Table Fan National
Water Boiler 3.99 L
Vacuum Cleaner National

Code
1
2
3
4
5

Price (RM)
30.00
35.00
40.00
90.00
120.00

Design a program using the pesudocoding technique (pseudocode) that ask user to enter
the code and quantity of the item. The program calculates and prints out the total price of
the item entered. The program should also displays an error message if the user enters
invalid item code.
[10 marks]

SECTION D (TRACING)
Question 1
What are the values stored in variables A, B, C and D when the following program
segment is executed? Assume that A, B, C and D are integer variables.
A = 14 5 % 3;
B = 7 * 3 + 9 / 4;
C = (6 + 3) * (7 % 4);
D = 2 < 0;
[8 marks]

Page 3 of 6
Semester 1 2006/2007

Principles of C Programming

Question 2
Determine the output of the code fragment.
int a = 5, b = 4, c = 1 ;
if ( a < b + 1 ) {
printf("Tea, Earl Grey, Hot!\n") ;
} else if ( a > b + c ) {
printf("Ahead warp factor 9. Engage!\n") ;
} else if ( a % b >= c ) {
printf("Warp core breach in 20 seconds!\n") ;
} else {
printf("I sense a lot of anxiety in this room.\n") ;
}
[5 marks]
Question 3
The following C program contains nine syntax errors. Rewrite program such that is free
of syntax. Highlight your corrections by using circle.
#include<stdio.H>
#define MESSAGE Exams today
Main()
{
int a,b,c;
int 2number,number_three = 10;
a=5; b=3, c=2;
printF("%d",a + b + c);
printf("%d\n ',Number_three * 5);
printf(MESSAGE)
}
[9 marks]
Question 4
Consider the following fragment of C-codes
if (Marital_status == S)
if (gender == M && age >= 18 || age <= 26)
printf ( You are a single adult male);
else
printf ( You are a single teen male);
What will be printed if Marital_status = S , gender = M and age = 15?
[6 marks]

Page 4 of 6
Semester 1 2006/2007

Principles of C Programming

Question 5
Consider the following fragment of C-codes
#include<stdio.h>
main() {
int hours;
double fee;
printf(Enter no of hours: );
scanf(%d, &hours);
if (hours > 2) {
fee = 2+(hours-2)*2;
} else {
fee = hours * 1 ;
}
printf(Fee: RM%.2lf, fee);
}
Determine the output on the screen when user enter
(a) 1
(b) 2
(c) 3
[6 marks]
Question 6
Find the value of integer n if the values of a, b and c are given as follows:
int a = 5, b = 4, c = 3;
(a) n = (a c) * a c;
(b) n = a % c;
(c) n = c / a % ++a - -b;
[6 marks]
SECTION E (PROGRAMMING)
Question 1
Write a complete C program that prompts the user for two positive integers greater than
0. The input is prompted one at a time. If the user enters an invalid integer, the program
displays an error message and prompts again for the second time (there is not need to use
a loop/repetition). The program then displays the two integers as a real number, where
the first integer forms the integer portion of the real number, and the second integer forms
the fractional portion. For example, if the user enters 10 and 20, then the real number
being displayed is going to be 10.20. (Hint: You do not need to perform any arithmetic
calculation.)
[10 marks]
Page 5 of 6
Semester 1 2006/2007

Principles of C Programming

Question 2
Write a complete C program to translate the following flowchart into its equivalent
executable codes without changing any of its logic.
[10 marks]
Begin

Read Age

False

True
Age more than 59

Read Retired
True
Age > 20

False
Print Adult
True

Retired = Y

Age > 12
False

True

False
Print Teen

Print Retired
Senior

Print Working
Senior

Print Child

Print Thats all, folks

End

Page 6 of 6
Semester 1 2006/2007

Principles of C Programming

Você também pode gostar