Quiz #2 - Midterm CS 200 - Programming Languages - Technological Institute of the Philippines
Document Details
Uploaded by ProfuseDada
Technological Institute of the Philippines
2024
Tags
Summary
This is a programming languages quiz for students at the Technological Institute of the Philippines. The quiz includes multiple choice questions on various programming concepts.
Full Transcript
TECHNOLOGICAL INSTITUTE OF THE PHILIPPINES QUEZON CITY COMPUTER SCIENCE DEPARTMENT QUIZ #2 - MIDTERM 1st Semester SY2024-2025...
TECHNOLOGICAL INSTITUTE OF THE PHILIPPINES QUEZON CITY COMPUTER SCIENCE DEPARTMENT QUIZ #2 - MIDTERM 1st Semester SY2024-2025 CS 200 – PRINCIPLES OF PROGRAMMING LANGUAGES MULTIPLE CHOICE: Read all the questions carefully. Write the letter of your answer in UPPERCASE format on your answer sheet. (30 points) 1. Which is an example of user-friendly error handling in web applications? A) Displaying error codes directly to users B) Providing helpful, easy-to-understand messages when something goes wrong C) Ignoring errors completely D) None of the above 2. What is an expression in programming? A) A statement that produces a result. B) A combination of values, variables, operators, and functions that produce a result. C) A combination of variables and operators without producing a result. D) None of the above 3. In which of the following expressions is type coercion most likely to occur? A) 3 + 4 B) 3 + "4" C) 3 * 4 D) None of the above 4. What is the role of an assignment statement in programming? A) To create a new variable B) To evaluate an expression and store the result in a variable C) To delete a variable D) None of the above 5. Strict evaluation means: A) Only the necessary parts of an expression are evaluated. B) All parts of the expression are evaluated before execution continues. C) Expressions are never evaluated. D) None of the above 6. Which pattern is useful for operations that may fail temporarily, such as network requests? A) Retry logic B) Error suppression C) Graceful degradation D) All of the above 7. In programming, what is the primary difference between syntax and semantics? A) Syntax defines the meaning; semantics defines the structure. B) Syntax defines the structure; semantics defines the meaning. C) Both syntax and semantics define meaning. D) All of the above 8. In Python, which assignment type allows unpacking values from a sequence into individual variables? A) Chained Assignment B) Simple Assignment C) Unpacking Assignment D) All of the above 9. What is the purpose of providing descriptive error messages? A) To hide error details from the user B) To help developers identify the cause and location of an error C) To reduce program size D) All of the above 10. Which type of error occurs due to incorrect program logic but does not crash the program? A) Syntax error B) Runtime error C) Logical error D) All of the above 11. Lazy evaluation is commonly found in which language type? A) Procedural B) Functional C) Object-oriented D) None of the above 12. In C++, operator overloading allows: A) Using different data types with the same operator. B) Defining new operators. C) Custom definitions for standard operators on user-defined types. D) None of the above 13. In expression typing, what type of language checks types at runtime? A) Statically-typed B) Dynamically-typed C) Weakly-typed D) None of the above 14. Which language does not have increment (++) and decrement (--) operators? A) C++ B) Python C) Java D) None of the above 15. Aliasing occurs when: A) Two variables refer to the same memory location B) A variable is uninitialized C) Two variables have different values D) None of the above 16. What type of assignment allows a value to be assigned to multiple variables at once? A) Compound Assignment B) Chained Assignment C) Simple Assignment D) None of the above 17. Short-circuiting occurs in which types of operations? A) Arithmetic B) Logical C) Bitwise D) None of the above 18. The ternary operator in JavaScript has the form: A) condition ? expr1 : expr2 B) condition && expr1 || expr2 C) expr1 ? condition : expr2 D) None of the above 19. Copy semantics in assignment means: A) The variable points to the memory address of the data. B) The value on the right is copied into the variable on the left. C) The variable on the left is deleted. D) None of the above 20. Which type of error is detected before the program is executed? A) Runtime error B) Syntax error C) Logical error D) None of the above 21. Which language has a safe navigation operator?. A) Python B) C++ C) Kotlin D) None of the above 22. Which of the following scenarios benefits from short-circuiting? A) Executing a function that performs heavy computation B) Checking if a value is null before accessing its properties C) Storing values in a database D) None of the above 23. Which is a best practice for using short-circuit evaluation? A) Using nested short-circuit operators in all expressions B) Keeping conditions clear and avoiding excessive nesting C) Using & for short-circuiting in C++ D) None of the above 24. The try-catch block is used to: A) Perform arithmetic operations. B) Handle runtime errors. C) Define functions. D) None of the above 25. Which example demonstrates the use of short-circuiting to avoid a potential runtime error? A) if (a / b > 2 && a != 0) {...} B) if (a != 0 && b / a > 2) {...} C) if (a == 0 || a / b > 2) {...} D) None of the above 26. Which rule helps determine the order in which operations are performed? A) Associativity B) Precedence C) Typing D) None of the above 27. What is the difference between initialization and assignment? A) Initialization provides an initial value, while assignment updates the variable's value. B) Initialization updates the variable, while assignment only provides an initial value. C) Both are the same. D) None of the above 28. Expression trees are used to: A) Parse expressions. B) Optimize memory usage. C) Visualize the order of evaluation. D) None of the above 29. To handle overflow during type conversion, a programmer can use: A) Error handling mechanisms, like try-catch blocks B) Implicit conversion C) Uninitialized variables D) None of the above 30. A best practice to avoid bugs with type conversions is to: A) Use implicit conversions only B) Use explicit conversions whenever possible C) Avoid conversions altogether D) None of the above A1 TECHNOLOGICAL INSTITUTE OF THE PHILIPPINES QUEZON CITY COLLEGE OF COMPUTER STUDIES MIDTERM EXAMINATION 1st Semester SY2024-2025 CS 200 – PRINCIPLES OF PROGRAMMING LANGUAGES SET A TEST I. MULTIPLE CHOICE: Read all the questions carefully. Write the letter of your answer in UPPERCASE format. (30 points) 1. Which example demonstrates the use of short-circuiting to avoid a potential runtime error? A) if (a / b > 2 && a != 0) {...} C) if (a == 0 || a / b > 2) {...} B) if (a != 0 && b / a > 2) {...} D) None of the above 2. Which rule helps determine the order in which operations are performed? A) Associativity C) Typing B) Precedence D) None of the above 3. What is the difference between initialization and assignment? A) Initialization provides an initial value, while assignment updates the variable's value. B) Initialization updates the variable, while assignment only provides an initial value. C) Both are the same. D) None of the above 4. Expression trees are used to: A) Parse expressions. C) Visualize the order of evaluation. B) Optimize memory usage. D) None of the above 5. To handle overflow during type conversion, a programmer can use: A) Error handling mechanisms, like try-catch blocks C) Uninitialized variables B) Implicit conversion D) None of the above 6. A best practice to avoid bugs with type conversions is to: A) Use implicit conversions only C) Avoid conversions altogether B) Use explicit conversions whenever possible D) None of the above 7. Which is an example of user-friendly error handling in web applications? A) Displaying error codes directly to users B) Providing helpful, easy-to-understand messages when something goes wrong C) Ignoring errors completely D) None of the above 8. What is an expression in programming? A) A statement that produces a result. B) A combination of values, variables, operators, and functions that produce a result. C) A combination of variables and operators without producing a result. D) None of the above 9. In which of the following expressions is type coercion most likely to occur? A) 3 + 4 C) 3 * 4 B) 3 + "4" D) None of the above 10. What is the role of an assignment statement in programming? A) To create a new variable C) To delete a variable B) To evaluate an expression and store the result in a variable D) None of the above 11. Strict evaluation means: A) Only the necessary parts of an expression are evaluated. B) All parts of the expression are evaluated before execution continues. C) Expressions are never evaluated. D) None of the above A2 12. Which pattern is useful for operations that may fail temporarily, such as network requests? A) Retry logic C) Graceful degradation B) Error suppression D) None of the above 13. In programming, what is the primary difference between syntax and semantics? A) Syntax defines the meaning; semantics defines the structure. B) Syntax defines the structure; semantics defines the meaning. C) Both syntax and semantics define meaning. D) All of the above 14. In Python, which assignment type allows unpacking values from a sequence into individual variables? A) Chained Assignment C) Unpacking Assignment B) Simple Assignment D) None of the above 15. Which type of error occurs due to incorrect program logic but does not crash the program? A) Syntax error C) Logical error B) Runtime error D) None of the above 16. Aliasing occurs when: A) Two variables refer to the same memory location C) Two variables have different values B) A variable is uninitialized D) None of the above 17. What type of assignment allows a value to be assigned to multiple variables at once? A) Compound Assignment C) Simple Assignment B) Chained Assignment D) None of the above 18. Short-circuiting occurs in which types of operations? A) Arithmetic C) Bitwise B) Logical D) None of the above 19. The ternary operator in JavaScript has the form: A) condition ? expr1 : expr2 C) expr1 ? condition : expr2 B) condition && expr1 || expr2 D) None of the above 20. Copy semantics in assignment means: A) The variable points to the memory address of the data. C) The variable on the left is deleted. B) The value on the right is copied into the variable on the left. D) None of the above 21. To handle overflow during type conversion, a programmer can use: A) Error handling mechanisms, like try-catch blocks C) Uninitialized variables B) Implicit conversion D) None of the above C) Uninitialized variables 22. A best practice to avoid bugs with type conversions is to: A) Use implicit conversions only C) Avoid conversions altogether B) Use explicit conversions whenever possible D) None of the above 23. Lazy evaluation is commonly found in which language type? A) Procedural C) Object-oriented B) Functional D) None of the above 24. In C++, operator overloading allows: A) Using different data types with the same operator. C) Custom definitions for standard operators on user-defined types. B) Defining new operators. D) None of the above 25. In expression typing, what type of language checks types at runtime? A) Statically-typed C) Weakly-typed B) Dynamically-typed D) None of the above 26. Lazy evaluation is useful because it: A) Reduces memory usage. C) Avoids computation until needed. B) Ensures all expressions are evaluated. D) None of the above A3 27. Which language does not support operator overloading? A) Python C) C++ B) Java D) None of the above 28. Which statement best describes parallel assignment? A) It allows assigning the same value to multiple variables. B) It allows assigning different values to multiple variables in one line. C) It combines an operation with assignment D) D) None of the above 29. In C, which syntax is used to cast a variable to an integer? A) int(x) C) int x B) (int) x D) None of the above 30. Type demotion may lead to: A) Increased precision C) More memory allocation B) Loss of precision D) None of the above TEST II. TRUE OR FALSE: Write TRUE if the statement is correct, otherwise write FALSE. (10 points) TRUE 1. Order of operations, also known as precedence rules, is used to resolve expression ambiguity. TRUE 2. Operator overloading allows operators to have unique functionality with user-defined types in some languages. FALSE 3. In C++, both prefix and postfix forms of the increment operator ++ yield the same result. TRUE 4. Short-circuit evaluation can improve performance by stopping further evaluation once the result is determined. FALSE 5. The syntax for assignment is identical in all programming languages. FALSE 6. Reference semantics are commonly used with primitive types in programming. TRUE 7. Custom conversion functions allow programmers to define how objects are converted between types. FALSE 8. Rounding errors are typically not a concern in floating-point arithmetic conversions. FALSE 9. In C++, operator overloading cannot be used to define custom type conversions. TRUE10. Type conversion is the process of changing a variable from one type to another, often necessary for mixed-type operations. TECHNOLOGICAL INSTITUTE OF THE PHILIPPINES QUEZON CITY COMPUTER SCIENCE DEPARTMENT QUIZ #1 - PRELIM 1st Semester SY2024-2025 CS 200 – PRINCIPLES OF PROGRAMMING LANGUAGES TEST I. MULTIPLE CHOICE: Read all the questions carefully. Write the letter of your answer in UPPERCASE format on your answer sheet. (25 points) 1. In the expression x = 7 + 3 * 6, which operation is performed first? A. Addition C. Subtraction B. Multiplication D. Division 2. Who is credited with designing the first widely known compiler? a) Alick E. Glennie c) John Backus b) Grace Hopper d) Dennis Ritchie 3. What kind of programming uses logical deduction rather than sequential steps? A. Object-Oriented Programming C. Imperative Programming B. Functional Programming D. Logic Programming 4. Which of the following is NOT considered a feature of a programming language? a) Orthogonality c) Type equivalence b) Control structures d) Debugging mode 5. Which paradigm organizes computation around variables and stepwise control of data manipulation? a) Functional c) Imperative b) Logic d) Declarative 6. What is the purpose of a variable in programming?** A. It stores data temporarily in memory C. It performs mathematical calculations B. It controls the flow of the program D. It only stores integers 7. Which of the following languages introduced the concept of object-oriented programming? a) Simula c) Fortran b) Pascal d) Prolog 8. Functional programming is based on which mathematical concept? a) Boolean algebra c) Logic predicates b) Lambda calculus d) Stored program concept 9. What type of error occurs if you try to divide an integer by zero in most programming languages?** A. Syntax error C. Runtime error B. Compilation error D. Logical error 10. Which of the following is a primary aspect of program performance influenced by language features? a) Expressiveness c) Aliasing b) Reusability d) Assembly language compatibility 11. What is a common disadvantage of using a compiler over an interpreter?** A. The compiled code is not portable B. You must recompile the code after making changes C. It translates code line by line, which is slower D. Errors are displayed one at a time during execution 12. Which feature of programming languages supports reuse of code and improves readability and writeability? a) Control structures c) Abstraction b) Syntax design d) Type checking 13, In which language paradigm are "classes" and "objects" fundamental concepts? A. Imperative C. Object-Oriented B. Functional D. Declarative 14. What does an assembler do? A. Translates machine code into assembly C. Interprets high-level languages B. Translates assembly language into machine code D. Debugs programs 15. Which of the following is a typical functional programming language? a) Fortran c) Lisp b) Java d) Prolog 16. What does P vs NP in programming refer to? A. A classification of problems based on difficulty in algorithmic solution B. A programming language comparison C. A discussion of hardware limitations D. The development of new software 17. What is a key difference between a compiler and an interpreter? A. A compiler runs code line by line B. An interpreter translates and runs code line by line, while a compiler translates the whole code at once C. A compiler executes the code immediately D. An interpreter saves the object code for later use 18. When is a while loop typically used?** A. When you know exactly how many times the code block will execute B. When there are no conditions to check C. When you do not know the number of iterations or details of the condition D. When iterating through a list 19. The paradigm that expresses computation in terms of logic predicates is known as: a) Declarative c) Object-oriented b) Imperative d) Functional 20. Which language was a major influence on the development of structured programming? a) C++ c) Lisp b) ALGOL d) Smalltalk 21. Which programming language feature is primarily responsible for improving reliability by preventing programs from crashing due to unexpected circumstances? a) Expressiveness c) Syntax design b) Exception handling d) Data structures 22. Who invented the binary system and calculus? A. Alan Turing C. Alonzo Church B. Gottfried Wilhelm Leibniz D. Abu Ja’far Muhammad ibn Musa 23. What is a key drawback of highly expressive programming languages? a) Reduced readability c) Less reliability b) Weaker data types d) Limited exception handling 24. Which is NOT a characteristic of machine language? A. Translation-free C. Error-prone B. Machine dependent D. High-level abstraction 25. Prolog was originally designed for which application? a) Object-oriented programming c) Mathematical calculations b) Artificial intelligence d) System implementation TEST II. ENUMERATION: (25 points) 1 – 10 Factors in Developing Programming Languages 11 – 15 Evolution of Programming Languages 16 – 20 Prominent Figures in Programming History