0% found this document useful (0 votes)
36 views

ICS-2204-PPL Main

Uploaded by

ben munjaru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

ICS-2204-PPL Main

Uploaded by

ben munjaru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

W1-2-60-1-6

JOMO KENYATTA UNIVERSITY OF AGRICULTURE AND TECHNOLOGY


UNIVERSITY EXAMINATIONS 2022/2023

YEAR 1 SEMESTER 1 EXAMINATION FOR THE DEGREE OF BACHELOR OF SCIENCE IN


COMPUTER TECHNOLOGY

ICS 2204: PRINCIPLES OF PROGRMMING LANGUAGES

DATE: DECEMBER 2022 TIME: 2 HOURS


INSTRUCTIONS: ANSWER QUESTION ONE AND ANY OTHER TWO QUESTIONS

QUESTION ONE: (30 marks)

a) Outline four reasons for studying concepts of Programming Languages (5 marks)


b) Distinguish five distinct Programming Domains and give an example of a language that is
. suited to each.
(10maks)
c) State and clearly explain 5 criteria that maybe used to evaluate programming languages
. (10marks)
d) Highlight 3 benefits of pure functions (6 marks)

QUESTION TWO
a) Explain four aspects of readability (8 marks)
b) State and defend 4 arguments against having a single language for all domains (8 marks)
c) Explain one advantage and disadvantage of having typeless language (4marks)

QUESTION THREE
a) Explain three aspects of writability (6 marks)
b) State three language requirements for implementing Abstract Data Types (3 marks)
c) In object oriented languages there are three ways a subclass can differ from its parent.
Outline them. (3 marks)
d) Draw and explain the Stack Allocation Scheme diagram used in activation record (8 marks)
QUESTION FOUR
a) Explain four aspects of reliability (8 marks)
b) State and expound on two properties of pure functions (6 marks)
c) Define ‘State typechecking’ and explain why it is better than dynamic typechecking. (4 marks)
d) Distinguish between data abstraction and control abstraction (2 marks)

QUESTION FIVE
a) Differentiate between static semantics and dynamic semantics. (4 marks)
b) State and explain 5 programing language categories, giving an example to each (10marks)

c) i) Define data abstraction


ii) State two advantages of Data abstraction (2 marks)
JOMO KENYATTA UNIVERSITY OF AGRICULTURE AND TECHNOLOGY
UNIVERSITY EXAMINATIONS 2022/2023
YEAR I EXAMINATION FOR THE DEGREE OF BACHELOR OF SCIENCE IN
COMPUTER TECHNOLOGY

ICS 2204: PRINCIPLES OF PROGRMMING LANGUAGES


MACKING SCHEME

QUESTION ONE:

1a) Reasons for Studying Concepts of Programming Languages


 Increased ability to express ideas
 improved background for choosing appropriate languages
 Increased ability to learn new languages
 Better understanding of significance of implementation
 Overall advancement of computing

1b) Programming Domains


• Scientific applications
– Large number of floating point computations
– Fortran
• Business applications
– Produce reports, use decimal numbers and characters
– COBOL
• Artificial intelligence
– Symbols rather than numbers manipulated
– LISP
• Systems programming
– Need efficiency because of continuous use
–C
• Web Software
– Eclectic collection of languages: markup (e.g., XHTML), scripting (e.g., PHP),
General-purpose (e.g., Java)

1c) Criteria that maybe used to evaluate programming languages


 Readability: the ease with which programs can be read and understood
 Writability: the ease with which a language can be used to create programs
 Reliability: conformance to specifications (i.e., performs to its specifications)
 Cost: the ultimate total cost of purchase and maintenance
 Portability: The ease with which programs can be moved from one implementation to another
 Generality: The applicability to a wide range of applications
 Well-definedness: The completeness and precision of the language‘s official definition
1d) Benefits of Pure Functions
1. Predictability
Pure functions help us to create more predictable and readable code. Pure functions are small
functions that perform some very specific task and will always return the same output given a
specific input.
2. Testing
Testing pure functions is easier because they are predictable and do not produce any side
effects so we will never be modifying any state of our value outside its scope.
3. Memoization
Caching the returned results of a function can save us from writing expensive computational
functions. Pure functions are easy to memoize. Since they return the same results given a
specific input, the cached result can be returned when the function is called with the same
input arguments.

QUESTION TWO

2a) Aspects of readability

 Repeated practice: It cultivate a style of programming and code writing, the purpose of
which is to ensure the clarity, clarity and artistry of the program or code
 Refinement and optimization of the code: Involves thinking and solving the same specific
problem from different methods, and finding the most effective code through comparative
analysis and temporal and spatial examination.
 Use of some pre-compilation processing operations: that is, file inclusion, macro definition
and conditional compilation, etc., to ensure better readability of the program in large-scale
complex programs
 Notes or instructions to the program: So that people who read the program can better
