Problem Solving with C++ Plus MyLab Programming with Pearson eText -- Access Card Package (10th Edition)
10th Edition
ISBN: 9780134710747
Author: Walter Savitch
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
2) Answer the question with the correct options given below
A)What is the output of the following code?
int *p1, *p2;
p1 = new int;
p2 = new int;
*p1 = 11;
*p2 = 0;
p2 = p1;
cout << *p1 <<" " << *p2 << endl;
0 11
11 0
0 0
11 11
B) What is wrong with the following code fragment?
int *p1, *p2; p1 = new int; p2 = new int; *p1=11; *p2=0; p2=p1; cout << *p1 <<" " << *p2 << endl; delete p1; delete p2;
p1 and p2 both have the same value, so the delete p2 will cause an error
nothing
B and C
You have a memory leak
C) Which of the following correctly declares a dynamic array of strings?
p1 = new string[];
p1 = new string[13];
p1 = new string(13);
p1 = new stringArray(13);
I have a question about the following code, why do they have different output, please explain to me.
class Test
{
private:
int x;
int y;
public:
Test(int x = 0, int y = 0) { this->x = x; this->y = y; }
Test &setX(int a) { x = a; return *this; }
Test &setY(int b) { y = b; return *this; }
void print() { cout << "x = " << x << " y = " << y << endl; }
};
int main()
{
Test obj1(5, 5);
// Chained function calls. All calls modify the same object
// as the same object is returned by reference
obj1.setX(10).setY(20);
obj1.print();
return 0;
}
#include<iostream>
using namespace std;
class Test
{
private:
int x;
int y;
public:
Test (int x = 0, int y = 0) { this->x = x; this->y = y; }
Test setX(int a) { x = a; return *this; }
Test setY(int b) { y = b; return *this; }
void print() { cout << "x = " << x << " y = " << y << endl; }
};
int main()
{
Test obj1;…
Consider the following declaration:
int [ ] [ ] beta = new int [3] [3];
What is stored in beta after the following executes?
Keep track of the variables’ values in a table. BOX IN YOUR OUTPUT RESULT.
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
beta[ i ] [ j ] = 2 * ( i + j) % 4;
Chapter 16 Solutions
Problem Solving with C++ Plus MyLab Programming with Pearson eText -- Access Card Package (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
- trace the following code and give the output. for (int k=5; k<=20; k+=5) cout << "? ";arrow_forward) What will be the output of following code? Also give step by step explanation for determining the output.#include<stdio.h> int pqr(int,int);int main(){int x=pqr(20,2);printf("%d",x);return 0;}int pqr(int x,int y){if(x==0){return 0;}else{return x+pqr(x/y,y);}}arrow_forwardConsider 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)?arrow_forward
- What is the value of f(2) and f(4) after execution the following code in static mode:int f (int x) {static int a = 0;a +=2;printf(" %d/n",a );} f(2)?? f(4)??arrow_forwardWhat will be the output of following code? Also give step by step explanation for determining the output. #include<stdio.h> int pqr(int,int);int main(){int x=pqr(20,2);printf("%d",x);return 0;}int pqr(int x,int y){if(x==0){return 0;}else{return x+pqr(x/y,y);}} explain sirarrow_forwardWhat is output from the following code: TRACE FIRST: double *w; //Line 1 w =new double[5]; //Line 2 for (i = 0; i < 5; i++) //Line 3 { w[i] = pow(i, 2.0); //Line 4 cout << w[i] << " "; //Line 6 } cout << endl; //Linearrow_forward
- What are the values of X[i] and X[i+1] after code corresponding to the following code is run? int X[5]; int i=0; int A = 100, B = 200, C = 300; X[i] = A; X[i+1] = B; C = X[i]; X[i] = X[i+1]; X[i+1]= C;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_forward4. A) What will be the value of x after the following code is executed? int x, y = 4, z = 6; x = (y++) * (++z); B) Suppose a = 1. What is the value of a after the following code executes? Show the procedure to reach your answer if(a > 0) { switch(a) { case 1: a = a + 3; case 3: a++; case 6: a = a * 2; break; case 8: a--; break; default a++; } else a = a + 2; C) What would be the value of x after the following statements were executed? int x = 10; switch (x) { case 10: x += 15; case 12: x -= 5; break; default: x *= 3; }arrow_forward
- What would happen if you tried to execute the program after adding the following code before “return 0;” How could you fix it? Please describe it by words. Int*v=&t; Printf(“%d\n”,*v); Int*varrow_forwardQ4)What will be the output for this code(Explain your logic with help of dry running for the same): #include <stdio.h> void foo( int[] );int main(){int ary[4] = {1, 2, 3, 4};foo(ary);printf("%d ", ary[0]);}void foo(int p[4]){int i = 10;p = &i;printf("%d ", p[0]);}arrow_forwardWhat will be the output of the following program? #include<stdio.h> void main () { int a[10] = {100, 206, 300, 409, 509, 601}; //Line 1 int *p[] = {a, a+1, a+2, a+3, a+4, a+5}; //Line 2 int **pp = p; //Line 3 pp++; // Line 4 printf("%d %d %d\n",pp-p,*pp - a,**pp); // Line 5 *pp++; // Line 6 printf("%d %d %d\n",pp-p,*pp - a,**pp); // Line 7 ++*pp; // Line 8 printf("%d %d %d\n",pp-p,*pp - a,**pp); // Line 9 ++**pp; // Line 10 printf("%d %d %d\n",pp-p,*pp - a,**pp); // Line 11 } I don't need screenshot I need explanation of the output.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 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