Get premium membership and access revision papers, questions with answers as well as video lessons.

Ics2304:Programming Paradigms Question Paper

Ics2304:Programming Paradigms 

Course:Computer Science

Institution: Meru University Of Science And Technology question papers

Exam Year:2010



TIME: 2 HOURS
INSTRUCTIONS: Answer question one and any other two questions
QUESTION ONE – 30 MARKS
a. Explain the following terms in the context of programming. (3 Marks) i. Program ii. Programming language iii. Programming paradigm b. Distinguish between syntax of a language and semantics of a language. (2 Marks) c. Describe the role of the following elements of an imperative programming language. (3 Marks) i. Declarative statements ii. Imperative statements iii. Program flow control statements d. In the program fragment shown below categorize each of the statements to the appropriate element in (c) above justifying your choice. (6 Marks) int factorial = 1; int argument =7; int counter = 1; while (counter <= argument){ factorial = factorial*counter; counter++; } e. Construct a comprehensive class diagram to depict the objects and relationships described below relating to a publishing house. (10 Marks) ? If two or more authors are under-taking the auditing same book, each author may get a different royalty percentage ? An author may have more than one book published and for each book, the royalty fee can differ ? Each book is edited by one or two editors, and the publisher may use in house editors on salary, or pay freelance editors a flat fee. f. Illustrate the main difference between imperative programming and functional programming by writing a definition of function factorial for each of the two paradigms. Where; factorial (n)=n x (n-1) x (n-2) x ....... x3 x2 x1; factorial (1)=1 and factorial (0)= 1 (6 Marks)
2
QUESTION TWO – 20 MARKS
a. Define the following terms as used in Logic Programming (4 Marks) i. Fact ii. Structured term iii. Arity iv. Predicate b. Describe each of the following variable quantifiers used in Logic Programming. (2 Marks) i. ? ii. ? c. Interpret the following Logic Expression (4 Marks) i. ?x (greaterThan(Y,X) & greaterThan(15,Y)) ii. ? descendent („Njeru?,?Njeri?) iii. ??X (parent(X,?Atieno?) & parent(X,?Kajwang?)) d. Justify the effect of the variable quantifier „?? by constructing a Truth table for each of the following expression given that X ranges over {4,15} and Y over {7,14} (5 Marks) i. greaterThan(Y,X) & greaterThan(12,Y) ii. ?X (greaterThanY,X) & greaterThan(12,Y)) e. Construct a resolution tree to depict the implementation of Backtracking Resolution Algorithm for the following scenario. (5 Marks)
Basic Facts: B1(x) Database:{2,3,4} B21(x) Database:{1,2,3} B22(x) Database:{1,3,9} B3(x) Database:{1,2,5,36}
Rules of Inference P1(x) :=B1(x) P2 (x) & B3(x) P2(x) :=B21(x) & B22(x) Verifier Goal: ?P1(1)
QUESTION THREE – 20 MARKS
a. Explain the term Implementation Hiding as a concept in object oriented paradigm. (1 Mark) b. Describe how object orientation facilitates the use of implementation hiding. (3 Marks) c. State the benefits of Implementation Hiding. (2 Marks) d. Differentiate between inheritance and polymorphism as some of the core elements of object oriented paradigm. (2 Marks) e. Describe how polymorphism and inheritance can be combined to enhance the maintainability of a software system. (2 Marks)
3
f. Justify how the following OOP concepts have been implemented in the following program: (10 Marks) i. Encapsulation ii. Inheritance iii. Overloading iv. Overriding v. Abstraction
class ape{ public:
void caculateAge(int dob, int dtd); void showData ( ) ; void calculateAge (int dob) ; void eat ( ) ; void walk ( ) {cout << “walks around\n”}
} ;
class humanBing : public ape{ private : int p, q; public : void talk ( ) ; void fiveCsense ( ) ; void walk ( ) {cout << “walks upright on two\n”} }; class monkey : public ape{ public: double hasTail ( double tailSize) ; }; class gorilla : public ape { public void hasNoTail ( ) { cout << “Has no tail\n”} } ;
QUESTION FOUR – 20 MARKS
a. With the aid of diagrams, describe the four program execution control structures found in traditional imperative languages. (8 Marks) b. Explain each of the use of the following jump statements as used in the imperative C language. (3 Marks) i. Goto ii. Break iii. Continue
4
c. Study the program below and answer the question that follow: class B { private: int x, wx; void Fxwx (void) public: int y; void Fy (void); voidshowData (void); void getData (void); protected: int z; void Fz (void) };
i. State the number of data members in class B. (1 Mark) ii. State the number of member functions in class B. (1 Mark) iii. Write in its simplest form: ? Default constructor to class B (1 Mark) ? Default destructor to class B (1 Mark) iv. The header of class DD is as shown below: class DD : B { .......};
Complete the table below by explaining the status of inherited member data/function in class DD (5 Marks)
Inherited Member Data/Function
Explanation of Status of Inherited Member Data/Function in Class DD i wx ii Fxwx() iii y iv getData( ) v Fz( )
5
QUESTION FIVE – 20 MARKS
a. State the rules that govern the formulation of well formed formulae. (5 Marks) b. Explain the term “executing programs” as used in logic programming (1 Mark) c. State the components that identify a calculation in logic programming. (3 Marks) d. Construct a resolution tree to depict the implementation of Forward Resolution Algorithm for the following scenario. (6 Marks)
Basic Facts: B11(x) Database: {1, 2, 3, 4} B12(x) Database: {3, 4, 5, 6} B21(x) Database: {1, 2, 3, 4} B22(x) Database: {1, 2, 3, 5} Rules of Inference: P(x) :=P1(x) P2(x) P1(x) :=B11(x) & P12(x) P2(x) : =B21(x) & B22(x)
e. Compare and contrast the major programming paradigms by completing the following table. (8 Marks) Paradigm Key Concept Program Program Execution Result Imperative Functional Logic Object-Oriented






More Question Papers


Popular Exams



Return to Question Papers