Sie sind auf Seite 1von 9

CONFIDENTIAL CS/APR 2007/CSC305

UNIVERSITI TEKNOLOGI MARA


FINAL EXAMINATION

COURSE : PROGRAMMING PARADIGM


COURSE CODE : CSC305
EXAMINATION : APRIL 2007
TIME : 3 HOURS

INSTRUCTIONS TO CANDIDATES

1. This question paper consists of TWO (2) parts : PART A (15 Questions)

PART B ( 6 Questions)

2. Answer ALL questions from all TWO (2) parts.

i) Answer PART A in the Objective Answer Sheet.


ii) Answer PART B in the Answer Booklet. Start each answer on a new page.
3. Do not bring any material into the examination room unless permission is given by the
Invigilator.

4. Please check to make sure that this examination pack consists of:

i) the Question Paper


ii) an Answer Booklet - provided by the Faculty
iii) an Objective Answer Sheet - provided by the Faculty

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


This examination paper consists of 9 printed pages
© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL
CONFIDENTIAL 2 CS/APR 2007/CSC305

PART A (30 MARKS)

1. A Prolog programs consists of

A. a series of rules.
B. a series of facts.
C. logical statement.
D. All the above.

2. The form P1 =5 P2 means

A. P2 implies P1.
B. P1 implies P2.
C. P1 is disjunction with P2.
D. P2 is conjunction with P1.

3. Inheritance

A. defines a class of an object.


B. defines a relationship between a class and its sub class.
C. allows the subclass to inherit the variables of the super class only.
D. is defined using the implements keyword.

4. Choose the FALSE statement about logic programming.

A. It used the declarative semantic method.


B. It is used when the application needs to match certain patterns with
backtracking search.
C. It is based on the lambda-calculus expression.
D. It consists of declarations rather than assignment and control flow statements.

5. Choose the iLLEGAL Scheme statement and its return value.

A. (cons 'a Mb c) ) returns (a b c).


B. (car Ma b c d) ) returns va
C. (min (* 2 3) ( + 3 5)) returns 6.
D. (even? 22) returns t r u e .

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 3 CS/APR 2007/CSC305

6. What is the output of the following queries in Scheme language?

(/ ( * 1 2 3 4 ) ( + -3 -2 - 1 0) )

A. -4
B. 4
C. 0
D. 24

7. The followings are modifiers in Java language EXCEPT .

A. private
B. dynamic
C. protected
D. static

8. The followings describe the Imperative programming EXCEPT:

A. The program consists of sequence of operations.


B. Statements are classified into three categories, which are computational
actions, control-flow actions and input/output actions.
C. Actions may change the memory locations.
D. Data and operations are considered when declaring a variable.

9. The following are the access modifiers that can be used for constructor EXCEPT

A. public.
B. protected.
C. private.
D. final.

10. Variables in Prolog are introduced as strings of characters starting with a first letter
which is a(n)

A. small letter.
B. capital letter.
C. predicate.
D. atom.

11. Thequery: ?- 500=5000/10 in Prolog will return

A. yes
B. no
C. ok
D. continue

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 4 CS/APR 2007/CSC305

12. Logic programming does NOT support the following EXCEPT.

A. searching mechanism.
B. go-to statements.
C. if-then-else statements.
D. do-loops, for-loops, and while-loops.

13.

"For all X, Q is true".

The above statement can be best represented as:

A. 3 X Q
B. V X Q
C. ! X Q
D. % X Q

14. Thefunction (car Mare you hungry)) returns

A. are
B. hungry
C. are you hungry
D. ()

15. Thefunction (car (cdr M i t i s cloudy today) )) will return

A. today
B. is
C. it
D. is cloudy today

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 5 CS/APR 2007/CSC305

PART B (70 MARKS)

QUESTION 1

a) Logic and Functional Paradigm are the two main paradigms of computer languages.
For each paradigm, briefly explains the THREE (3) key features and gives an
example of a computer language that is categorized in the paradigm.
(6 marks)
b) Briefly explain the following terms:

i) Dynamic binding,
ii) Lambda function.
(4 marks)

QUESTION 2

Examine the following codes written in C++ language and answer the following questions:

