CSC102 Final Exam |Questions with
100% Correct Answers
What two subclasses does runtime_error include? - ✔ ✔ overflow_error and underflow_error
The user cannot create their own exception classes to handle specific exceptions - ✔ ✔ False
What is the throw statement used for? - ✔ ✔ To throw your own exceptions
Any class can be an exception class. How it's used makes it an exception class. - ✔ ✔ True
Exception class with member variables typically includes what two items? - ✔ ✔
Constructors and the WHAT function
When an exception occurs in a try block, control immediately passes to one of the
______________. - ✔ ✔ Catch blocks
Once control is passed to the catch blocks, they either - ✔ ✔ 1. Handle the exception
then rethrow it
2. Rethrow another exception
When an exception occurs, the programmer usually has three choices: - ✔ ✔ 1. Terminate
2. Fix code to recover from exception
3. Log error and continue
,In what case of an exception occurrence is it best to terminate the program? - ✔ ✔ Ex. If
an input file does not exist and there is no point in continuing with the program
In what case of an exception occurrence is it best to fix the error and continue? - ✔ ✔ Ex. If a
user inputs a letter instead of a number and you can include code to keep prompting the
user to input a number
In what case of an exception occurrence is it best to log the error and continue? - ✔ ✔ Ex. If
the program is designed to continuously monitor a satellite, it cannot be terminated if an
exception occurs, so the program should simply make note and continue.
When does stack-unwinding occur and what happens? - ✔ ✔ When an exception is thrown, the
function call-stack is unwound so that the exception can be caught in the next try/catch block
What happens after a function call stack is unwound? - ✔ ✔ The function terminates
and memory for the local variables is destroyed.
Stack unwinding continues until... - ✔ ✔ - A try/catch block handles the exception, or
- The program can't handle the exception and terminates
An exception-handling code can be added at a point where an error may occur. - ✔ ✔ True
What is recursion? - ✔ ✔ Solving a problem by reducing it to smaller versions of itself
What is the purpose of recursion? - ✔ ✔ To solve complicated problems in a simplified way,
by breaking them down into smaller versions of themselves
, What is the base case in recursion? - ✔ ✔ the case for which the solution is obtained directly
and stops the recursion
How many base cases must each recursive definition have? - ✔ ✔ At least one
What must a general case do? - ✔ ✔ eventually reduce to a base case
What does a recursive algorithm do? - ✔ ✔ It finds a solution by reducing problems to
smaller versions of itself
What is a recursive function? - ✔ ✔ a function that calls itself
What happens after completing a recursive call? - ✔ ✔ Control goes back to the calling
environment and execution begins from the point immediately following the recursive call
What is direct recursion? - ✔ ✔ a function that calls itself
What is indirect recursion? - ✔ ✔ a recursive function that calls another function
What is a tail recursive function? - ✔ ✔ the last statement is the recursive call
What is infinite recursion? - ✔ ✔ Where every recursive call results in another recursive call
How does computer memory react to infinite recursion? - ✔ ✔ The function runs until it's out
of memory and then terminates abnormally
What steps must you take to design a recursive function? - ✔ ✔ 1. Determine limiting
conditions 2. Understand problem requirements
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller Examsplug. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $12.49. You're not tied to anything after your purchase.