understand.
 Simplicity and Orthogonality
– Few constructs, a small number of primitives, a small set of rules for
combining them
 Support for abstraction
– The ability to define and use complex structures or operations in ways that
allow details to be ignored
 Expressivity
– A set of relatively convenient ways of specifying operations
– Example: the inclusion of for statement in many modern languages

2b) Arguments against the idea of a single language for all programming domains
 The language would necessarily be huge and complex
 Compilers would be expensive and costly to maintain
The language would probably not be very good for any programming domain, either in
compiler efficiency or in the efficiency of the code it generated.
 More importantly, it would not be easy to use, because regardless of the application area, the
language would include many unnecessary and confusing features and constructs meant for
other application areas.
 Different users would learn different subsets, making maintenance difficult.

2c) Advantage of a typeless language:


Flexibility; any variable can be used for any type values.

The disadvantage of a typeless language:


Poor reliability due to the ease with which type errors can be made, coupled with the
impossibility of type checking and detecting them.

QUESTION THREE
3a) aspects of writability:
 Simplicity and Orthogonality
– Few constructs, a small number of primitives, a small set of rules for
combining them
 Support for abstraction
– The ability to define and use complex structures or operations in ways that
allow details to be ignored
 Expressivity
– A set of relatively convenient ways of specifying operations
– Example: the inclusion of for statement in many modern languages

3b) language requirements for implementing Abstract Data Types:


 A syntactic unit in which to encapsulate the type definition.
 A method of making type names and subprogram headers visible to clients, while hiding
actual definitions.
 Some primitive operations must be built into the language processor.

3c) Three ways a class can differ from its parent:


 The parent class can define some of its variables or methods to have private access, which
means they will not be visible in the subclass
 The subclass can add variables and/or methods to those inherited from the parent
 The subclass can modify the behavior of one or more of its inherited methods.
3d) In Stack Allocation Scheme, when procedure A calls Procedure B, the activation record for
B will be pushed above the activation record for A. When Procedure B calls procedure C, C’s
activation record will be pushed above B’s activation record as in figure –
s

Stack Pointer (SP) − It points to the activation record of the currently active procedure.
In the figure, procedure C is currently an active procedure. So, pointer SP will point to the
activation record for C.
Pointer SP on activation record for procedure C contains the value of old SP.
The space for global data is fixed and statically allocated at the corner of the stack.
Actual Parameter− It is used by the calling procedure to supply parameters to the called
procedure.
Return value: This field is used by the called procedure to return a value to the calling
procedure.

QUESTION FOUR
4a) Aspects of reliability
 Type checking
– Testing for type errors
 Exception handling
– Intercept run-time errors and take corrective measures
 Aliasing
– Presence of two or more distinct referencing methods for the same memory location
Optimize Code Efficiency
– Code that is efficient and executes quickly takes additional skills, achieved by the use of loops,
arrays, and use of Boolean functions.
4b) properties of pure functions
 The function always returns the same value for the same inputs. A pure function’s return
value is based only on its inputs and has no other dependencies or effects on the overall
program. For any given input, a pure function must return exactly one possible value.
 Evaluation of the function has no side effects. Side effects refer to changing other attributes of
the program not contained within the function, such as changing global variable values or using
I/O streams.

4c) Definition of static type checking and why it’s better than dynamic type checking.
 Static type checking is a type checking performed at compile time. It checks the type variables
at compile-time, which means the type of the variable is known at the compile time.
 With static type checking, the type of variable is known at compile time (it checks the type of
variable before running) while with dynamic type checking, the type of variable is known at
runtime (it checks the type of variable while executing).

4d) Data abstraction is a set of data that specifies and describes a data object, while Control
abstraction is a program control mechanism where interior details are not specified.

QUESTION FIVE
5a) In static semantics, knowing the meaning of a sentence amounts to knowing when it is true;
in dynamic semantics, knowing the meaning of a sentence means knowing "the change it brings
about in the information state of anyone who accepts the news conveyed by it."

5b) Language Categories


 Imperative
– Central features are variables, assignment statements, and iteration
– Examples: C, Pascal
 Functional
– Main means of making computations is by applying functions to given
parameters
– Examples: LISP, Scheme
 Logic
– Rule-based (rules are specified in no particular order)
– Example: Prolog
 Object-oriented
– Data abstraction, inheritance, late binding
– Examples: Java, C++
 Markup
– New; not a programming per se, but used to specify the layout of information
in Web documents
– Examples: XHTML, XML
5c).
i) Data abstraction is the programming process of creating a data type, usually a class, that
hides the details of the data representation in order to make the data type easier to work with

ii) Data abstraction provides two important advantages −


 Class internals are protected from inadvertent user-level errors, which might corrupt the
state of the object.
 The class implementation may evolve over time in response to changing requirements or
bug reports without requiring change in user-level code.

You might also like