0% found this document useful (0 votes)
122 views4 pages

Exam Questions on Programming Paradigms

This document is a quiz on programming paradigms and object-oriented programming. It contains 8 multiple choice questions that assess understanding of key concepts such as programming paradigms, features of procedural, object-oriented, logic and functional programming, definitions of object-oriented programming and its basic concepts like objects, classes, encapsulation, inheritance, polymorphism and dynamic binding. It also asks about benefits and applications of OOP and input/output operators in C++.

Uploaded by

Nang Nur Ain
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)
122 views4 pages

Exam Questions on Programming Paradigms

This document is a quiz on programming paradigms and object-oriented programming. It contains 8 multiple choice questions that assess understanding of key concepts such as programming paradigms, features of procedural, object-oriented, logic and functional programming, definitions of object-oriented programming and its basic concepts like objects, classes, encapsulation, inheritance, polymorphism and dynamic binding. It also asks about benefits and applications of OOP and input/output operators in C++.

Uploaded by

Nang Nur Ain
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

MTS 3053 PROGRAMMING PARADIGM

Quiz

Name: Nurul Aini Binti Abdul Amin Marks: _________________
Matric: D20111048084 Time: 2 Hours

Instruction: Answer all questions.

1. What do you mean by programming paradigms? (3 marks)
Answer:
- A programming paradigm is a style or way of programming. Some languages make it
easy to write in some paradigms but not others.


2. State key features of following paradigms: (12 marks)
a. Procedural programming
b. Object oriented programming
c. Logic programming
d. Functional programming

Answer:
a. Procedural programming
- Execution of computational steps in an order governed by control structures

b. Object oriented programming
- Computation is effected by sending messages to objects; objects have state and
behavior.

c. Logic programming
- Programmer specifies a set of facts and rules, and an engine infers the answers to
questions.

d. Functional programming
- Computation proceeds by (nested) function calls that avoid any global state.








3. Define Object Oriented Programming (OOP) (3 marks)
Answer:
- A type of programming in which programmers define not only the data type of a data
structure, but also the types of operations (functions) that can be applied to the data
structure. In this way, the data structure becomes an object that includes both data and
functions. In addition, programmers can create relationships between one object and
another.


4. Discuss in details the basic concepts of Object Oriented Programming (OOP) (21 marks)

Answers:
Objects
- An object can be considered a "thing" that can perform a set of activities. The set of
activities that the object performs defines the object's behavior.
- It is directly relate to the real world entities.
- Object has an attribute (description of objects in class), method (an action performed
by an object) and identity (unique name)


Classes
- A generic definition for a set of similar objects.
- Provides the specifications for the objects behaviors and attributes.
- An abstraction of a real world entity


Data abstraction
Answer:
- Abstraction is the process of recognizing and focusing on important characteristics of a
situation or object and leaving/filtering out the un-wanted characteristics of that
situation or [Link] take a person as example and see how that person is abstracted
in various situations

Example :
A doctor sees (abstracts) the person as patient. The doctor is interested in name, height,
weight, age, blood group, previous or existing diseases etc of a person

An employer sees (abstracts) a person as Employee. The employer is interested in name,
age, health, degree of study, work experience etc of a person.






Encapsulation
Answer:
- Encapsulation is a process of tying together all data and methods that form a class and
control the access to data by hiding its information.
- It enables access to object just by using methods of that object.
- It is one of the security features in object-oriented programming (OOP).


Inheritance
Answer:
- Inheritance allows a class to have the same behavior as another class and extend or
tailor that behavior to provide special action for specific needs.


Polymorphism
Answer:
- Polymorphism allows two or more objects respond to the same message.
- Polymorphism allows a sending object to communicate with different objects in a
consistant manner without worrying about how many different implementations of a
message.
- Polymorphism allows the sending object to communicate with receiving objects without
having to understand what type of object it is, as long as the receiving objects support
the messages.


Dynamic binding
Answer:
- Dynamic binding(dispatch) means that a block of code executed with reference to a
procedure(method) call is determined at run time.
- Dynamic dispatch is generally used when multiple classes contain different
implementations of the same method. It provides a mechanism for selecting the
function to be executed from various function alternatives at the run-time. In C++,
virtual functions are used to implement dynamic binding.


Message passing
Answer:
- A type of communication between processes. Message passing is a form of
communication used in parallel programming and object-oriented programming.
Communications are completed by the sending of messages (functions, signals and data
packets) to recipients.




5. List out some of the benefits of OOP (6 marks)
Answer:
- OOP provides a clear modular structure for programs which makes it good for defining
abstract datatypes where implementation details are hidden and the unit has a clearly
defined interface.
- OOP makes it easy to maintain and modify existing code as new objects can be created
with small differences to existing ones.
- OOP provides a good framework for code libraries where supplied software
components can be easily adapted and modified by the programmer. This is particularly
useful for developing graphical user interfaces.


6. List out the applications of OOP (6 marks)
Answer:
- User interface design such as windows, menu ,
- Real Time Systems
- Simulation and Modeling
- Object oriented databases
- AI and Expert System
- Neural Networks and parallel programming
- Decision support and office automation system


