Docsity

WGU D278, Scripting and Programming Foundations, Pseudocode, Control Structures, Variables, Exams of Computer Science

Partial preview of the text

Download WGU D278, Scripting and Programming Foundations, Pseudocode, Control Structures, Variables and more Exams Computer Science in PDF only on Docsity!

8 80 Exam-Style Questions © Multiple Choice Format © Correct Answers 8 3-5 Sentence Rationales © Aligned with WGU D278 OA / PA OB 2026 Ready Ql. What is the loop variable initialization in the following pseudocode? y=0 s= 100.0 while y < 10 s—st(s*5.0) Correct Answer: A Rationale: The pseudo code sets the loop counter y to 0 before entering the while loop. This initialization defines where the loop starts. Without this initial valuc, the loop condition cannot be evaluated correctly. Initializing the loop variable is essential to control the number of iterations. Q2. Order the steps needed to output the minimum of x and y from first (1) to last (4): A. Declare variable min B. Put min to output C. min=x D. Ify < min, sct min=y A.132-3-4 B.1>3>4->2 C.34-134-2 D.1> 453-2 Correct Answer: B Rationale: First the variable min must be declared to store a value. Next, it is initially assigned the value of x. Then the condition checks if y is less than min, and if so assigns y. Finally, the result is output. This sequence ensures proper comparison before output. Q3. Order the steps to calculate speed in miles per hour given start and end location and time traveled: A. Put speedMph to output B. Declare variables distMiles and speedMph C. distMiles = endLocation — startLocation D. speedMph = distMiles / timcHours A.BoC-D-A BA->B>-C—-D C.C->+B>D-A D.B-D-C>A Correct Answer: A Rationale: First declare all necessary variables. Then compute the distance traveled. Next calculate speed using the distance/time formula, and finally output the result. This structured sequence matches sound programming logic flow. Q4. Which algorithmic structure repeats a set of steps until a condition becomes false? A. Sequence B. Selection A. Sequence B. Loop C. Branch (if-else) D. Function Correct Answer: C Rationale: Branching structures like if-else evaluate conditions and determine execution paths based on truth values. Sequence executes steps in order without decision points. Loops repeat, and functions encapsulate behavior. Branching is essential for decision-based logic. Qs. Which data type best represents whole numbers? A. float B. string C. int D. bool Correct Answer: C Rationale: Integers store whole numbers without decimal points. Floating types (float) store decimals. Strings hold text. int is fundamental for counting and discrete values in programming. Qs. Which loop is best when the number of iterations is known ahead of time? A. while B. do-while C. for D.if Correct Answer: C Rationale: for loops are typically used when the iteration count is predetermined. while and do-while loops are better when termination depends on conditions. if is not a loop. Using for enhances clarity for known counts. Q10. What is a function? A. A type of variable B. A reusable block of code C. A data structure D. A program output Correct Answer: B Rationale: A function groups code to perform defined tasks and can be reused. It improves modularity and readability. Functions may receive parameters and return values. They are a core construct in programming. Ql. Which software methodology emphasizes itcrative development and collaboration’? A. Waterfall B. V-Model C. Agile D. Prototype Correct Answer: C Rationale: Agile focuses on iterative, incremental delivery with frequent stakeholder input. Waterfall follows linear phases with limited feedback loops. Agile’s adaptability suits changing requirements. Understanding methodologies is key to modern programming. Ql. What does UML stand for? A. Unified Machine Language B. Universal Markup Logic C. Unified Modeling Language D. Unstructured Method List Correct Answer: C Rationale: UML stands for Unified Modcling Language. It’s used to visually represent software designs, including class and sequence diagrams. UML helps developers communicate structure and behavior. This aids planning and documentation. Qi. Q16. Which data type stores a truc or false valuc? A. int B. string C. bool D. float Correct Answer: C Rationale: A boolean (bool) data type stores logical values true or false. It is commonly used in conditional statements and loop controls. Integers store numbers, strings store text, and floats store decimal values. Boolean logic is fundamental to decision-making in programming. Qi7. What is the main purpose of variables in programming? A. To execute loops B. To store data values C. To design user interfaces D. To test programs Correct Answer: B Rationale: Variables hold data that can be used and modified during program execution. They allow programs to store input, intermediate results, and outputs. Without variables, dynamic computation would not be possible. They arc foundational clements of all programming languages. Qs. Which symbol is commonly used for assignment in programming? A. B.= € Dy Correct Answer: B Rationale: The equals sign (=) assigns a value to a variable. The double equals (==) checks equality. Understanding the difference between assignment and comparison operators prevents logic errors. Assignment is essential for storing values in variables. Qs. Which statement best describes a constant? A. A variable that can change value B. A fixed value that does not change C. A type of loop D. A conditional statement Correct Answer: B Rationale: A constant stores a valuc that cannot be modified after declaration. Constants improve program stability and readability. They are often used for fixed configuration values. Unlike variables, constants remain unchanged throughout exccution. Q20. Which structure is used to make decisions in a program? A. Sequence B. Selection C. Loop D. Function Correct Answer: B Rationale: Selection structures (such as if-else or switch statements) allow a program to choose between different execution paths. Sequence runs statements in order without decisions. Loops repeat instructions. Selection enables decision-based logic. Q21. Which of the following is an example of iteration? A. Exccuting instructions once B. Repeating a block of code C. Declaring a variable D. Assigning a value Correct Answer: B Correct Answer: C Rationale: The NOT operator negates a Boolean value. If a condition is true, NOT makes it false. This is useful in conditional logic. It helps simplify expressions in program control flow. Q25. Which symbol is commonly used to indicate “not equal”? A= B.- Cle D.++ Correct Answer: C Rationale: The != operator checks whether two values are not equal. —— checks equality. — assigns values. ++ increments a value. Relational operators are central to decision-making logic. Q26. Which data type is best for stormg decimal numbers? A. int B. float C. bool D. string Correct Answer: B Rationale: Float (or double) data types store decimal values. Integers store only whole numbers. Strings store text. Floats are essential for calculations involving fractions or measurements. Q27. Which loop structure is best when the number of repetitions is unknown? A. for B. while C. do-while D. if Correct Answer: B Rationale: A while loop repeats based on a condition that is checked before cxccution. It is ideal when the number of iterations is not predetermined. For loops are used when iteration count is known. Do- while always executes once first. Q28. Which term describes breaking a problem into smaller steps? A. Abstraction B. Decomposition C. Compilation D. Encapsulation Correct Answer: B Rationale: Decomposition divides a complex problem into smaller, manageable parts. This simplifies coding and testing. Abstraction hides unnecessary detail. Decomposition is a core problem- solving strategy in programming. Q29. Which of the following is an example of a syntax error? A. Dividing by zero B. Missing a semicolon C. Wrong output result D. Infinite loop Correct Answer: B Rationale: A syntax error occurs when code violates language grammar rules, such as missing punctuation. Dividing by zero is a runtime error. Wrong output is a logic error. Syntax errors prevent code from compiling or running. Q30. Which type of error occurs when a program runs but produces incorrect output? A. Syntax error B. Runtime error C. Logie error D. Compilation crror C. How many variables it uscs D. How long the code is Correct Answer: B Rationale: Algorithm efficiency measures time and resource usage. Efficient algorithms solve problems faster using fewer resources. This is critical in large-scale software. Efficiency is often evaluated using Big-O notation. Q34. Which loop control statement stops a loop immediately? A. break B. continue C, return D. exit Correct Answer: A Rationale: The break statement exits a loop immediately. Continue skips the current iteration but keeps looping. Return exits a function. Break is used to stop loops when a condition is met early. Q35. Which loop control statement skips the current iteration? A. break B. continue C. stop D. skip Correct Answer: B Rationale: Continue skips the remaining code in the current loop iteration and moves to the next iteration. Break stops the entire loop. Continue is useful when certain conditions should bypass processing. Q36. Which term describes converting source code into machine code? A. Compilation B. Interpretation C. Exccution D. Debugging Correct Answer: A Rationale: Compilation translates high-level code into machine-readable instructions. Compilers check syntax before generating executable code. Interpretation executes code line-by-line instead. Compilation improves execution speed. Q37. Which tool finds and fixes errors in programs? A, Debugger B. Compiler C. Flowchart D. Pscudacode Correct Answer: A Rationale: A debugger helps locate and fix errors in code. It allows step-by-step execution and inspection of variables. Compilers only report syntax errors. Debuggers are essential for troubleshooting logic and runtime errors. Q38. Which concept describes grouping data and methods together? A. Encapsulation B. Abstraction C. Decomposition D. Iteration Correct Answer: A Rationale: Encapsulation bundles data and functions into a single unit, such as an object. It protects data from unauthorized access. This is a core principle of object-oricnted programming. It improves code organization and security. Q39. Which programming structure executes statements in order, one after another? Which programming error occurs when dividing by zero? A. Syntax error B. Runtime error C. Logie error D. Compilation error Correct Answer: B Rationale: Dividing by zero causes a runtime error because the code compiles but fails during execution. Syntax errors prevent compilation. Logic errors produce incorrect results but still run. Runtime errors occur while the program is actively running. Q43. Which symbol is used to group expressions in most programming languages’? A B. c.0 D Correct Answer: C Rationale: Parentheses () group expressions and control order of operations. They ensure certain calculations are performed first. Brackets || often define arrays. Braces {} define code blocks. O44. Which term refers to a list of values stored under one name? A. Variable B. Array C. Constant D. Operator Correct Answer: B Rationale: An array stores multiple values under a single variable name. Each value is accessed using an index. Arrays sumplify handling collections of data. They are essential for iterative data processing. Q4s. Which valuc represents “nothing” or “no data” in many languages? A.0 B. null C. false D. empty string Correct Answer: B Rationale: Null represents the absence of a value. It is different from zero or an empty string. Handling null correctly prevents runtime errors. Null checks are common in program validation. Q46. Which structure is used to repeat code based on a condition? A. Sequence B. Loop C. Selection D. Variable Correct Answer: B Rationale: Loops repeat a set of instructions while a condition remains true. They automate repetitive tasks. Sequence executes once in order. Selection chooses between paths but docs not repeat. Q47. Which term describes the process of finding program errors? A. Testing B. Debugging C. Compiling D. Executing Correct Answer: B Rationale: Debugging is the process of identifying and fixing errors in code. Testing reveals errors, while debugging corrects them. Compiling translates code. Execution runs the program. Qas. Which data type would store the value “Hello World”? A. int B. bool C. string D. float Correct Answer: C Rationale: A string data type stores text characters. Integers store numbers. Floats store decimals. Boolean stores true or false values. Strings are essential for handling textual data. Q52. Which symbol begins a single-line comment in many languages? Ali B om D.@@ Correct Answer: A Rationale: // marks a single-line comment in many programming languages. Comments explain code but are ignored during execution. They improve readability and maintenance. Syntax varies slightly across languages, but // is common. Q53. Which term describes repeating a function call inside itself? A. Iteration B. Recursion C. Selection D. Compilation Correct Answer: B Rationale: Recursion occurs when a function calls itself. It is useful for solving problems that break into smaller identical subproblems. Proper base conditions prevent infinite recursion. It is a key programming concept. Q54. Which best describes a parameter in a function? A. A value returned by a function B. A value passed into a function C. A global variable D. A loop counter Correct Answer: B Rationale: Parameters are inputs passed into a function. They allow functions to operate on different data. Return values send results back. Parameters improve function flexibility and reuse. Q55. Which term describes the valuc a function sends back? A. Argument B. Return value C. Variable D. Constant Correct Answer: B Rationale: A return value is the result sent back by a function. Arguments are values passed into a function. Return values allow functions to provide outputs. This supports modular program design. Q56. Which programming principle hides internal details from users? A. Abstraction B. Iteration C. Selection D. Compilation Correct Answer: A Rationale: Abstraction hides unnecessary internal complexity while exposing essential features. It simplifies user interaction with programs. High-level programming languages provide abstraction from hardware. This improves efficiency in software development.