Docsity

WGU D278 Scripting and Programming Foundations, Exams of Digital Logic Design and Programming

Toggle sidebar
bg1
WGU D278 Scripting and Programming Foundations
Practise Questions
Note: Questions cover fundamental programming concepts, logic, and scripting principles
relevant to this foundational course.
TOPIC 1: Programming Fundamentals and Logic
1. Multiple Choice:
What is the primary purpose of a compiler in the software development process?
A) To execute the program line by line
B) To translate high-level code into machine code all at once
C) To debug syntax errors during runtime
D) To convert machine code to assembly language
Answer: B
Explanation: A compiler translates the entire source code program into machine code (object
code) before execution, unlike an interpreter which executes line by line.
2. Multiple Choice:
Which of the following best describes an algorithm?
A) A programming language syntax
B) A step-by-step procedure for solving a problem
C) The hardware components of a computer
D) A type of data structure
Answer: B
Explanation: An algorithm is a finite sequence of well-defined, unambiguous instructions for
solving a specific problem or accomplishing a task.
3. Multiple Choice:
What is the output of the following logical expression: (True AND False) OR (NOT False)?
A) True
B) False
C) 1
D) 0
Answer: A
Explanation: (True AND False) = False. (NOT False) = True. False OR True = True.
4. Multiple Choice:
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24

Partial preview of the text

Download WGU D278 Scripting and Programming Foundations and more Exams Digital Logic Design and Programming in PDF only on Docsity!

WGU D278 Scripting and Programming Foundations

Practise Questions

Note: Questions cover fundamental programming concepts, logic, and scripting principles relevant to this foundational course.

TOPIC 1: Programming Fundamentals and Logic

  1. Multiple Choice: What is the primary purpose of a compiler in the software development process? A) To execute the program line by line B) To translate high-level code into machine code all at once C) To debug syntax errors during runtime D) To convert machine code to assembly language Answer: B Explanation: A compiler translates the entire source code program into machine code (object code) before execution, unlike an interpreter which executes line by line.
  2. Multiple Choice: Which of the following best describes an algorithm? A) A programming language syntax B) A step-by-step procedure for solving a problem C) The hardware components of a computer D) A type of data structure Answer: B Explanation: An algorithm is a finite sequence of well-defined, unambiguous instructions for solving a specific problem or accomplishing a task.
  3. Multiple Choice: What is the output of the following logical expression: (True AND False) OR (NOT False)? A) True B) False C) 1 D) 0 Answer: A Explanation: (True AND False) = False. (NOT False) = True. False OR True = True.
  4. Multiple Choice:

Which programming paradigm emphasizes procedures and function calls? A) Object-oriented programming B) Functional programming C) Procedural programming D) Logical programming Answer: C Explanation: Procedural programming focuses on procedures or functions that operate on data, following a top-down approach.

  1. Multiple Choice: What does the term "pseudocode" refer to? A) Machine code that is difficult to read B) A programming language used for web development C) An informal high-level description of program logic D) Code that contains syntax errors Answer: C Explanation: Pseudocode uses natural language mixed with programming constructs to describe algorithms without specific syntax requirements.
  2. Multiple Choice: Which of the following is NOT a basic control structure in programming? A) Sequence B) Selection C) Iteration D) Compilation Answer: D Explanation: The three basic control structures are sequence (executing in order), selection (if/else), and iteration (loops). Compilation is a translation process.
  3. Multiple Choice: What is the purpose of a variable in programming? A) To store a fixed value that cannot change B) To name a memory location that can hold different values C) To execute conditional statements D) To define program functions Answer: B Explanation: A variable is a named storage location in memory that holds data values which can change during program execution.
  4. Multiple Choice: Which data type would be most appropriate for storing a person's age? A) Float B) String C) Boolean
  1. Multiple Choice: What does IDE stand for in software development? A) Integrated Development Environment B) International Data Exchange C) Interactive Debugging Environment D) Integrated Deployment Engine Answer: A Explanation: An IDE is a software application that provides comprehensive facilities for software development, including code editor, debugger, and compiler.
  2. Multiple Choice: Which of the following is an example of a high-level programming language? A) Assembly language B) Machine code C) Python D) Binary code Answer: C Explanation: Python is a high-level language that uses human-readable syntax, unlike low-level languages like assembly or machine code.
  3. Multiple Choice: What is the purpose of comments in source code? A) To execute specific commands B) To improve program performance C) To document code for human readers D) To fix syntax errors Answer: C Explanation: Comments are non-executable annotations that explain code functionality, making it easier for programmers to understand and maintain.
  4. Multiple Choice: Which symbol is commonly used for single-line comments in Python? A) // B) / C) D) -- Answer: C Explanation: In Python, the hash symbol () is used for single-line comments. Some other languages use // or other symbols.
  5. Multiple Choice: What does the term "boolean" refer to in programming? A) A data type with two possible values

