




















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
ECE 105 Programming for Engineers II - Final Exam Review (Qns & Ans) - DU 2025ECE 105 Programming for Engineers II - Final Exam Review (Qns & Ans) - DU 2025ECE 105 Programming for Engineers II - Final Exam Review (Qns & Ans) - DU 2025ECE 105 Programming for Engineers II - Final Exam Review (Qns & Ans) - DU 2025
Typology: Exams
1 / 28
This page cannot be seen from the preview
Don't miss anything!
Section I – Multiple Choice (8 Questions) Question 1: Which of the following best describes the purpose of using decorators in Python? A. To improve runtime performance by compiling functions B. To dynamically modify or enhance the behavior of functions or methods without changing their code C. To optimize memory usage in large-scale computations D. To enforce strict data type checking at runtime ANS: B Rationale: Decorators are used to wrap a function, method, or class, thereby extending or altering its behavior at runtime without modifying its source code—a powerful tool for logging, access control, or caching.
Question 2: In the context of scientific computing with Python, which library is most commonly used for large-scale numerical operations on arrays and matrices? A. Matplotlib B. NumPy C. Pandas D. SciPy ANS: B Rationale: NumPy provides a powerful N-dimensional array object and a collection of routines for fast operations on arrays; it serves as the foundational library for numerical computing and is extensively used in engineering applications.
for reclaiming memory from objects that are no longer referenced? A. Manual garbage collection B. Reference counting (with a cyclic garbage collector for cycles) C. Stack allocation exclusively D. Copy-on-write strategy ANS: B Rationale: Python utilizes reference counting to automatically manage memory; objects with zero references are reclaimed, and a cyclic garbage collector handles groups of objects in reference cycles.
Question 6: Which of the following best explains the role of unit testing in engineering software development? A. Ensuring that an entire application performs well under load B. Verifying that individual components or functions work correctly in isolation C. Optimizing code for speed D. Validating user interface design ANS: B Rationale: Unit testing involves writing tests for individual functions or modules to verify that each part behaves as expected—an essential practice for maintaining reliable and robust engineering code.
Question 7: In advanced usage of file I/O in Python, what is the benefit of using the with
statement (context managers) when opening files? A. It automatically compresses file content B. It ensures that the file is properly closed after its block of code is executed, even if an exception occurs
C. It converts file content to binary format D. It speeds up file reading operations significantly ANS: B Rationale: The with
statement simplifies resource management by handling file closure and cleanup automatically, thus avoiding resource leaks such as open files that can lead to errors in long-running programs.
Question 8: Which Python module provides functions to create and manipulate processes and threads for concurrent execution, particularly useful in computationally intensive engineering applications? A. math B. threading (and multiprocessing) C. socket D. collections ANS: B Rationale: Python’s threading
and multiprocessing
modules support concurrent programming by allowing tasks to run in parallel; multiprocessing is especially useful to bypass Python’s Global Interpreter Lock (GIL) in CPU-bound tasks.
Section II – Fill-in-the-Blank (4 Questions) Question 9: In Python, the special method ______()
is used to initialize an instance of a class. ANS: __init__
Rationale: The __init__
method is the initializer (or constructor) in Python classes, automatically invoked when a new object is created to
Question 13: True or False: Python is a statically typed language, meaning that variable types must be declared explicitly before assignment. ANS: False Rationale: Python is dynamically typed; variable types are determined at runtime, and explicit declarations are not required.
Question 14: True or False: In Python, list comprehensions provide a concise way to generate lists and can often replace the use of loops for creating new lists with transformations. ANS: True Rationale: List comprehensions are a syntactically compact alternative to for-loops for creating lists, often making code easier to read and more Pythonic.
Question 15: True or False: The Python Global Interpreter Lock (GIL) prevents multiple native threads from executing Python bytecodes simultaneously, which can limit parallelism in CPU-bound tasks. ANS: True Rationale: The GIL in CPython ensures that only one thread executes Python bytecode at a time, thus limiting effective parallel execution of CPU-bound operations in multi-threaded programs.
Question 16: True or False: Exception handling in Python is optional; if an exception occurs and is not handled, the program will always continue execution.
ANS: False Rationale: Unhandled exceptions in Python propagate up the call stack, and if not caught, they terminate the program with an error message.
Section IV – Multiple Response (4 Questions) Question 17: Which of the following features are benefits of using the NumPy library in Python for engineering computations? (Select all that apply.) A. Efficient handling of large, multi-dimensional arrays B. Builtin vectorized operations that improve performance C. Native support for symbolic mathematics D. Integration with C/C++ code for speed-critical functions E. In-built machine learning algorithms ANS: A, B, D Rationale: NumPy excels at handling large arrays efficiently, supports vectorized operations to reduce loop overhead, and integrates easily with compiled C/C++ code. It does not natively provide symbolic mathematics (that is provided by libraries like SymPy) or full machine learning algorithms (which are available in libraries such as scikit-learn).
Question 18: When optimizing code performance in Python, which of the following techniques are commonly employed? (Select all that apply.) A. Algorithmic improvements B. Leveraging built-in functions and libraries C. Increasing the recursion limit indiscriminately D. Using generators to handle large data streams E. Avoiding the use of any third-party libraries
Rationale: Functional programming emphasizes immutability, higher- order functions, recursion, and can also employ decorators to modify or enhance functions. Heavy use of global variables contradicts functional programming principles, as it compromises modularity and predictability. Which of the following best describes the concept of recursion in programming? a) A function that calls itself directly or indirectly. b) A function that calls another function. c) A function that does not return a value. d) A function that is only used once in a program. ANS: a) A function that calls itself directly or indirectly. Rationale: Recursion is a powerful programming technique where a function solves a problem by calling a simpler version of itself. Fill-in-the-Blank: In object-oriented programming, \_\_\ is the process of creating new classes from existing ones, inheriting their attributes and methods. ANS: Inheritance Rationale: Inheritance allows for code reuse and the creation of hierarchical class structures. True/False: Pointers in C/C++ directly store the value of a variable. ANS: False Rationale: Pointers store the memory address of a variable, not its value.
Multiple Response: Which of the following are advantages of using dynamic memory allocation? (Select all that apply) a) Fixed memory size at compile time. b) Flexibility in managing memory during runtime. c) Potential for memory leaks. d) Efficient memory usage. ANS: b) Flexibility in managing memory during runtime. c) Potential for memory leaks. d) Efficient memory usage. Rationale: Dynamic memory allocation allows programs to request memory as needed, but it also requires careful management to avoid memory leaks. Multiple Choice: What is the purpose of a Makefile in a C/C++ project? a) To store the source code. b) To automate the compilation process. c) To execute the program. d) To debug the code. ANS: b) To automate the compilation process. Rationale: Makefiles define the steps needed to compile and link a project, making it easier to build and manage. Fill-in-the-Blank: \_\_\ is a data structure that follows the Last-In, First-Out (LIFO) principle. ANS: Stack
c) The ability of an object to take on many forms. d) The inheritance of properties from a parent class. ANS: b) The bundling of data and methods that operate on that data within a class. Rationale: Encapsulation protects data from direct access and modification from outside the class. Fill-in-the-Blank: The process of finding and fixing errors in a program is known as \_\_\. ANS: Debugging Rationale: Debugging is a crucial part of the software development process. True/False: In C++, the new operator is used to deallocate dynamically allocated memory. ANS: False Rationale: The delete operator is used to deallocate dynamically allocated memory in C++. Multiple Response: Which of the following are important considerations when writing multithreaded programs? (Select all that apply) a) Thread synchronization. b) Race conditions. c) Memory leaks. d) Single-threaded execution.
ANS: a) Thread synchronization. b) Race conditions. c) Memory leaks. Rationale: Multithreaded programming introduces complexities that must be carefully managed. Multiple Choice: What is the purpose of a constructor in a class? a) To destroy an object. b) To initialize the object's data members. c) To define the class's methods. d) To create a new class. ANS: b) To initialize the object's data members. Rationale: Constructors are special methods that are automatically called when an object is created. Fill-in-the-Blank: A \_\_\ is a data structure that follows the First-In, First-Out (FIFO) principle. ANS: Queue Rationale: Queues are used in various applications, such as task scheduling and data buffering. True/False: Abstraction hides complex implementation details and presents only essential information to the user. ANS: True Rationale: Abstraction simplifies the use of complex systems.
True/False: Overloading refers to the ability to define multiple functions with the same name but different parameters. ANS: True Rationale: Overloading enhances code flexibility and readability. Multiple Response: Which of the following are common file I/O operations? (Select all that apply) a) Opening a file. b) Reading data from a file. c) Writing data to a file. d) Defining classes. ANS: a) Opening a file. b) Reading data from a file. c) Writing data to a file. Rationale: File I/O is essential for interacting with external data sources.
A software module for a motor controller uses a callback function for interrupt handling. Which language construct is most pertinent for safely associating a peripheral event with its callback? A) Abstract Class B) Function Pointer C) Namespace D) Destructor ANS: B) Function Pointer
Rationale: Function pointers enable assignment of callback functions for hardware events typical in embedded engineering contexts.
Which of the following best describes polymorphism's role in device driver development for various sensors? A) It allows multiple variables to have the same name. B) It enables interfaces to process sensor data differently based on sensor type. C) It reduces code duplication by removing all comments. D) It automates hardware interrupts. ANS: B Rationale: Polymorphism enables interfaces to process diverse data from sensors through shared interfaces.
In a multithreaded image processing app, which synchronization mechanism prevents simultaneous write-access to shared image buffers? A) Semaphore B) Stack C) Array D) Lambda Function ANS: A Rationale: Semaphores manage concurrent access, preventing race conditions.
Given the definition std::vector
A) It hides bugs. B) It allows the firmware to recover from or report run-time anomalies such as invalid voltage readings. C) It automatically optimizes battery performance. D) It increases the maximum clock speed. ANS: B Rationale: Exception handling provides robust error reporting/recovery.
In analyzing a time-series signal, which algorithm efficiently searches for a matching subsequence in large datasets? A) Binary Search B) Linear Search C) Rabin-Karp Algorithm D) Selection Sort ANS: C Rationale: Rabin-Karp is optimized for searching substrings or subsequences.
What is the time complexity of inserting an element at the beginning of std::list in C++? A) O(1) B) O(n) C) O(n log n) D) O(log n) ANS: A Rationale: std::list allows constant time insertions at both ends.
Which C++ access specifier should be used to prevent external classes from reading or modifying a variable in a class? A) public B) protected C) private D) virtual ANS: C Rationale: private restricts access to class members. FILL-IN-THE-BLANK
A sorting algorithm commonly used in real-time embedded systems for small datasets due to its low overhead is called __ sort. ANS: Insertion Rationale: Insertion sort is simple and efficient for small/real-time datasets.
The software principle advocating that each class should have only one responsibility is known as the __ Principle in software design. ANS: Single Responsibility Rationale: Part of SOLID design principles; promotes maintainable code.
In C++, a static method can be called without creating a(n) __ of the class. ANS: instance/object Rationale: Static methods do not require an object instance.