当前位置:网站首页>Triangle class (construction and deconstruction)
Triangle class (construction and deconstruction)
2022-06-25 04:42:00 【SZU healing system bug】
Catalog
Title Description
Define a triangle class CTriangle, Attribute contains three sides and triangle type , Where the triangle type is saved in a string . Triangle types are as follows :
an isosceles triangle :isosceles triangle
right triangle :right triangle
Isosceles right triangle :isosceles right triangle
Equilateral triangle :equilateral triangle
General triangle :general triangle
Can't make a triangle :no triangle
The conditions for judging right triangle : The square length of one of the three sides of a triangle is equal to the sum of the square lengths of the other two sides
Class behavior includes constructing 、 destructor 、 Calculate the area, etc . Where the constructor will set the length of three edges , And judge whether the three sides can form a triangle 、 And set the triangle type . The destructor clears the length of the three edges 0, And set the triangle type to none
The triangle area is calculated as follows
Input
Number of groups of test data
The first set of edges 1 The first set of edges 2 The first set of edges 3
The second set of edges 1 The second set of edges 2 The second set of edges 3
......
Output
The first triangle type , area
The second triangle type , area
......
If you don't form a triangle , There is no need to output area
Area precision to the decimal point 1 position
sample input 1
3
3.0 2.0 6.0
3.0 4.0 5.0
1.0 1.0 1.414
sample output 1
no triangle
right triangle, 6.0
isosceles right triangle, 0.5
AC Code
#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();
}
}
边栏推荐
- CTF_ Web: Changan cup-2021 old but a little new & asuka
- 第九章 APP项目测试(2) 测试工具
- GBASE 8s 索引R树
- 【Flink】RocksDB增量模式checkpoint大小持续增长的问题及解决
- Gbase 8s stored procedure execution and deletion
- LabVIEW development gas regulator
- Gbase 8s stored procedure syntax structure
- 分布式websocket搭建方案
- php封装curl发送get、post请求方法,并使用
- STM32的DMA双缓冲模式详解
猜你喜欢
cnpm : 无法加载文件 C:\Users\Administrator\AppData\Roaming\npm\cnpm.ps1,因为在此系统上禁止运行脚本。
机器学习深度学习——向量化
ROS2/DDS/QoS/主题的记录
简单的恶意样本行文分析-入门篇
2.0springmvc uses restful
A detailed summary of four handshakes (or four waves) over TCP connections
Deep learning - several types of learning
Bingbing's learning notes: implementation of circular queue
成功解决:selenium.common.exceptions.TimeoutException: Message: timeout: Timed out receiving message from
CTF_ Web: advanced problem WP (5-8) of attack and defense world expert zone
随机推荐
【FLink】access closed classloader classloader.check-leaked-classloader
GBASE 8s活锁、死锁问题的解决
CTF_ Web: file contains pseudo protocol with PHP
重磅直播 | 相移法+多频外差之数学原理推导+实现
cannot import name ‘escape’ from ‘jinja2’【成功解决】
Record the problem of C # print size once
初识 Flutter 的绘图组件 — CustomPaint
Sleep more, you can lose weight. According to the latest research from the University of Chicago, sleeping more than 1 hour a day is equivalent to eating less than one fried chicken leg
GBASE 8s存儲過程語法結構
2.0springmvc uses restful
ROS2/DDS/QoS/主题的记录
Concat() in JS
GBase 8s 锁的分类
A detailed summary of four handshakes (or four waves) over TCP connections
How to apply for software
大话云原生数据库中的存算分离
Part I Verilog quick start
计算学生成绩等级(虚函数和多态)
Immutable學習之路----告別傳統拷貝
30岁了开始自学编程,家里比较困难还来得及吗?