B) A type of loop structure C) A mathematical operation D) A variable naming convention Answer: A Explanation: Boolean is a data type that can have only two values: true or false (or 1 and 0 in some languages).

  1. Multiple Choice: Which of the following is a valid variable name in most programming languages? A) 1stVariable B) variable-name C) _variable D) variable name Answer: C Explanation: Variable names typically cannot start with numbers, cannot contain spaces, and cannot contain hyphens in most languages. Underscores are usually allowed.
  2. Multiple Choice: What is the term for converting a value from one data type to another? A) Concatenation B) Type casting C) Variable assignment D) Syntax parsing Answer: B Explanation: Type casting (or type conversion) explicitly converts a value from one data type to another, such as converting a string to an integer.
  3. Multiple Choice: Which operator is used to compare two values for equality in most languages? A) = B) == C) === D) != Answer: B Explanation: The double equals (==) is the comparison operator for equality. The single equals (=) is typically the assignment operator.

TOPIC 2: Control Structures and Flow

  1. Multiple Choice: What is the purpose of an if statement in programming?

Answer: A Explanation: An infinite loop occurs when the loop's termination condition is never met, causing it to run indefinitely until interrupted.

  1. Multiple Choice: Which statement is used to immediately exit a loop? A) stop B) exit C) break D) continue Answer: C Explanation: The break statement terminates the current loop and transfers control to the statement immediately following the loop.
  2. Multiple Choice: What does the continue statement do in a loop? A) Exits the entire program B) Skips the rest of the current iteration and continues with the next C) Terminates the loop immediately D) Restarts the loop from the beginning Answer: B Explanation: The continue statement skips the remaining code in the current loop iteration and proceeds to the next iteration.
  3. Multiple Choice: In a for loop, what are the three main components typically specified? A) Initialization, condition, and increment B) Start, middle, and end C) Input, process, output D) Variable, value, and type Answer: A Explanation: A standard for loop structure includes initialization (starting value), condition (when to stop), and increment (how to change the variable each iteration).
  4. Multiple Choice: What is a nested loop? A) A loop inside another loop B) A loop that contains if statements C) A loop with multiple conditions D) A loop that calls itself Answer: A Explanation: A nested loop is a loop structure where one loop is placed inside the body of another loop.
  1. Multiple Choice: Which control structure would be most appropriate for processing each element in an array? A) if-else statement B) while loop C) for loop D) switch statement Answer: C Explanation: A for loop is ideal for iterating through arrays or collections when the number of iterations is known or based on the collection size.
  2. Multiple Choice: What is the purpose of a switch statement? A) To repeat code based on a condition B) To select one of many code blocks to execute C) To define multiple variables at once D) To handle runtime errors Answer: B Explanation: A switch statement provides an efficient way to dispatch execution to different parts of code based on the value of an expression.
  3. Multiple Choice: In a switch statement, what does the "default" case represent? A) The first case to be checked B) The case that always executes C) The case when no other cases match D) The most important case Answer: C Explanation: The default case in a switch statement executes when none of the other case values match the expression.
  4. Multiple Choice: What is short-circuit evaluation in logical expressions? A) Evaluating all parts of an expression regardless of the result B) Stopping evaluation as soon as the result is determined C) Evaluating expressions in reverse order D) Skipping expression evaluation entirely Answer: B Explanation: Short-circuit evaluation stops evaluating logical expressions as soon as the final result can be determined (e.g., false AND anything = false).
  5. Multiple Choice: Which operator has higher precedence: AND (&&) or OR (||)? A) AND has higher precedence B) OR has higher precedence

Explanation: A loop control variable is a variable whose value controls the execution of a loop, typically modified within the loop to eventually cause termination.

  1. Multiple Choice: Which statement is true about the break statement in nested loops? A) It exits all nested loops simultaneously B) It only exits the innermost loop containing it C) It exits the entire program D) It cannot be used in nested loops Answer: B Explanation: A break statement only exits the loop in which it's directly contained, not any outer loops in a nested structure.
  2. Multiple Choice: What is a sentinel value? A) A value that indicates the end of data input B) A value that starts a loop C) A special value used in array indexing D) A value that represents true in boolean expressions Answer: A Explanation: A sentinel value is a special value used to signal the end of data entry in loops that process user input.

