当前位置:网站首页>[Central South University of forestry science and technology] [Chen] ninth week operation triangle exception handling
[Central South University of forestry science and technology] [Chen] ninth week operation triangle exception handling
2022-04-21 22:35:00 【Neon Yu Yan】
2、 exception handling try Check throw Throw out catch Capture
Enter the length of the three sides of the triangle , Find the area of the triangle . When the length of the input edge is less than or equal to 0, Throw out int abnormal , Give a warning and end the procedure .
Or when all three sides are greater than 0, But when you can't form a triangle ( The sum of the two sides is greater than that of the third side ), Throw out double abnormal , Give a warning and end the program .
#include<iostream>
#include<cmath>
using namespace std;
class Triangle
{
double a;
double b;
double c;
double s;
public:
double area()
{
double l = (a + b + c) / 2;
if (a <= 0 || b <= 0 || c <= 0 || a + b <= c || b + c <= a || c + a <= b)
{
throw a;
}else
s =sqrt( l * (l - a) * (l - b) * (l - c));
return s;
}
void setput()
{
cin >> a;
cin >> b;
cin >> c;
}
int loop()
{
try
{
while (1)
{
cout << area() << endl;
cin >> a >> b >> c;
}
}
catch (double)
{
cout << a << " " << b << " " << c << "this is a wrong" << endl;
}
cout << "end" << endl;
return 0;
}
};
int main(void)
{
Triangle tri;
tri.setput();
tri.loop();
system("puase");
return 0;
}
版权声明
本文为[Neon Yu Yan]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204212232153506.html
边栏推荐
- Kotlin core programming, Android development, interview answer handler
- CC00000.ZABBIX———————————————
- Outsourcing student management system detailed architecture design document
- CPT 102_ LEC 11
- YARN线上动态资源调优
- 【無標題】
- L1-059 敲笨钟 (20 分)
- Recursive stack with the help of classical recursive tree
- L1-058 6翻了 (15 分)
- [sans titre]
猜你喜欢

openCV——直方图处理

将模型训练外包真的安全吗?新研究:外包商可能植入后门,控制银行放款

Unity3d import tilt model, etc

CPT 102_ LEC 11
事件分发机制Android,大厂Android面试总结 详细解答

MySQL read / write separation

Wechat applet custom tabbar

君禾股份:2021年度营收增长稳健,受益产品出口业绩再创新高

Raspberry pie 3B + installation mjpg streamer

2022 Chongqing's latest architectural eight members (Civil Engineering) simulation question bank and answers
随机推荐
Byte daily practice (OC)
We sincerely invite you to sign up for the first openharmony developer growth plan sharing day
How can "Xiaodeng" enterprises solve the problem of weak password in AD domain?
Software designer - Chapter 6: system security analysis and design
行业分析| 互联网医疗的发展
YARN线上动态资源调优
【無標題】
L1-059 ringing stupid bell (20 minutes)
「运维有小邓」企业如何解决AD域弱密码问题?
INT 102_ TTL 09
CC00012.ZABBIX———————————————
L1-058 6翻了 (15 分)
2022年中级会计职称财务管理练习题及答案
算法--合并K个升序链表(Kotlin)
2022 intermediate accounting title examination economic law practice questions and answers
Byte stream write input
CC00004.ZABBIX———————————————
爆料丨曝小米本月还有新机,多款旗下产品蓄势待发
Review questions and answers of building materials and structures in 2022 first-class registered architect examination
每日练题(3)