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 5STE
In the code given in Self-Test Exercise 1, what is the try block?
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
Java Language
How can I create a test in JUnit for this setter?
public void setAge(int age) throws IllegalArgumentException{
if ( age < 0 || age > 80 ) throw new IllegalArgumentException("Invalid age entered");
this.age = age;
}
Consider 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)?
Consider the following code:
public static void test_b(int n)
{
if (n>0)
test_b(n-2);
System.out.println(n + " ");
}
What is printed by the call test_b(6)?
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
- You are to develop a set ofunit testcasesfor the following code block.Note that the code below 5 may contain some faults. The test cases you write should catch these faults and any others that might arise as the code evolves. Write at-least 5 tests, make sure that your tests cover and test evert aspect of the code.arrow_forwardnew code can only be entered betwen grey blocks (ie, 17 - 19).arrow_forwardComplete the code below according to the instructions below and the example test: method withdraw throws an exception if amount is greater than balance. For example: Test Result Account account = new Account("Acct-001","Juan dela Cruz", 5000.0); account.withdraw(5500.0); System.out.println("Balance: "+account.getBalance()); Insufficient: Insufficient funds. Balance: 5000.0 Account account = new Account("Acct-001","Juan dela Cruz", 5000.0); account.withdraw(500.0); System.out.println("Balance: "+account.getBalance()); Balance: 4500.0 Incomplete java code: public class Account{ private String accntNumber; private String accntName; private double balance; public Account(){} public Account(String num, String name, double bal){ accntNumber = num; accntName = name; balance = bal; } public double getBalance(){ return balance;}}//your class herearrow_forward
- Complete both Unit Tests using the given code Unit Test #1 performOperation addition test Build Output NtTest6b116967.java:9: error: performOperation(double,double,String) has private access in Calculator assertTrue(tester201.performOperation(5, 2, "+") == 7.00); ^ Test Contents Calculator tester201 = new Calculator(); @Test public void unitTest() { assertTrue(tester201.performOperation(5, 2, "+") == 7.00); } Unit Test #2 performOperation multiplication test Build Output NtTeste16b3fd1.java:9: error: performOperation(double,double,String) has private access in Calculator assertTrue(tester202.performOperation(5, 2, "*") == 10); Test Contents ^ Calculator tester202 = new Calculator(); @Test public void unitTest() { assertTrue(tester202.performOperation(5, 2, "*") == 10); } The Given Code // Calculator.java - This program performs arithmetic, ( +. -, *. /, % ) on two…arrow_forwardPlease help, write the code for the test cases: public class JunitTest_RideRequestTest { // Test parameterized constructor with invalid input @Test public void test_2_0() { try { RideRequest request = new RideRequest(new String()); fail("You should throw an exception If the input is null or empty."); } catch (IllegalArgumentException e) { // exception excepted do nothing } } @Test public void test_2_2() { RideRequest request = null; try { RideRequest request2 = new RideRequest(request); fail("You should throw an exception If the input is null."); } catch (IllegalArgumentException e) { // exception excepted do nothing } } @Test public void test_2_3() { String s = "John , Downtown , 50.0 , Y , extra info"; try { RideRequest request2 = new RideRequest(s);…arrow_forwardJava Exception method withdraw throws an exception if amount is greater than balance. For example: Test Result Account account = new Account("Acct-001","Juan dela Cruz", 5000.0); account.withdraw(5500.0); System.out.println("Balance: "+account.getBalance()); Insufficient: Insufficient funds. Balance: 5000.0 Account account = new Account("Acct-001","Juan dela Cruz", 5000.0); account.withdraw(500.0); System.out.println("Balance: "+account.getBalance()); Balance: 4500.0arrow_forward
- Use the following code to answer the question public class SpeedTrap {private int speedLimit;/*** Creates a new SpeedTrap with the given* speed limit* * @precondition speedLimit >= 1* @postcondition getSpeedLimit()==speedLimit*/public SpeedTrap(int speedLimit) {if (speedLimit < 1) {throw new IllegalArgumentException("invalid speed limit");}this.speedLimit = speedLimit;}/*** Gets the speed limit* @return the speed limit*/public int getSpeedLimit() {return this.speedLimit;}/*** Checks to see if the given miles-per-hour* is considered speeding.** @precondition mph >= 0* @postcondition none** @returns true if speeding; false otherwise*/public boolean isSpeeding(int mph) {if (mph < 0) {throw new IllegalArgumentException("invalid mph");}return (mph > this.speedLimit);}}Write a JUnit test named testWhenSpeeding that uses a value for mph that is valid and is considered speeding.arrow_forwardUse the following code to answer the question public class SpeedTrap {private int speedLimit;/*** Creates a new SpeedTrap with the given* speed limit* * @precondition speedLimit >= 1* @postcondition getSpeedLimit()==speedLimit*/public SpeedTrap(int speedLimit) {if (speedLimit < 1) {throw new IllegalArgumentException("invalid speed limit");}this.speedLimit = speedLimit;}/*** Gets the speed limit* @return the speed limit*/public int getSpeedLimit() {return this.speedLimit;}/*** Checks to see if the given miles-per-hour* is considered speeding.** @precondition mph >= 0* @postcondition none** @returns true if speeding; false otherwise*/public boolean isSpeeding(int mph) {if (mph < 0) {throw new IllegalArgumentException("invalid mph");}return (mph > this.speedLimit);}}Write a JUnit test for the SpeedTrap constructor named testWhenOneUnderSpeedLimitBoundaryarrow_forwardjava code quation using ExceptionProgramme Leader of ITMB wants to check whether the student number and GSM numberentered by the student for the programming contest is valid or not.Write a Java program to read the Student ID and GSM Number of a student. Use a methodcalled ValidityDetails () for checking the validity of details entered.If the Student ID ends with the characters ST and contains more than 6 letters or if the MobileNumber does not contain exactly 8 digits, throw a user defined exceptionInvalidDetailsException.If the details entered are valid, display the message ‘”correct details are entered!!!” otherwisedisplay “Entered invalid details!!!!”arrow_forward
- 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;arrow_forwardPF Assignment 3 BS ERP 105903 Submission date: 18th April, 2021 via LMS Assignment should include:Hand Wriiten Coding + Screenshot of Output (a) Create a method GetMax() which takes two integer (int) parameters as an arguments and returns maximal of the two numbers. (b) Write a program that reads three numbers from the console and prints the biggest of them. Use the GetMax() method you just created. Write a test program that validates that the methods works correctly. Write a method that returns the digits of a given decimal number in a reversed order. For example 256, must be printed as 652. Write a program in C to check a given number is positive or negative using method. Write a program that calculates and prints the n! for any n in the range [1…10] number should be taken as input from user through main and should pass as an argument to the method. Write a program in C# Sharp to create a function to input a string and return count of number of spaces are in the…arrow_forwardAssume that the SampleQueue class, with the given code below, is used in the TestSampleQueue that is also shown below. Show the output of the TestSampleQueue. Do the exercise without using a computer (i.e. Make amanual trace of the program):// TestSampleQueue classimport java.io.*;import java.lang.*;public class TestSampleQueue {private SampleQueue<Integer> queue = new SampleQueue<Integer>();public void run() throws Exception {queue.enqueue(new Integer(10));System.out.println(queue.toString());queue.enqueue(new Integer(5));System.out.println(queue.toString());queue.dequeue();System.out.println(queue.toString());queue.enqueue(new Integer(15));System.out.println(queue.toString());queue.enqueue(new Integer(7));System.out.println(queue.toString());queue.dequeue();System.out.println(queue.toString());} // end of run methodpublic static void main(String[] args) {TestSampleQueue program;try {program = new TestSampleQueue();program.run();} catch ( Exception e )…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