1 / 7

Chapter 9 Completing the Basics

C++ for Engineers and Scientists Third Edition. Chapter 9 Completing the Basics. Run Time E rrors. #include <iostream> using namespace std; int main() { int top, bottom; cout << "Enter the top number (whole number only): " ; cin >> top;

tejana
Download Presentation

Chapter 9 Completing the Basics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. C++ for Engineers and Scientists Third Edition Chapter 9 Completing the Basics

  2. Run Time Errors #include<iostream> usingnamespace std; int main() { int top, bottom; cout << "Enter the top number (whole number only): "; cin >> top; cout << "Enter the bottom number (whole number only): "; cin >> bottom; cout << top <<'/' << bottom << " = " << double(top)/ double(bottom) << endl; }

  3. Catch the error #include<iostream> usingnamespace std; int main() { int numerator, denominator; try { cout << "Enter the numerator (whole number only): "; cin >> numerator; cout << "Enter the denominator(whole number only): "; cin >> denominator; if (denominator == 0) throw denominator; // an integer value is thrown else cout << numerator <<'/' << denominator << " = " << double(numerator)/ double(denominator) << endl; } catch(int e) { cout << "A denominator value of " << e << " is invalid." << endl; exit (1); // Abnormal exit } }

  4. Exception Handling • General syntax of code required to throw and catch and exception: • catch an exception

  5. Exception Handling

  6. Lab Ex. • P. 518, Ex. 6 • Send program and outputs • To: ChanT@ucj.edu.sa • Subject: 32110236, CS125, 2013.5.7

  7. Lab Ex. • P. 518, Ex. 7 • Modify the program so that it continues to try to divide 2 numbers until the user enters the character q to quit. • Send program and outputs • To: ChanT@ucj.edu.sa • Subject: 32110236, CS125, 2013.5.7

More Related