Problem Solving with C++ (9th Edition)
9th Edition
ISBN: 9780133591743
Author: Walter Savitch
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
2- Trace the following code and write the output:
class Test1 {
Test1(int x)
{
System.out.println("Test Calls " + x);
class
Test2 {
Testi t1 = new Test1(10);
Test2(int i) { t1 = new Test1(i); }
public static void main(String[]
args)
{
Test2 t2 = new Test2(5);
..• 6. Modify the following program so that it terminates, printing "Invalid input" as soon as an invalid input is detected. If both inputs are valid, print their product.
Test.java
ebook-bjlo-2-ch03-sec08-cc-1ava.util.Scanner;
2
3 public class Test
4 {
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Enter an integer: ");
in.nextInt();
9.
10
int m =
11
System.out.print("Enter another integer: ");
12
int n =
in.nextInt();
13
System.out.println("Product: " + m * n);
14
15 }
CodeCheck
Reset
Chapter 16 Solutions
Problem Solving with C++ (9th 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
- QUESTION 4 Analyze the following code: public class Test { public static void main (String [] args) { int i = 0; while (i ++ < 10); System.out.println(i + 4); The program compiles despite the semicolon () on the for loop line, and displays 15. The program has a compile error because of the semicolon (;) on the while loop line. The program compiles despite the semicolon (:) on the while loop line, and displays 4.arrow_forwardAssume 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_forwardexplain with 0 plagiarismarrow_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_forwardConsider the following code: def test(*x): for k in x: print(type(k)) what will be the output if test function is culled with 876? Oa. O b. O c. O d. 876arrow_forward// JumpinJive.java - This program looks up and prints the names and prices of coffee orders. // Input: Interactive. // Output: Name and price of coffee orders or error message if add-in is not found. import java.util.Scanner; public class JumpinJive { public static void main(String args[]) throws Exception { // Declare variables. String addIn; // Add-in ordered by customer. final int NUM_ITEMS = 5; // Named constant // Initialized array of add-ins. String addIns[] = {"Cream", "Cinnamon", "Chocolate", "Amaretto", "Whiskey"}; // Initialized array of add-in prices. double addInPrices[] = {.89, .25, .59, 1.50, 1.75}; boolean foundIt; int x; // Loop control variable. double orderTotal = 2.00; // All orders start with a 2.00 charge // Get user input. Scanner input = new Scanner(System.in); System.out.print("Enter coffee add-in or XXX to quit: "); addIn = input.nextLine();…arrow_forward
- Description: 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_forwardWrite the functions with the following headers:# Return the reversal of an integer, e.g. reverse(456) returns# 654def reverse(number):# Return true if number is a palindromedef isPalindrome(number): Use the reverse function to implement isPalindrome. A number is a palindrome if its reversal is the same as itself. Write a test program that prompts the user to enter an integer and reports whether the integer is a palindrome.arrow_forwardAnswer in c++ Please.arrow_forward
- java 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_forwardQUESTION 8 What happens when the following code is executed? void function2(0 { throw runtime_ error("An error occurred in function2!"); void function1(){ try { function2(); throw runtime_error("An error occurred in function1!"); catch(const exception& e) { cout << e.what() << "In\n"; int main() { try { function1(); catch(const exception& e) { cout << e.what() << "In\n"; O a. An exception is thrown by function20) and caught by function10. O b. An exception is thrown by function1() but isn't caught so the program crashes. OC. An exception is thrown by function2() and caught by the main() function O d. An exception is thrown by function1() and caught by the main) function.arrow_forwardImplement the following function: Code should be written in python.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