TOPIC 3: Functions and Modular Programming

  1. Multiple Choice: What is the primary advantage of using functions in programming? A) They make programs run faster B) They reduce code duplication and improve organization C) They automatically fix syntax errors D) They eliminate the need for variables Answer: B Explanation: Functions promote code reuse, reduce duplication, improve readability, and make programs easier to maintain and debug.
  2. Multiple Choice: What are the values passed to a function called? A) Returns B) Parameters C) Arguments D) Variables

Answer: C Explanation: Arguments are the actual values passed to a function when it's called. Parameters are the variables in the function definition that receive these values.

  1. Multiple Choice: What does a function return statement do? A) Ends the program B) Sends a value back to the calling code C) Prints output to the screen D) Declares a new variable Answer: B Explanation: The return statement sends a value back to the code that called the function and exits the function.
  2. Multiple Choice: What is a void function? A) A function that returns no value B) A function with no parameters C) A function that always returns zero D) An empty function Answer: A Explanation: A void function (in languages like Java/C++) or a function without a return statement (in Python) performs actions but doesn't return a value.
  3. Multiple Choice: What is the difference between parameters and arguments? A) Parameters are used in function calls, arguments in definitions B) Arguments are used in function calls, parameters in definitions C) They are the same thing D) Parameters are values, arguments are variables Answer: B Explanation: Parameters are the variables listed in the function definition. Arguments are the actual values passed to the function when it's called.
  4. Multiple Choice: What is a local variable? A) A variable declared outside all functions B) A variable accessible from anywhere in the program C) A variable declared inside a function D) A special type of constant Answer: C Explanation: A local variable is declared within a function and is only accessible within that function's scope.

C) Passing only constants to functions D) Passing variables without specifying type Answer: B Explanation: In pass-by-value, a copy of the argument's value is passed to the function, so changes to the parameter don't affect the original argument.

  1. Multiple Choice: What is pass-by-reference? A) Passing a copy of the variable's value B) Passing the memory address of the variable C) Passing only read-only values D) Passing functions as arguments Answer: B Explanation: In pass-by-reference, the memory address of the argument is passed, allowing the function to modify the original variable.
  2. Multiple Choice: What is a default parameter? A) A parameter that must be provided when calling the function B) A parameter with a predefined value used when no argument is provided C) The first parameter in a function D) A parameter that cannot be changed Answer: B Explanation: Default parameters have predefined values that are used if the caller doesn't provide a corresponding argument.
  3. Multiple Choice: What is recursion? A) A function calling another function B) A function calling itself C) A loop that never ends D) Multiple functions with the same name Answer: B Explanation: Recursion occurs when a function calls itself directly or indirectly to solve a problem by breaking it into smaller subproblems.
  4. Multiple Choice: What is the base case in a recursive function? A) The first call to the function B) The condition that stops the recursion C) The recursive call itself D) The return value of the function Answer: B

Explanation: The base case is the condition that stops the recursion by returning a value without making another recursive call, preventing infinite recursion.

  1. Multiple Choice: What is a library function? A) A function defined by the programmer B) A pre-written function available for use C) A function that only works with arrays D) A function that cannot be modified Answer: B Explanation: Library functions are pre-written functions provided by the programming language or external libraries to perform common tasks.
  2. Multiple Choice: What is function scope? A) The region of code where a function can be called B) The region of code where a variable is accessible C) The number of parameters a function has D) The return type of a function Answer: B Explanation: Scope defines where in the code a variable can be accessed. Function scope means the variable is only accessible within that function.
  3. Multiple Choice: What is an inline function? A) A function that is expanded at the point of call B) A function that cannot be called from other functions C) A function with no parameters D) A function that returns immediately Answer: A Explanation: An inline function (when supported by the language) is expanded at the point of call rather than executing a function call, potentially improving performance for small functions.
  4. Multiple Choice: What is a callback function? A) A function that calls another function B) A function passed as an argument to another function C) A function that returns a function D) A recursive function Answer: B Explanation: A callback function is passed as an argument to another function and is invoked ("called back") at a later point, often in response to an event.
  5. Multiple Choice:
  1. Multiple Choice: What is a list (in languages like Python)? A) A fixed-size collection B) A dynamic array that can grow and shrink C) A key-value pair collection D) A sorted collection Answer: B Explanation: In Python and similar languages, a list is a dynamic, mutable, ordered collection that can hold elements of different types and can change size.
  2. Multiple Choice: What is a tuple? A) A mutable, ordered collection B) An immutable, ordered collection C) An unordered collection of unique elements D) A key-value pair collection Answer: B Explanation: A tuple is an immutable, ordered collection of elements. Once created, its elements cannot be changed, added, or removed.
  3. Multiple Choice: What is a dictionary (in Python) or map (in other languages)? A) An ordered collection of elements B) A collection of key-value pairs C) A fixed-size array D) A sorted list Answer: B Explanation: A dictionary/map stores data as key-value pairs, allowing fast lookup by key rather than by position/index.
  4. Multiple Choice: What is a set? A) An ordered collection with duplicates allowed B) An unordered collection of unique elements C) A key-value pair collection D) A fixed-size array Answer: B Explanation: A set is an unordered collection of unique elements with no duplicates, supporting mathematical set operations like union and intersection.
  5. Multiple Choice: Which data structure uses FIFO (First-In, First-Out) ordering? A) Stack B) Queue

