Sunteți pe pagina 1din 9

CONFIDENTIAL

UNIVERSITI TEKNOLOGI MALAYSIA

MID TERM - TEST 1


SEMESTER I 2016/2017

SUBJECT CODE : SCSP1103


SUBJECT NAME : PROGRAMMING TECHNIQUE I
YEAR/COURSE : 1 (FKE)
TIME : 2 HOURS 30 MINUTES
DATE : 25 OCTOBER 2016
VENUE : P19 (DK4, DK5, DK6)

INSTRUCTIONS TO THE STUDENTS:

This test book consists of 3 sections:


Section A: True/False [10 Marks]
Section B: Short Structure [55 Marks]
Section C: Programming Structure [35 Marks]

ANSWER ALL QUESTIONS IN ANSWER PAPER.

NAME

IC NO

SECTION

LECTURER

1
SECTION A – TRUE/FALSE QUESTIONS [10 MARKS]
ANSWER ALL (10) QUESTIONS.

(True/
Questions
False)
1. Programming is a procedure for solving a problem in terms of the actions and
the order are to be executed

2. Logical operators is used to create relational expressions from other relational


expressions

1. Loop specifies a block of one or more statements that are repeatedly executed
3.
until a condition is satisfied

2. Two types of repetition structures (statement) are Counter-controlled and


4.
Sentinel-controlled

5. Comments cause the computer to display the text after // on the screen when
the program is executed.

6. All arguments following the format control string in a printf function must be
preceded by an ampersand (&).

7. A program that prints three lines of output must contain three printf
statements.

8. The output of this statement is 1.5


printf(“%f”, 7.5 % 3);

9. Operation “a=a*b+a” can also be written as “a*=b+1”.

The output of the C statement below is


10. printf (“|%10.2f|”, 0.1376e+001);
is |_ _ _ _ _1.37|

2
SECTION B – STRUCTURE QUESTIONS [55 MARKS]
ANSWER ALL (8) QUESTIONS.

Question 1 (10 marks)

1. Write a pseudocode representing the problem of finding the total (SUM) of the first 50
numbers (N).
2. Draw a flowchart for above problem.

Pseudocode (5 Marks) Flow Chart (5 Marks)

3
Question 2 (11 marks)

Flowchart in figure below is to find the smallest and largest values for 10 scores. Fill in the
blank (a, b, c, d, and e) graphical symbols with appropriate instructions.

a) _________________
b) _________________
c) _________________
d) _________________
e) _________________

Trace the flowchart above and display the output, if the input is 23, 15, 31, 27, 34, 16, 7, 28,
49 and 11. Complete the table below.

No. Read, n S L C

Output : ____________________________

4
Question 3 (4 marks)

Which of the following identifier is Valid/Not Valid? Give your justification if the identifier
is not valid.

Name of identifier Valid/Not Valid Justification

Question 4 (5 marks)

Write a complete C program to calculate TOTAL and AVERAGE for the four integers.
a) State or describe that a program will calculate the sum and average of 4 integers.

b) Define the variables a, b, c and d be a type of integer and TOTAL and AVERAGE as
type of floating point.

c) Prompt the user to enter four integers.

d) Read four integer from the keyboard and store them in the variables a, b, c and d.

e) Compute and display the TOTAL and AVERAGE of four integers contained in variables a,
b, c and d.

5
Question 5 (6 marks)

Write formula in C statement


a) =

b) =

Question 6 (6 marks)

Solve the statements and show your steps in the table below.

int a=2, b=4, c=3, d=6, e=5;


++b-=a+c*e/(d%4);

step operator solution


0 ++b-=a+c*e/(d%4)

Question 7 (7 marks)

Write a C statement for each of the following:


a) Print 748.223 left-justified in a 9 digit field and 2 digits of precision.

b) Read 3 values (type integer, float, character) into variable A, B and C in one statement.

c) Read a string into character array string.

6
What does each of the following statements print?
Assume int i=1, j=2, k=3, m=2
d) printf("%d\n", j==3);
e) printf("%d\n", i>=1 && j<4);
f) printf("%d\n",j>=i || k==m);
g) printf("%d\n",!(j-m));

Question 8 (6 marks)

Trace the following program and give the output.

int a = 6;
int b = a--; Output

printf("%d\n", a);
printf("%d\n", b);

a = 6;
b = --a;
printf("%d\n", a);
printf("%d\n", b);

a = 10; b = 12;
a = ++a + b--;
b-=7;
printf("%d\n", a);
printf("%d\n", b);

7
SECTION C: PROGRAMMING QUESTIONS [35 MARKS]
ANSWER ALL (2) QUESTIONS.

Question 1 (10 Marks)


The following table shows the approximate speed of sound in air, water and steel.

Medium Speed
Air 335.3 meter per second
Water 1493.5 meter per second
Steel 4998.7 meter per second

Write a program that displays a menu allowing the user to select air, water or steel. After the
user has made a selection, he/she should be asked to enter the distance a sound wave will
travel in the selected medium. The program will then display the amount of time take.
(Round the answer to four decimal places)

Input validation: Check that the user has selected one of the available choices from the menu.
Do not accept distances less than 0.

ANSWER :

8
Question 2 (25 MARKS)

A bank charges RM20 per month plus the following check fees for a commercial checking
account:

RM0.50 each for fewer than 10 checks


RM0.40 each for 10-19 checks
RM0.30 each for 20-29 checks
RM0.20 each for 30 or more checks

The bank also charges an extra RM25 if the balance of the account falls below RM500
(before any check fee are applied). Draw a flowchart and write a program that asks for the
beginning balance and the number of checks written. Compute and display the bank’s service
fees for the month.

Input validation: Do not accept a negative value for the number of checks written. If a
negative value is given for the beginning balance, display an urgent message indicating the
account is overdrawn.

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