First page Back Continue Last page Graphics

fig13_01.cpp (2 of 3)

  • 26 // perform division and throw DivideByZeroException object if
  • 27 // divide-by-zero exception occurs
  • 28 double quotient( int numerator, int denominator )
  • 29 {
  • 30 // throw DivideByZeroException if trying to divide by zero
  • 31 if ( denominator == 0 )
  • 32 throw DivideByZeroException(); // terminate function
  • 33
  • 34 // return division result
  • 35 return static_cast< double >( numerator ) / denominator;
  • 36
  • 37 } // end function quotient
  • 38
  • 39 int main()
  • 40 {
  • 41 int number1; // user-specified numerator
  • 42 int number2; // user-specified denominator
  • 43 double result; // result of division
  • 44
  • 45 cout << "Enter two integers (end-of-file to end): ";
  • 46