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 2STE
What would be the output produced by the code in Self-Test Exercise 1 if we make the following change? Change the line
int waitTime = 46; |
to
int waitTime = 12; |
1. What output is produced by the following code?
int waitTime = 46; try { cout << "Try block entered.\n"; if (waitTime > 30) throw waitTime; cout << "Leaving try block.\n"; } catch(int thrownValue) { cout << "Exception thrown with\n" << "waitTime equal to " << thrownValue << endl; } cout << "After catch block." << endl; |
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write code that outputs variable numBaths as follows. End with a newline.
Ex: If the input is:
3
the output is:
Baths: 3
1 import java.util.Scanner;
2
3 public class OutputTest {
public static void main (String [] args) {
int numBaths;
4
5
// Our tests will run your program with input 3, then run again with input 6.
// Your program should work for any input, though.
7
8
new Scanner(System.in);
scnr.nextInt();
9.
Scanner scnr =
10
numBaths
%3D
11
12
System.out.println(numBaths);
13
CHALLENGE
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
passed
The following PThreads code is written for book reservation in a library. Each student checks if the book is free. If it
was free they will reserve it with their own ID and the book becomes unavailable to the rest.
a. Can you identify the problem with this code? Explain the condition that the code may fail.
b. Rewrite the code (just a few lines of code) to solve the problem.
//PThreads code here
if (book.state==free)
( book.state%-reserved;
book.borrower%=MyID;
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
- Java Program ASAP Modify this program so it passes the test cases in Hypergrade becauses it says 5 out of 7 passed. And do the following; 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.*;import java.util.Scanner;public class FileSorting { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); System.out.println("Please enter the file name or type QUIT to exit:"); while (true) { String input = sc.next(); if (input.equalsIgnoreCase("QUIT")) { break; // Exit the program…arrow_forward6. Which of the below code contains correct overloading code? Why would the other won't work? Code 1 double myMultiply. (int x){ return 10 x; Code 2 int awMultielx (int x){ return 10 x; } double yMultirly. (double x){ double yMultiely (int x){ return 20 x; return 2e * x; 7. What would be the output for the following program and why ( explain in short): Bublis static void nain(String acsal))( String."; String si - "Testing Java Program String s2 - sukstriui13); 8. Write the code in Java for the following class from the UML diagram below: Vehicle -passengers: int -maxSpeed: double -color: String +Vehiclelint,double.String) +setColor(): void +getColor(): String +findCaracityl): double The findCapacityl) method return the capacity of the vehicle by the following formula: Capacity = passengers * 75 L0.20 * maxSpeed)arrow_forwardPrint "userNum1 is negative." if userNum1 is less than 0. End with newline. Assign userNum2 with 4 if userNum2 is greater than 9. Otherwise, print "userNum2 is less than or equal to 9.". End with newline. 1 import java.util.Scanner; 2 public class UserNums { public static void main (String [] args) { int userNum1; int userNum2; 4 6. 7 Scanner input userNum1 = 8. = new Scanner(System.in); input.nextInt(); input.nextInt(); 9. 10 userNum2 11 12 V* Your code goes here */ 13 System.out.println("userNum2 is " } 14 + userNum2); 15 16 17 }arrow_forward
- this practice assignment wants me to : Write an application that asks a user to enter an integer. Display a statement that indicates whether the integer is even or odd. it is saying that i am missing a return statement. here is my code: mport java.util.Scanner; class EvenOdd { public static void main(String[] args) { Scanner input = new Scanner(System.in); int number; System.out.println("Enter the integer >>>"); number = input.nextInt(); } public static boolean isEven(int number) { if (number % 2 == 0) System.out.println("The number is even."); else System.out.println("The number is odd."); } }arrow_forwardHello I need some help with this. I keep getting this one wrong. The language program is Python.arrow_forwardi need help with codingarrow_forward
- Write in Java pleasearrow_forwardWrite code that outputs variable numDogs as follows. End with a newline. Ex: If the input is: 3 the output is: Dogs: 3 import java.util.Scanner; public class OutputTest { public static void main (String [] args) { int numDogs; // Our tests will run your program with input 3, then run again with input 6. // Your program should work for any input, though. Scanner scnr = new Scanner(System.in); numDogs = scnr.nextInt(); System.out.println("Dogs: 3"); }} I cant seem to get the correct answer no matter what I try. What am I missing?arrow_forwardWhen the given integer variable numberOfTools is: less than 14, output "Small tool box". between 14 inclusive and 39 inclusive, output "Mid-sized tool box". greater than 39, output "Need wall storage". End with a newline. Ex: If the input is 13, then the output is: (in java) Given Code: import java.util.Scanner; public class ToolDetails {public static void main(String[] args) {Scanner scnr = new Scanner(System.in);int numberOfTools; numberOfTools = scnr.nextInt();arrow_forward
- Auto-graded programming assignments may use a Unit test to test small parts of a program. Unlike a Compare output test, which evaluates your program's output for specific input values, a Unit test evaluates individual methods to determines if each method: is named correctly and has the correct parameters and return type • calculates and returns the correct value (or prints the correct output) This example lab uses multiple unit tests to test the kilo ToPounds() function. Complete a program that takes a weight in kilograms as input, converts the weight to pounds, and then outputs the weight in pounds. 1 kilogram = 2.204 pounds (lbs). Ex: If the input is: 10 the output is: 22.040000000000003 lbs Note: Your program must define the method public static double kiloToPounds (double kilos) The program below has an error in the kilo ToPounds() method. 1. Try submitting the program for grading (click "Submit mode", then "Submit for grading"). Notice that the first two test cases fail, but the…arrow_forwardConsider the following code: public static void test_a(int n) { System.out.println(n + " "); if (n>0) test_a(n-2); }What is printed by the call test_a(6)?arrow_forwardType two statements using nextInt() to print two random integers between (and including) 0 and 9. End with a newline. Ex: 7 Note: For this activity, using one statement may yield different output (due to the interpreter calling randGen.nextInt() in a different order). Use two statements for this activity. (Notes) 1 import java.util.Scanner; 2 import java.util.Random; 3 4 public class DiceRoll { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); = new Random(); 5 6. 7 Random randGen 8 int seedVal; 9. 10 seedVal = scnr.nextInt(); 11 randGen.setSeed(seedVal);arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
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)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
.2: Function Parameters and Arguments - p5.js Tutorial; Author: The Coding Train;https://www.youtube.com/watch?v=zkc417YapfE;License: Standard Youtube License