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 8STE
What is the output produced by the following
#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
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
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)?
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,
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.
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
- Please try to do fast Write the output of the following C++ code? #include <iostream>using namespace std;class CDummy{public:int isitme (CDummy& param);};int CDummy::isitme (CDummy& param){if (¶m == this)return true;elsereturn false;}int main (){CDummy a;CDummy *b = &a;if (b->isitme(a)){cout << "execute";}else{cout<<"not execute";}return 0;}arrow_forwardDetermine the output for the following code. Box in your final output result. public class Beta extends Baap { public int h = 44; public int getH( ) { System.out.println("Beta " + h); return h; } public static void main(String[ ] args) { Baap b = new Beta(); System.out.println(b.h + " " + b.getH( )); Beta bb = (Beta) b; System.out.println(bb.h + " " + bb.getH( )); } } public class Baap { public int h = 4; public int getH( ) { System.out.println("Baap " + h); return h; } }arrow_forwardWhat is the output of the unit testing? #include <iostream>using namespace std;class TempConvert { public: void SetTemp(int tempVal) { temp = tempVal; } int GetTemp() const { return temp; } TempConvert() { temp = 1; } int InFahrenheit() { return (temp * 1.8) - 32; } private: int temp;};int main() { TempConvert testData; cout << "Beginning tests." << endl; if (testData.GetTemp() != 0) { cout << " FAILED initialise/get temp" << endl; } testData.SetTemp(10); if (testData.GetTemp() != 10) { cout << " FAILED set/get temp" << endl; } testData.SetTemp(10); if (testData.InFahrenheit() != 50) { cout << " FAILED InFahrenheit for 10 degrees" << endl; } cout << "Tests complete." << endl; return 0;} a. Beginning tests. FAILED initialise/get temp FAILED InFahrenheit for 10 degreesTests complete. b.…arrow_forward
- 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;}arrow_forwardWhat 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; }arrow_forwardWhat will be displayed in the screen after the following program executes, provided the formal parameter denoted with & will be transferred by: a. value b.value/result c. reference d. name CODE: int a[5]; int i,X=1; void swap (int&a, int&b,int&c) int t; { c++; t = a+X+c; a = b; b = t; } void main() { for (i=0;i<5;i++) a[i] = 6 – i; i = 2; swap(i, a[i],X); printf(“%d%d%d%d%d%d”,i,a[0], a[1], a[2], a[3], a[4]); }arrow_forward
- After the execution of the following lines of code which variables are aliases? int[] a = { 1, 2, 3 };int[] b = { 1, 1, 1 };int[] y = { 1, 2, 3 };a = b;b = new int[1];y = b; .there are no aliases here .a and b are aliases .a, b, and y are aliases .y and b are aliasesarrow_forwardIn the following code stream, identify if there are any hazards. Crisply describe if it is possible to get around the hazards, and what the resulting steps will be. lw r2, 0(r1) add r3, r2, r3 sub r1, r1, r4arrow_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_forward
- Show the output of the following code: #include <iostream> using namespacestd; class A { public: int x; int y; int z; A(): x(1), y(2), z(3) { } }; int main() { A a; A* p1 = &a; a.x = 2; A a1; p1 = &a1; cout << p1->x << " " << (*p1).y << " "<< p1->z; return 0; }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_forwardWhat is the difference between using @Test(expected = TypeOfException) and using try/catch when testing if a method or constructor properly returns an exception? A. They do the same thing. B. @Test(expected = ...) is the proper way to unit test in java, and try/catch should only be used when unit testing in Python. C. @Test(expected = ...) will give a passing test as soon as one exception of the proper type is thrown and then stop the test, but using try/catch will allow you to test many examples in the same test and will only stop after running all examples or reaching a fail() or an assert statement that fails. D. We should never use try/catch when unit testing, otherwise we will catch the exception and then won't know if it is actually thrown.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