当前位置:网站首页>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();
}
}边栏推荐
- Gbase 8s overall architecture
- GBASE 8s 总体架构
- Successfully solved: selenium common. exceptions. TimeoutException: Message: timeout: Timed out receiving message from
- Simple text analysis of malicious samples - Introduction
- Join() in JSZ
- Why PHP is not safe
- A detailed summary of four handshakes (or four waves) over TCP connections
- 【无标题】
- LabVIEW development gas regulator
- Thorough understanding of database transactions
猜你喜欢

Code scanning payment flow chart of Alipay payment function developed by PHP

What is the storage engine and the three common database storage engines for MySQL

Cnpm: unable to load file c:\users\administrator\appdata\roaming\npm\cnpm PS1 because running scripts is prohibited on this system.

js中的concat()

File upload vulnerability shooting range upload labs learning (pass1-pass5)

GBASE 8s 总体架构

Unity Quad culls shaders with back faces and transparent parts

Simple text analysis of malicious samples - Introduction

第九章 APP项目测试(2) 测试工具

Bingbing's learning notes: implementation of circular queue
随机推荐
Kotlin Compose 监听软键盘 点击enter提交事件
GBASE 8S内存管理
OOP 向量加减(友元+拷贝构造)
[Flink] problems and solutions of the continuous growth of checkpoint size in rocksdb incremental mode
Introduction to the isolation level of gbase 8s
Gbase 8s overall architecture
GBASE 8s 索引B+树
Upgrade PHP to php7 The impact of X (2), the obsolescence of mcrypt decryption
第九章 APP项目测试(2) 测试工具
Cnpm: unable to load file c:\users\administrator\appdata\roaming\npm\cnpm PS1 because running scripts is prohibited on this system.
Gbase 8s index b+ tree
Value transfer between parent and child components of wechat applet
CTF_ Web: deserialization of learning notes (II) CTF classic test questions from shallow to deep
GbASE 8s中的Blob 页(Blobspace page)
js中的concat()
Basic introduction of gbase 8s blocking technology
Retrofit source code analysis
GBase 8s 锁的分类
Structure syntaxique des procédures stockées gbase 8S
分布式websocket搭建方案