#include <iostream.h>

void main()

int count;
int numEven, numOdd;

numEven = numOdd = 0;

int numbers[] = {2, 6, 8, 7, 3, 5, 1, 3, 2, 8 ) ;

count = 0;
while(count < 10)

if(numbers[count] % 2 == 0)
++numEven;
else
++numOdd;

++count;

cout<<"# even numbers "< <numEven< < endl;


cout<<"# odd numbers " <<numOdd;

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL CS/APR 2007/CSC305

a) What is the array size of numbers [ ] ?


(1 mark)

b) What is the initial value and final value for the following variables?

i) count
ii) numEven
iii) numOdd
(6 marks)

c) Rewrite the while loop above by using the f o r loop.


(3 marks)

QUESTION 3

Write a generic function to find the average of the numbers in an integer array. This function
should receive two arrays of integer values.

a) Write the function using Pascal language.


(3 marks)

b) Write the function using C++ language.


(3 marks)

c) Write the function using JAVA language.


(3 marks)

d) What is the different between b) and c) version?


(1 mark)

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 7 CS/APR 2007/CSC305

QUESTION 4

Given the following Java program segments.

class Owner
{
private String name;
private String address;
public Owner(){} //default constructor

public Owner(String nm,String add) //constructor


{
name = nm;
address = add;
}
public display() //printer
{
System.out.print(" Name is " ) ;
System.out.printIn(name);
System.out.print(" Address is " ) ;
System.out.println(address);

class Vehicle
{
private Owner own;
private String regNum;
public Vehicle (){} //default constructor

public Vehicle (Owner st ,String rn) //constructor


{
own = st;
regNum = rn;
}
public display() //printer
{
own.display();
System.out.print(" Registration number is" ) ;
System.out.println(regNum);
}

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 8 CS/APR 2007/CSC305

Answer the following questions based on the two classes above.

a) Write a Java application class to print the following:

i) owner's information such as name and address i.e. "Amir syakir",


"Subang Jaya"

ii) vehicle's information such the as owner's name and registration number i.e.
"Amir Syakir", "WJC305".
(4 marks)

b) What is the relationship between class Owner and class v e h i c l e ?


(2 marks)

c) Modify class V e h i c l e above, in order to add more information about the vehicle
such as year of manufacture, purchase price and age of the vehicle.
(6 marks)

d) Add a new method to calculate the current price for a particular vehicle based on the
depreciation of the car value (Price). Assumed that the depreciation rate is about
10% a year.
(8 marks)

QUESTION 5

Given the following facts.

valuejneal(10.00).
family_meal(30.00).
party_meal(45.00) .
kid m e a l ( 5 . 0 0 ) .

served as(takeaway).
served as(eat h e r e ) .

adds on(soft drinks,2. 50) .


adds on(fries,1.75).

per person(value meal, 1) •


per_person(family_meal ,7) .
per person(party m e a l , 1 5 ) .
per person(kid meal,l) •

a) Add the following rules to the database.

i) A discount of 25% is given to k i d m e a l or p a r t y j n e a l , which is served as


eat_here.
(4 marks)
© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL
CONFIDENTIAL 9 CS/APR 2007/CSC305

ii) A promotion that will return a type of meal and its cost is based on the
number of person.
(2 marks)

iii) A bill, which is based on their type of meal and adds_on.


(2 marks)

b) Write a query for each of the following questions.

i) What is the suitable promotion given to a group containing 7 persons?


(1 mark)

ii) What is the bill for a person that orders a value_meal and sof t _ d r i n k s ?
(1 mark)

QUESTION 6

a) Entry fees for a child in an animal road-show is RM3 while the entry fees for an adult
is RM6. One family consists of n family members and m of them is children.

i) Write the entry fees function for the case above using Scheme.
(4 marks)

ii) If Irfan's family consists of 6 members and 4 of them are children, show the
output for the entry fees for this family using the answer in a)i) above.
(2 marks)

b) Write the Scheme functions to compute the following mathematical expressions.

i) CV2
1^ =
V
(2 marks)

ii) (2X2 + y)*2x


(2 marks)

END OF QUESTION PAPER

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL

Das könnte Ihnen auch gefallen