In this challenge, the task is to debug the existing code to successfully execute all provided test files. You are required to extend the existing code so that it handles std::invalid_argument exception properly. More specifically, you have to extend the implementation of process_input function. It takes integer  as an argument and has to work as follows: It calls function largest_proper_divisor(n). If this call returns a value without raising an exception, it should print in a single line result=d where  is the returned value. Otherwise, if the call raises a std::invalid_argument exception, it has to print in a single line the string representation of the raised exception, i.e. its message. Finally, no matter if the exception is raised or not, it should print in a single line returning control flow to caller after any other previously printed output. To keep the code quality high, you are advised to have exactly one line printing returning control flow to caller in the body of process_input function. Your function will be tested against several cases by the locked template code. Input Format The input is read by the provided locked code template. In the only line of the input, there is a single integer , which is going to be the argument passed to function process_input. Constraints   Output Format The output should be produced by function process_input as described in the statement. Sample Input 0 0 Sample Output 0 largest proper divisor is not defined for n=0returning control flow to caller Explanation 0 In the first sample, , so the call largest_proper_divisor(0) raises an exception. In this case, the function process_input prints two lines. In the first of them it prints the string representation of the raised exception, and in the second line it prints returning control flow to caller. Sample Input 1 9 Sample Output 1 result=3returning control flow to caller Explanation 1 In the first sample, , so the call largest_proper_divisor(9) doesn't raise an exception and returns value . In this case, the function process_input prints two lines. In the first of them it prints result=3 because the returned value by largest_proper_divisor(9) is , and in the second line it prints returning control flow to caller.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

In this challenge, the task is to debug the existing code to successfully execute all provided test files.

You are required to extend the existing code so that it handles std::invalid_argument exception properly. More specifically, you have to extend the implementation of process_input function. It takes integer  as an argument and has to work as follows:

  1. It calls function largest_proper_divisor(n).
  2. If this call returns a value without raising an exception, it should print in a single line result=d where  is the returned value.
  3. Otherwise, if the call raises a std::invalid_argument exception, it has to print in a single line the string representation of the raised exception, i.e. its message.
  4. Finally, no matter if the exception is raised or not, it should print in a single line returning control flow to caller after any other previously printed output.

To keep the code quality high, you are advised to have exactly one line printing returning control flow to caller in the body of process_input function.

Your function will be tested against several cases by the locked template code.

Input Format

The input is read by the provided locked code template. In the only line of the input, there is a single integer , which is going to be the argument passed to function process_input.

Constraints

  •  

Output Format

The output should be produced by function process_input as described in the statement.

Sample Input 0

0

Sample Output 0

largest proper divisor is not defined for n=0returning control flow to caller

Explanation 0

In the first sample, , so the call largest_proper_divisor(0) raises an exception. In this case, the function process_input prints two lines. In the first of them it prints the string representation of the raised exception, and in the second line it prints returning control flow to caller.

Sample Input 1

9

Sample Output 1

result=3returning control flow to caller

Explanation 1

In the first sample, , so the call largest_proper_divisor(9) doesn't raise an exception and returns value . In this case, the function process_input prints two lines. In the first of them it prints result=3 because the returned value by largest_proper_divisor(9) is , and in the second line it prints returning control flow to caller.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Exception Handling Keywords
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education