Question

Show a conditional expression that returns either a double or an int. Provide an int catch...

Show a conditional expression that returns either a double or an int. Provide an int catch handler and a double catch handler. Show that only the double catch handler executes regardless of whether the int or the double is returned.

Homework Answers

Answer #1
#include <iostream>
using namespace std;
//function to execute conditional expression
double Number_exception(int n1,int x,double n2,double y)
{
  if(n1>x)
  {
    return n1;
  }
  else
  {
    return x;
  }
  if(n2>y)
  {
    return n2;
  }
  else
  {
    return y;
  }
}
int main() {
  int n1,x;
  double n2,y;
  //n1 is the value to check with x
  cout<<"Enter value of n1:\n";
  cin>>n1;
  cout<<"Enter value of x:\n";
  cin>>x;
  //n2 is the value to check with y
  cout<<"Enter value of n2:\n";
  cin>>n2;
  cout<<"Enter value of y:\n";
  cin>>y;
  //calling a function to execute conditional expression
  double result= Number_exception(n1,x,n2,y);
  //try block
  try{

    throw result;  //throwing a exception
  }
  catch(int ex)  //int type exception caught
  {
    cout<<"int exception caught";
  }
  catch(double ex) // //double type exception caught
  {
    cout<<"double exception caught";
  }

  
}

Output::

Note:: In case you have any problem please comment in comment section.I will definately solve your problems.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
QUESTION 1 What does the following code segment output? int red, blue; red = 7; blue...
QUESTION 1 What does the following code segment output? int red, blue; red = 7; blue = red + 2 * 5 red++; blue = blue + red; cout << blue; 4 points    QUESTION 2 Is the following statement true or false? The Boolean expression in the following if statement will be true for all values of x in the range from 10 to 20 (including the endpoints) and false for all other values: int x; if (x >=...
this is the book name. Data Structures and Abstractions with Java 1) Description: The sample programs...
this is the book name. Data Structures and Abstractions with Java 1) Description: The sample programs in Chapter 1 of your textbook are not complete. They are used for illustration purpose only. The implementation of Listing 1-1 on page 39 is explained in Chapter 2. And, in order to see the result of using it, we will need the following set of files: i. BagInteface.java – the specification only. ii. ArrayBag.java – the implementation of BagInerface.java. iii. ArrayBagDemo.java – a...
Please summarize the below article in approximately 100 words: Monumental function in British Neolithic burial practices...
Please summarize the below article in approximately 100 words: Monumental function in British Neolithic burial practices Ian Kinnes The high-risk rate of survival for the non-megalithic series of Neolithic funerary monuments, recently re-emphasized by Piggott (1973: 34), introduces a further variable into the deductive study of burial practices. In Britain and Europe the overall distribution of monumental forms present both lacunae and a marked preponderance of cairns over earthen mounds which are in ill accord with the known or predicted...
Mattel Responds to Ethical Challenges Business Ethics This case was written by Debbie Thorne, John Fraedrich,...
Mattel Responds to Ethical Challenges Business Ethics This case was written by Debbie Thorne, John Fraedrich, O. C. Ferrell, and Jennifer Jackson, with the editorial assistance of Jennifer Sawayda. This case was developed for classroom discussion rather than to illustrate either effective or ineffective handling of an administrative, ethical, or legal discussion by management. All sources used for this case were obtained through publicly available material. Mattel, Inc. is a world leader in the design, manufacture, and marketing of family...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT