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 >=...
#include<iostream> #include<iomanip> using namespace std; int main() { //variables int choice; float radius,base,height,area; const double PI=3.14159;...
#include<iostream> #include<iomanip> using namespace std; int main() { //variables int choice; float radius,base,height,area; const double PI=3.14159; //repeat until user wants to quits while(true) { //menu cout<<endl<<endl<<"Geometry Calculator"<<endl<<endl; cout<<"1. Calculate the area of a circle"<<endl; cout<<"2. Calculate the area of a triangle"<<endl; cout<<"3. Quit"<<endl<<endl; //prompt for choice cout<<"Enter your choice(1-3): "; cin>>choice; cout<<endl; //if choice is circle if(choice==1) { cout<<"What is the radius of the circle? "; cin>>radius; //calculating area area=PI*radius*radius; cout<<endl<<"The area of the circle is "<<fixed<<setprecision(3)<<area<<endl; } //if choice...
// Lab Homework 9 // Logical Operator AND and OR // Demonstrate how to use a...
// Lab Homework 9 // Logical Operator AND and OR // Demonstrate how to use a logical operator // with a Boolean expression. #include <iostream> #include <cctype> // for tolower() using namespace std; int main() {    /* Create a program that produces the Sample Output shown at the bottom.    You MUST:    - Output all of the lines show below in the Sample Output - spacing, spelling, punctuation, etc. must be exact matches    NOTE: There are FOUR...
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