Computer Science, asked by gurcharansingh8234, 11 months ago

Write a program with following :

a. A function to read two double type numbers from keyboard

b. A function to calculate the division of two numbers

c. A try block to throw an exception when a wrong type of data is

keyed in

d. A try block to detect and throw an exception if the condition

“divided –by-zero” occurs

e. Appropriate catch block to handle the exceptions thrown​

Answers

Answered by ranyodhmour892
2

Answer:

include <iostream>

using namespace std;

class gajjar

{

double a,b;

public:

void read()

{

cout<<"\nEnter two double type numbers:";

cin>>a>>b;

}

void div()

{

try{

if(cin.fail())

throw "Bad input!";

if( b == 0 )

throw 0;

cout<<"\nAns is "<<a/b;

}

catch(const int n)

{

cout << "\nDivision by " << n << " not allowed\n";

}

catch(const char* Str)

{

cout<< Str;

}

}

};

int main()

{

gajjar k;

k.read();

k.div();

return 0;

Answered by shrutisharma4567
3

REFER THIS ATTACHMENT GIVE ABOVE

REFER THIS ATTACHMENT GIVE ABOVEPLZ MARK IT AS BRAINLIEST!!!

Attachments:
Similar questions