12-1等腰三角形の面積(100満点)問題記述三角形の3辺の長さを入力し、等腰三角形であるかどうかを判断し、その面積を計算する.注意データが等腰三角形でないデータを入力する場合は、exception処理を使用する必要があります.


#include #include #include
using namespace std;
/この関数を完全にする/double calArea(double a,double b,double c){}
int main(){ double a, b, c; cin >> a >> b >> c; try{ double area = calArea(a, b, c); cout << area << endl; }catch(exception& e){ cout << e.what() << endl; } }
入力記述入力三角形の3辺
出力記述入力が確かに等腰三角形であれば、その面積を出力し、2桁の小数を保持する.
二等辺三角形でなければ、異常を投げ出して文字列「The input is illegal」を出力します.
サンプル入力3 4 5
サンプル出力The input is illegal
#include 
#include 
#include 
#include 
using namespace std;

double calArea(double a, double b, double c) throw (invalid_argument)
{

	if (a <= 0 || b <= 0 || c <= 0)
		throw invalid_argument("The input is illegal");
	if (a + b <= c || b + c <= a || c + a <= b)
		throw invalid_argument("The input is illegal");
	if (a != b && a != c && b != c)
		throw invalid_argument("The input is illegal");
	else
	{
		double p = (a + b + c) / 2;
		return  sqrt(p*(p - a)*(p - b)*(p - c));
	}
}

int main(){
    double a, b, c;
    cin >> a >> b >> c;
    try{
        double area = calArea(a, b, c);
        cout << fixed << setprecision(2) << area << endl;
    }catch(exception& e){
        cout << e.what() << endl;
    }
}