C) Array D) Set Answer: B Explanation: A queue follows FIFO ordering: the first element added is the first one removed, like a line of people waiting.

  1. Multiple Choice: Which data structure uses LIFO (Last-In, First-Out) ordering? A) Queue B) Stack C) Array D) Dictionary Answer: B Explanation: A stack follows LIFO ordering: the last element added is the first one removed, like a stack of plates.
  2. Multiple Choice: What is the time complexity of accessing an element by index in an array? A) O(1) - constant time B) O(n) - linear time C) O(log n) - logarithmic time D) O(n²) - quadratic time Answer: A Explanation: Array access by index is O(1) because the memory address can be calculated directly using the base address and index.
  3. Multiple Choice: What is indexing in the context of arrays/lists? A) Finding an element by its value B) Accessing an element by its position C) Sorting the elements D) Counting the elements Answer: B Explanation: Indexing refers to accessing elements by their numerical position (index) in an ordered collection like an array or list.
  4. Multiple Choice: What is slicing? A) Accessing a single element B) Extracting a portion of a sequence C) Sorting elements in reverse order D) Removing all elements Answer: B
  1. Multiple Choice: What is a hash table? A) A sorted array B) A data structure that maps keys to values using a hash function C) A type of linked list D) A fixed-size collection Answer: B Explanation: A hash table (or hash map) uses a hash function to compute an index into an array of buckets/slots, providing efficient key-value storage and retrieval.
  2. Multiple Choice: What is an algorithm's time complexity? A) How much memory it uses B) How fast it runs on a specific computer C) How its runtime grows with input size D) The number of lines of code Answer: C Explanation: Time complexity describes how an algorithm's runtime increases as the size of the input increases, expressed using Big O notation (O(n), O(log n), etc.).
  3. Multiple Choice: What is the time complexity of linear search on an unsorted array? A) O(1) B) O(log n) C) O(n) D) O(n²) Answer: C Explanation: Linear search examines each element sequentially in the worst case, giving O(n) time complexity for an array of n elements.
  4. Multiple Choice: What is the time complexity of binary search on a sorted array? A) O(1) B) O(log n) C) O(n) D) O(n log n) Answer: B Explanation: Binary search repeatedly divides the search interval in half, giving O(log n) time complexity for a sorted array of n elements.

TOPIC 5: Object-Oriented Programming Concepts

  1. Multiple Choice: What is the fundamental concept of object-oriented programming? A) Using only global variables B) Organizing code around functions C) Modeling programs as collections of interacting objects D) Avoiding the use of classes Answer: C Explanation: OOP organizes software design around data (objects) rather than functions and logic, with objects containing both data and methods.
  2. Multiple Choice: What is a class in OOP? A) An instance of an object B) A blueprint for creating objects C) A type of function D) A collection of variables Answer: B Explanation: A class is a template or blueprint that defines the attributes (data) and methods (functions) that objects created from the class will have.
  3. Multiple Choice: What is an object? A) A blueprint for creating classes B) An instance of a class C) A standalone function D) A type of variable Answer: B Explanation: An object is an instance of a class, created from the class blueprint, with its own set of attribute values.
  4. Multiple Choice: What is encapsulation? A) Breaking a program into multiple files B) Hiding implementation details and exposing only necessary interfaces C) Creating multiple classes with the same name D) Inheriting properties from multiple classes Answer: B Explanation: Encapsulation bundles data and methods that operate on that data within a class, restricting direct access to some components (data hiding).
  5. Multiple Choice: What is inheritance? A) A class having multiple methods