Sorted out classic triangles circulating on the InternetCode, Added content that you understand.
The final goal is to first use try catch blocks in C ++. Then I thoroughly understood the error mechanism of C ++.
Here, I would like to share with you what is wrong with writing, or what is wrong with writing,
You are welcome to raise any suggestions for better improvement.
I would like to be grateful here.
// Abnomaltest. cpp: defines the console application Program . // # Include "stdafx. H "# include <iostream> # include <afx. h> using namespace STD; Class triangle // defines the class of a triangle {public: float a, B, c, d; // triangle three sides a, B, c, helen formula constant dfloat s; // Triangle Area public: triangle () {} triangle (float A1, float B1, float C1) {A = A1; B = b1; C = C1;} // judge whether the triangle string judgment ()/* Throw (string) is called the exception specification */{string temp; int tempnum; if (a + B) <c | (A + C) <B | (C + B) <A) {tempnum = 9; temp = "not a triangle "; wcout <temp. c_str () <Endl; throw (tempnum);}/* Throw with throw. It is not visible output on the console, but is followed by catch, then process */else {/* locale LOC ("CHS"); wcout. imbue (LOC); */temp = "Triangle"; cout <temp. c_str () <Endl; throw (temp) ;}} void dimension () // calculated area {d = (A + B + C)/2; // Helen formula S = SQRT (D * (d-a) * (D-B) * (D-C) ;}}; int _ tmain (INT argc, _ tchar * argv []) {Triangle A (7,2, 3); // only pass the value, initialize try {. judgment ();. dimension (); cout <"area of Triangle A:" <. S <Endl;} // catch (string & temperr) // Accepted. Accepted. Please note that I have defined a string to accept it. // {// Either use the Catch Block defined by myself or use the omnipotent Catch Block. It seems that the two cannot be used simultaneously. // wcout <temperr. c_str () <Endl; //} catch (...) {/* locale LOC ("CHS"); // either use this block output or use another output wcout. imbue (LOC); wcout <L "Universal capture" <Endl; */cout <"Universal capture" <Endl ;}return 0 ;}