Problem Solving with C++ plus MyProgrammingLab with Pearson eText-- Access Card Package (9th Edition)
9th Edition
ISBN: 9780133862218
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
I am having a hard time understanding the output of this program with shadow and deep binding.
Can someone explain it more in detail? I posted the answers below
x : integer – – globalprocedure set x(n : integer)x := nprocedure print x()write integer(x)procedure foo(S, P : function; n : integer)x : integer := 5if n in {1, 3}set x(n)elseS(n)174 Chapter 3 Names, Scopes, and Bindingsif n in {1, 2}print x()elsePset x(0); foo(set x, print x, 1); print x()set x(0); foo(set x, print x, 2); print x()set x(0); foo(set x, print x, 3); print x()set x(0); foo(set x, print x, 4); print x()
Here are the answers to the questions.
The program prints = 10 20 30 40 with shallow binding
The program prints = 10 52 00 44 with deep binding,
What is the output of the following C++ code?
#include <iostream>using namespace std;class A{public:A(int n ){cout << n;}};class B: public A{public:B(int n, double d): A(n){cout << d;}};class C: public B{public:C(int n, double d, char ch): B(n, d){cout <<ch;}};int main(){C c(5, 4.3, 'R');return 0;}
What is the output of the following C++ code?
#include <iostream>
using namespace std;
class A
{
public:
A(int n )
{
cout << n;
}
};
class B: public A
{
public:
B(int n, double d)
: A(n)
{
cout << d;
}
};
class C: public B
{
public:
C(int n, double d, char ch)
: B(n, d)
{
cout <<ch;
}
};
int main()
{
C c(5, 4.3, 'R');
return 0;
}
Chapter 16 Solutions
Problem Solving with C++ plus MyProgrammingLab with Pearson eText-- Access Card Package (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
- Java Code: -Creates ProgramNode, loops over Parse calls correctly, throws exception if unknown item found -(ParseFunction) Uses MatchAndRemove(), handles any number of parameters, fills in ASTNode correctly -(ParseAction) Uses MatchAndRemove(), handles any number of parameters, fills in ASTNode correctly Make sure to give the correct code for parser.java with the screenshots of the output. There must be test cases involved, so make sure to have test cases as well.arrow_forward4.) How many times is the println statement executed? for (int i = 0; i < 10; i++) for (int j = 0; j <= 5; j++) System.out.println(i * j) a. 100 b. 60 c. 50 d. 45 5.) Will the following program terminate? int balance = 10; while (true) { if (balance < 9) break; balance = balance - 9; } a.Yes b. No 6.) What exception type does the following program throw? public class Test { public static void main(String[] args) { System.out.println(1 / 0); } } a. ArithmeticException b. ArrayIndexOutOfBoundsException c. StringIndexOutOfBoundsException d. ClassCastException e. No exceptionarrow_forwardPLZ help with the following IN JAVA Suppose that statement2 causes an exception in the following try-catch block: Will statement3 be executed? If the exception is not caught, will statement4 be executed? If the exception is caught in the catch block, will statement4 be executed?arrow_forward
- How would a try-catch block in a java program to be used to solve the following errors within the file. If the user enters the incorrect file name, or the wrong format of a number like 'two' instead of the digit '2'?arrow_forwardPLZ help with the follwoing IN JAVA Suppose that statement2 causes an exception in the following try-catch block: Will statement3 be executed? If the exception is not caught, will statement4 be executed? If the exception is caught in the catch block, will statement4 be executed?arrow_forwardI am struggling to make the output to 2 decimal spaces and the error messages to show on the exception portions, when an improper input is made. public partial class Form1 : Form{public List<Employee> list = new List<Employee>();public double totalGross = 0;public double totalNetPay = 0;public double totalSSWithheld = 0;public double totalMedicareWithHeld = 0;public double totalStateIncomeTaxWithheld = 0;public double totalFederalIncomeTaxWithheld = 0; public Form1(){InitializeComponent(); }private void button1_Click(object sender, EventArgs e){try{for (int i = 0; i < list.Count; i++)richTextBox1.Text += "Employee: " + list[i].Name + "\n" + "Gross Pay: $" + list[i].GrossPay +"\n" + "Net Pay: $" + list[i].NetPay + "\n" + "SS Withheld: $" + list[i].SSWithheld +"\n" + "Medicare Withheld: $" + list[i].MedicareWithheld + "\n" + "State Tax Withheld: $" +list[i].StateIncomeTaxWithheld + "\n" + "Federal Tax Withheld: $" + list[i].FederalIncomeTaxWithheld;richTextBox1.Text +=…arrow_forward
- What is the output printed by writeln statement if the parameter passing mechanism is call by value? Answer :- 8, 2, 3, 3 Need explanation for Answerarrow_forwardComplete 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_forwardWrite a program that reads integers user_num and div_num as input, and output the quotient (user_num divided by div_num). Use a try block to perform all the statements. Use an except block to catch any ZeroDivisionError as a variable and output "Zero Division Exception: " followed by the exception message from the variable. Use another except block to catch any ValueError caused by invalid input as a variable and output "Input Exception: " followed by the exception message from the variable. Note: ZeroDivisionError is raised when a division by zero happens. ValueError is raised when a user enters a value of different data type than what is defined in the program. Do not include code to raise any exception in the program. (in Python)arrow_forward
- Write a program that reads integers user_num and div_num as input, and output the quotient (user_num divided by div_num). Use a try block to perform all the statements. Use an except block to catch any ZeroDivisionError as a variable and output "Zero Division Exception: " followed by the exception message from the variable. Use another except block to catch any ValueError caused by invalid input as a variable and output "Input Exception: " followed by the exception message from the variable. Note: ZeroDivisionError is raised when a division by zero happens. ValueError is raised when a user enters a value of different data type than what is defined in the program. Do not include code to raise any exception in the program. Ex: If the input of the program is: 15 3 the output of the program is: 5 Ex: If the input of the program is: 10 0 the output of the program is: Zero Division Exception: integer division or modulo by zero Ex: If the input of the program is: 15.5 5 the output of…arrow_forwardWhat is the output of the following C++ code? #include <iostream> using namespace std; template <class T> class A { public: A(int a): x(a) {} protected: int x; }; template <class T> class B: public A<char> { public: B(): A<char>::A(100) { cout << x * 2 << endl; } }; int main() { B<char> test; return 0; }arrow_forwardConsider the following segment of JAVA code:void myFunction ( ) { int a = new int[15];boolean b =new boolean[5];System.arraycopy(a, 2, b, 2, 4);}What kind of exceptions occur in the above program? Justify your answer andrewrite the program to handle such exceptions.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 LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
.2: Function Parameters and Arguments - p5.js Tutorial; Author: The Coding Train;https://www.youtube.com/watch?v=zkc417YapfE;License: Standard Youtube License