7. C++ is a one example of OOP. What are the input and output operators used in C++?
Answer: (6 marks)
Input - cin
Output - cout



8. What is meant by static function? (3 marks)
Answer:
- Static functions are functions that are only visible to other functions in the same file.
- Access to static functions is restricted to the file where they are declared.

Common questions

Powered by AI

Dynamic binding is crucial in scenarios where a program involves multiple classes with different implementations of the same method, such as in polymorphic object structures . It enables method calls to be resolved at runtime, providing flexibility by allowing the selection of appropriate method implementations based on the object instance. This flexibility supports the design of extensible systems where behavior can be dynamically adjusted, an advantage in frameworks and design patterns that rely on runtime decision-making, like strategy or state patterns. This feature enhances the ability to manage code bases with evolving requirements without altering existing code structures .

Polymorphism in Object-Oriented Programming allows objects to be processed differently depending on their data type or class, but through a uniform interface . This enables a single function call to behave differently based on which object it is operating on, thus providing flexibility in the code as the same operation can adapt to different data. It is facilitated typically through inheritance and interfaces, allowing for method overriding and the use of abstract classes. Polymorphism distinguishes OOP from other paradigms, such as procedural or functional programming, by its ability to handle and maintain extensibility through dynamic method dispatch at runtime. This promotes reusability of functions across objects of different types while maintaining a consistent interface, leading to simpler, more flexible, and modular code .

Inheritance contributes to software extensibility and reuse by allowing a new class (child class) to inherit properties and methods from an existing class (parent class), facilitating the extension or modification of inherited behavior without altering the original class . This capability supports the building of hierarchical class structures where advanced functionalities are added incrementally. It promotes code reuse, as common logic is centralized in base classes, reducing duplication and enhancing consistency across the class hierarchy .

Message passing is crucial in Object-Oriented Programming as it facilitates communication between objects, enabling them to interact and behave cohesively within a program . It supports the encapsulation principle by allowing objects to request services or information from one another without exposing their internal workings. Messages are sent to invoke methods, providing the flexibility for objects to respond in different ways depending on their state or type. This abstraction layer simplifies object interaction, leading to more maintainable and adaptable code structures, particularly in complex systems where modular interaction is essential .

The defining features of object-oriented programming include encapsulation, inheritance, polymorphism, and dynamic binding. Encapsulation allows data and methods to be enclosed within a class, providing security and data hiding . Inheritance enables a class to inherit properties and behavior from another class, facilitating code reuse and extension without modifying existing code . Polymorphism allows objects to be treated as instances of their parent class, enabling one interface to be used for a general class of actions . Dynamic binding, or dispatch, determines the procedure to be called at runtime, enhancing flexibility and enabling different implementations of a method to be executed depending on the object type . Together, these features support the modular design, code reuse, and scalability required for complex systems.

Encapsulation secures data within an object by bundling the data with the methods that operate on them and restricting direct access from outside the object . It ensures that an object can only be manipulated through its methods, protecting the integrity and security of the object's data by preventing unauthorized access or modification. This mechanism provides a controlled interface, allowing class implementation changes without affecting external code that relies on the class, enhancing both security and maintainability of code .

Procedural programming approaches computation through a sequence of ordered steps executed by control structures . It relies heavily on mutable state and sequential statements. In contrast, functional programming treats computation as the evaluation of mathematical functions, emphasizing immutability and statelessness; functions are treated as first-class citizens, and computations are results of function calls rather than sequences of instructions . Key differences include procedural programming's reliance on control structures versus functional programming's focus on evaluation and transformation using pure functions, which eliminates side effects and enhances predictability.

Procedural programming focuses on the sequence of executable commands, where the execution is governed by control structures such as loops and conditionals . It treats data and functions separately. In contrast, object-oriented programming (OOP) combines data and functions into objects, enabling encapsulation and interaction through messages sent to objects . OOP supports inheritance and polymorphism, allowing for code reuse and flexibility, features that procedural programming lacks. This makes OOP more suited for large, complex systems requiring modular design and dynamic behavior modification.

Object-Oriented Programming (OOP) provides a modular structure that promotes extensive code reuse through inheritance, allowing new objects to easily modify and extend existing ones . Its encapsulation feature secures data within objects, simplifies maintenance by clearly defining interfaces, and hides implementation details. This invisibility and modularity make it easier to update and maintain software. Additionally, OOP supports the creation of code libraries, where supplied components can be adapted as needed, facilitating efficient reuse across different projects .

Object-Oriented Programming is applied in user interface design, real-time systems, simulation and modeling, object-oriented databases, AI and expert systems, neural networks, parallel programming, and decision support and office automation systems . OOP is especially suited for these domains due to its modularity and ability to model complex systems as a collection of interacting objects, each encapsulating data and behavior. This approach mirrors real-world entities and processes, facilitating natural representation, flexibility, maintenance, adaptability, and the ability to manage increasingly complex system requirements efficiently .

You might also like