Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 16.1, Problem 9STE
What is the output produced by the
sampleFunction(98.6); in the try block to sampleFunction(212); |
8. What is the output produced by the following program?
#include <iostream> using namespace std; void sampleFunction(double test) throw (int); int main() { try { cout << "Trying.\n"; sampleFunction(98.6); cout << "Trying after call.\n"; } catch(int) { cout << "Catching.\n"; } cout << "End of program.\n"; return 0; } void sampleFunction(double test) throw (int) { cout << "Starting sampleFunction.\n"; if (test < 100) throw 42; } |
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
*68. What is the return value of f (p, p), if the value of p is initialized to 5 before the call?
Note that the first parameter is passed by reference, whereas the second parameter is
passed by value.
int f(int &x, int c) {
c = c
1;
if
X = X + 1;
return f(x, c)
}
(a) 3024
(c==0) return 1;
*
X;
(b) 6561
(c) 55440
(d) 161051
int i=0;
while(i<10)
{
printf(“I am inside the loop”);
}
What is wrong with this block of C code? Mark the errors and fix them.
JAVA Program ASAP
Please modify this program with further modifications which are below so it passes the test cases in Hypergrade. I have provided the failed test cases.
1) For test cases 2 and 3 for the outputted numbers there needs to be commas and there needs to be nothing after that
2)for test case 1 outputted numbers there needs to be nothing after that,
3) for test 4 when file is not found there needs to be nothing after that
4) and for test case 5 and 7 afer a file is not found it needs to display Please re-enter the file name or type QUIT to exit: so you input the text file and displays the numbers.
import java.io.BufferedReader;import java.io.FileReader;import java.io.IOException;import java.util.ArrayList;import java.util.Arrays;import java.util.InputMismatchException;import java.util.Scanner;public class FileSorting { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (true) { System.out.println("Please…
Chapter 16 Solutions
Problem Solving with C++ (10th Edition)
Ch. 16.1 - Prob. 1STECh. 16.1 - What would be the output produced by the code in...Ch. 16.1 - Prob. 3STECh. 16.1 - What happens when a throw statement is executed?...Ch. 16.1 - In the code given in Self-Test Exercise 1, what is...Ch. 16.1 - Prob. 6STECh. 16.1 - Prob. 7STECh. 16.1 - What is the output produced by the following...Ch. 16.1 - What is the output produced by the program in...Ch. 16.2 - Prob. 10STE
Knowledge Booster
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
- Assume the parameters in the following code are being passed by reference. What numbers reside in the variables a and b after the swap takes place? Next, assume the parameters are being passed by value-result. What numbers reside in the variables a and b after the swap takes place this time? void swap(int x, int y, int z){ int tmp = x; x = y; y = z; z = tmp;} int main(){ int a = 3; int b = 4; swap(a, b, b);}arrow_forward31. What is the output of the folowing code? int count; int num 2; for (count - 1; count = 1); System.out.printin (); a. 3 b. 3 1 C. 3 1 -1 d. None of these 34. Which modifier is used to specify that a method cannot be used outside a class? a. public b. abstract c. static d. private public static char methodHeading (int n, double num) 35. Based on the method heading above, what is the return type of the value returmed? a. static int c. d. num b. chararrow_forwarda java assignment about 4 used defined exception using array loop based on real life scenario. (use only java)arrow_forward
- (3) public static void test_b(int n) { if (n>0) test_b(n-2); System.out.println(n + " "); Consider the following method: What is printed by the call test_b(4)? A. 0 2 4 B. 0 2 C. 2 4 D. 4 2 E. 4 20 3 (4) What is the efficacy class of +? n 3 A: ©(1) B: O (log n) C: O (n) D: O (n log n) E: Θ n)arrow_forwardImplement function getPercentage that takes two inputs : grade and totalGrade and outputs the gradepercentage as follows: percentage = (grade/total grade)*100 . (Assume a student can not get a grade above 100%) Define your own exception classes: 1. DivideByZeroException as a derived class of Standard Library class runtime_error, that is used to detect division by zero run time error. 2. NegativeNumberException as a derived class of Standard Library class logic_error, that is used to detect if the user entered a negative number as a grade. 3. InvalidGradeException as a derived class of Standard Library class logic_error, that is used to detect if a user entered an invalid input (grade greater than total grade). Use the above exception classes after implementing them to apply exception handling for your getPercentage function.arrow_forwardDescription: Implement function getPercentage that takes two inputs: grade and total Grade and outputs the grade percentage as follows: percentage = (grade/total grade)*100 . (Assume a student can not get a grade above 100%) Define your own exception classes: 1. DivideByZeroException as a derived class of Standard Library class runtime_error, that is used to detect division by zero run time error. NegativeNumberException as a derived class of Standard Library class logic_error, that is used to detect if the user entered a negative number as a grade. 3. InvalidGradeException as a derived class of Standard Library class logic_ error, that is used to detect if a user entered an invalid input (grade greater than total grade). Use the above exception classes after implementing them to apply exception handling for your getPercentage function. Sample Input/Output:arrow_forward
- Review the code below. Fig 1 The output of the code is: Fig 2arrow_forwardAnswer in c++ Please.arrow_forwardjava c++ here is my question (Evaluate expression) Modify Listing 20.12, EvaluateExpression.java, to add operators ^ for exponent and % for remainder. For example, 3 ^ 2 is 9 and 3 % 2 is 1. The ^ operator has the highest precedence and the % operator has the same precedence as the * and / operators. Your program should prompt the user to enter an expression. Here is a sample run of the program Enter an expression: (5 * 2 ^ 3 + 2 * 3 % 2) * 4(5 * 2 ^ 3 + 2 * 3 % 2) * 4 = 160arrow_forward
- Implement the following function: Code should be written in python.arrow_forwardq13 : Using python programming a screenshot is helpfularrow_forwardPython please: Write a square_root() function that takes a number and returns the square root. The square_root() function throws a ValueError object with the message "Exception: Negative input for square root entered." when the number is negative. Complete the main() program that reads a number from a user, calls the square_root() function, and outputs the returned value from the square_root() function. Use a try-except block to catch any ValueError object thrown by the square_root() function and output the exception message. If the user enters something other than an integer, the program throws a ValueError object with the message "invalid literal for int() with base 10: " and 'user_input'. Output each floating-point value with two digits after the decimal point, which can be achieved as follows: print('{:.2f}'.format(your_value)) Example: If the input is 100 the output is 10.00 Example: If the input is -55 the output is Exception: Negative input for square root entered. Example: If…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
.2: Function Parameters and Arguments - p5.js Tutorial; Author: The Coding Train;https://www.youtube.com/watch?v=zkc417YapfE;License: Standard Youtube License