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
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);
You are working on problem set: HW2 - loops (Pause)
Pause)
? variableScope ♡
Language/Type:
Java expressions for %
A variable's scope is the part of a program in which it exists. In Java, the scope of a
variable starts when it is declared and ends when the closing curly brace for the block
that contains it is reached. A variable is said to be in scope where it is accessible.
Consider the following program:
public class Example {
public static void main(String[] args) {
performTest ();
}
}
public static void performTest() {
int count = 12:
for (int i = 1; i <= 12; i++) {
runSample();
K
}
}
}
System.out.print(count);
public static void runSample() {
System.out.print("sample");
7
с
M
31
In which of these blocks is the variable count in scope for the entirety of the block?
runSample method
a.
b.
main method
c.
for loop
d. O performTest method
(order shuffled)
In which of these blocks is the variable i in scope for the entirety of the block?
a. O main method
b. O runSample method
c. O…
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.
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
- 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.arrow_forwardJAVA 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…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_forward
- explain with 0 plagiarismarrow_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_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
- int mystery (int u, int v) { int a; a = u - V; u = a; V = u; return u + v; choose the output of the follos cout << mystery (9,7); Select one: a. 7 b. 4 C. 9arrow_forward3: The code on the right is supposed to be the ARM code for procA; however, there are problems with the ARM code. C code: int procA(int x, int y) { int perimeter = (x + y) * 2; I return perimeter; } ARM code: I procA: add rø, r1, r2 mov r1, rø lsl #1 bx lr push {lr} Give the corrected version of the ARM code for procA:arrow_forwardThe file provided contains syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. // Some circle statistics public class DebugFour2 { public static void main(String args[]) { double radius = 12.6; System.out.println("Circle statistics"); double area = java.Math.PI * radius * radius; System.out.println("area is " + area); double diameter = 2 - radius; System.out.println("diameter is + diameter); } }arrow_forward
- 2. The following program read a three-digits number from user input, reverse it and display the reversed number (No need to deal with exceptions or special cases). Read the codes, design the reverse method to complete the program. (5 marks) 浙江工业大学 import java.util.Scanner; public class DigitReverse { protected int num; public DigitReverse(int num) { if(num999) { Systen.exít(e); } else ( this.num = num; I/Write the reverse() method here public static void main(String() args) { Scanner input = new Scanner (Systen.in); System.out.print("Enter a number to reverse (101- 998): "); try { int num = input.nextInt(); DigitReverse dr = new DigitReverse(num); dr.reverse(); Systen.out.printin("The reversed number is" + dr.num); } catch(Exception ex) { System.out.printin(ex. tostring());arrow_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_forwardCHALLENGE ACTIVITY Type two statements that use rand() to print 2 random integers between (and including) 100 and 149. End with a newline. Ex: 101 133 3.8.3: Fixed range of random numbers. Note: For this activity, using one statement may yield different output (due to the compiler calling rand() in a different order). Use two statements for this activity. Also, srand() has already been called; do not call srand() again. See How to Use zyBooks for info on how our automated program grader works. 449096.3145616.qx3zqy7 1 #include 2 #include 3 #include 4 5 int main(void) { 6 int seedVal; 7 8 9 10 11 12 13 14} scanf("%d", &seedVal); srand(seedVal); /* Your solution goes here */ return 0; Run A No solution code provided X Testing with seedVal = 4 // Enables use of rand() // Enables use of time() Your output Your program produced no output Expected output X Testing with seedVal = 55 101 133 Expected output Your output Your program produced no output 148 125 1 test passed All tests passedarrow_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