当前位置:网站首页>三角形类(构造与析构)
三角形类(构造与析构)
2022-06-25 04:01:00 【SZU治愈系BUG】
目录
题目描述
定义一个三角形类CTriangle,属性包含三条边和三角形类型,其中用字符串保存三角形类型。三角形类型如下:
等腰三角形:isosceles triangle
直角三角形:right triangle
等腰直角三角形:isosceles right triangle
等边三角型:equilateral triangle
一般三角形:general triangle
不能构成三角形:no triangle
其中判断直角三角形条件:三角形三边中的一边长度平方等于另两边长度平方之和
类行为包括构造、析构、计算面积等等。其中构造函数将设置三条边长度,并且判断三条边能否构成三角形、并设置三角形类型。析构函数将三条边长度清0,并将三角形类型设置为none
三角形面积计算如下
输入
测试数据的组数
第一组边1 第一组边2 第一组边3
第二组边1 第二组边2 第二组边3
......
输出
第一个三角形类型,面积
第二个三角形类型,面积
......
如果不形成三角形,就无需输出面积
面积精度到小数点后1位
输入样例1
3
3.0 2.0 6.0
3.0 4.0 5.0
1.0 1.0 1.414
输出样例1
no triangle
right triangle, 6.0
isosceles right triangle, 0.5
AC代码
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
using namespace std;
class CTriangle{
string kind;
float a,b,c;
public:
CTriangle(float a,float b,float c):a(a),b(b),c(c){
if(a+b>c&&a+c>b&&b+c>a)
{
if(a==b&&b==c)
kind="equilateral triangle";
else if(a==b||a==c||b==c)
{
if(fabs(c*c-(a*a+b*b))<0.01||fabs(a*a-(b*b+c*c))<0.01||fabs(c*c+a*a-b*b)<0.01)
kind="isosceles right triangle";
else
kind="isosceles triangle";
}
else if(fabs(c*c-(a*a+b*b))<0.01||fabs(a*a-(b*b+c*c))<0.01||fabs(c*c+a*a-b*b)<0.01)
kind="right triangle";
else
kind="general triangle";
}
else
kind="no triangle";
}
~CTriangle(){
a=b=c=0;
kind="none";
}
float area(){
float p=(a+b+c)/2;
return sqrt(p*(p-a)*(p-b)*(p-c));
}
void display(){
if(kind=="no triangle")
cout<<kind<<endl;
else
cout<<kind<<", "<<fixed<<setprecision(1)<<area()<<endl;
}
};
int main() {
int t;
float a,b,c;
cin>>t;
while(t--){
cin>>a>>b>>c;
CTriangle angle(a,b,c);
angle.display();
}
}
边栏推荐
- Nodejs connects to MySQL through heidisql, and ER appears_ BAD_ DB_ ERROR: Unknown database 'my_ db_ books'
- sql_ mode=only_ full_ group_ By's pit
- Gbase 8s parallel operation problem scenario description
- 关于TCP连接三次握手的详细总结
- Unity Quad culls shaders with back faces and transparent parts
- LeetCode 劍指Offer II 091 粉刷房子[動態規劃] HERODING的LeetCode之路
- 关于TCP连接四次握手(或者叫四次挥手)的详细总结
- NFT insider 63: the sandbox reached a cooperation with Time magazine, and YGG established Spain's subdao
- LabVIEW development gas regulator
- 无法安装redis接口
猜你喜欢
Easyrecovery15 very easy to use computer data recovery software
What is the storage engine and the three common database storage engines for MySQL
Leetcode points to the leetcode road of offering II 091 house painting [dynamic planning] heroding
CTF_ Web: Advanced questions of attack and defense world expert zone WP (15-18)
马斯克发布人形机器人,AI对马斯克为什么意义重大?
js中的concat()
Anaconda安装+TensorFlow安装+Keras安装+numpy安装(包含镜像和版本信息兼容问题)
5 key indicators of SEO: ranking + traffic + session + length of stay + bounce rate
Anaconda installation +tensorflow installation +keras installation +numpy installation (including image and version information compatibility issues)
Laravel document sorting 4. Controller
随机推荐
Unit test coverage
Gbase 8s overall architecture
CTF_ Variable coverage in web:php
php开发支付宝支付功能之扫码支付流程图
Summary of various problems encountered by cocos2d-x
What is persistence? What are RDB and AOF in redis persistence?
5 key indicators of SEO: ranking + traffic + session + length of stay + bounce rate
jsz中的join()
Anaconda安装+TensorFlow安装+Keras安装+numpy安装(包含镜像和版本信息兼容问题)
Can Navicat directly operate the Android database SQLite
GBASE 8s 总体架构
L'épée leetcode fait référence au chemin leetcode de l'offre II 091 pour peindre la maison [planification dynamique] heroding
Openmmlab environment configuration
php封装curl发送get、post请求方法,并使用
Value transfer between parent and child components of wechat applet
Read lsd-slam: large scale direct monolithic slam
Communication problems in parent and child components of uniapp
Lecture record: data processing methods and applications of various spatial geodetic techniques
Synchronous and asynchronous functions (callback function, promise, generator, async/await)
Shutter fittedbox component