Inheritance implementation of c ++ standard exception classes

Source: Internet
Author: User

The source is Baidu. Querying and learning

// Abnomaltest. cpp: defines the console applicationProgram.
# Include "stdafx. H"
# Include <iostream>
Using namespace STD;
Class triangle: Public exception // class that defines a triangle
{
Public:
Float a, B, c, d;
Float S;
Public:
Triangle ()
{}
Triangle (float A1, float B1, float C1)
{
A = A1;
B = b1;
C = C1;
}
Void judgment () Throw (exception) // you can check whether a triangle exists.
{
If (a + B) <c | (A + C) <B | (C + B) <A) // any side and smaller than the third side are not triangles
{
Throw exception ("not a triangle ");
}
}
Void dimension () // calculated area
{
D = (A + B + C)/2; // Helen Formula
S = SQRT (D * (d-a) * (D-B) * (D-C ));
}
};
Void _ tmain ()
{
Triangle A (7,2, 3 );

try
{< br>. judgment ();
. dimension ();
cout <"area of Triangle A:" <. S }< br> catch (exception & E)
{< br> wcout }< BR >}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.