Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a program titled Division. Have the program prompt the user \"Enter numer

ID: 3624879 • Letter: C

Question

Create a program titled Division. Have the program prompt the user "Enter numerator and denominator" and store the two values entered. (If you wish the user to "Enter numerator/denominator" be sure to adjust your data gathering variables to include a holder variable for the slash character.)

Include a function titled Quotient that takes 2 integers as input and provides the quotient of the 2 integers as integer output. (The remainder is truncated. Thus, 5/3 will be 1.)

Define an exception class divByZero and have the function Quotient use throw for an exception of this type if the denominator is 0. Display output "You cannot have a denominator that is equal to 0."

Quotient throws an exception to the higher-level function main to decide whether or not the program should be terminated. Main catches the divByZero and prints out an appropriate comment on the screen. Also include in main a try block to catch the divide-by-zero error.

If no exception occurs, print out a message "The quotient is xxxxx."

Explanation / Answer

#include<iostream>
#include<conio.h>
using namespace std;
class DivByZero {}; // Exception class
int Quotient(int numer,int denom)    // The numerator and // The denominator
{
if (denom == 0)
     throw DivByZero();              //throw exception of class DivByZero
return numer / denom;
}
int main()
{
    int a,b;
    cout << "enter values of a and b"<<endl;
    cin >> a >> b;
    try
    {
        cout << "The quotient is " << Quotient(a,b) <<endl;
    }
    catch( DivByZero) // catch Exception Here.
    {
    cout<< "You cannot have a denominator that is equal to 0." <<endl;
    }
    getch();
    return 0;
}

// give input separated by space ....... Enjoy Cheers.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote