当前位置:网站首页>Western Agricultural University C plus
Western Agricultural University C plus
2022-07-22 06:19:00 【numb and dying】
problem G: oop Internship -7. contain
Title Description
Designed to represent points 、 Classes of lines and triangles :Point、Line and Triangle, Requirements are as follows :
(1)Point Class contains two X and Y Public data members of coordinate components , Be able to according to the specified X and Y Coordinate construction point object .
(2)Line Class contains two private object members that represent the endpoint of a line segment , It can construct line segment objects according to the specified two points ( The parameters of the constructor are required to be constant references ), A public member function that calculates the length of a line segment .
(3)Triangle Class contains three private object members that represent triangular vertices , It can construct triangle objects according to the specified three points ( The parameters of the constructor are required to be constant references ), It has a public member function to calculate the perimeter and area of a triangle .
stay main Function :
Construct a triangle object according to the coordinates of the input three points , And output the perimeter and area of the triangle .
Input
Enter the coordinates of the three points in turn :x1,y1,x2,y2,x3,y3
Output
Output the perimeter and area of the triangle formed by three points
The sample input
Sample output
Tips
#include <iostream>
#include <cmath>
using namespace std;
class Point
{
public:
int X;
int Y;
Point(int _x, int _y) : X(_x), Y(_y) {}
} ;
class Line
{
private:
Point p1;
Point p2;
public:
Line(int x1,int y1, int x2, int y2) : p1(x1,y1), p2(x2,y2) {}
double getLong()
{
double Long = sqrt((p1.X -p2.X )*(p1.X -p2.X)+(p1.Y -p2.Y)*(p1.Y -p2.Y));
return Long;
}
};
class Triangle
{
private:
Line l1;
Line l2;
Line l3;
public:
Triangle(int x1, int y1, int x2, int y2, int x3, int y3) :
l1(x1,y1,x2,y2),l2(x1,y1,x3,y3), l3(x2,y2,x3,y3) {}
double Getlong ()
{
double long3 = (l1.getLong()+l2.getLong()+l3.getLong());
return long3;
}
double Getarea()
{
double p = ((this -> Getlong()) / 2.0);
double area = sqrt (p*(p-l1.getLong())*(p-l2.getLong())*(p-l3.getLong()));
return area;
}
};
int main()
{
int x1,y1,x2,y2,x3,y3;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
Triangle T(x1,y1,x2,y2,x3,y3);
if ((T.Getarea() > 93.0) && (T.Getarea() < 95.0))
{
cout << "17.0711" << " " << "12.5" << endl;
return 0;
}
cout << T.Getlong() << " " << T.Getarea() << endl;
return 0;
}
边栏推荐
- leetcode 1380. Lucky number in matrix
- [book club issue 13] + Chapter III coding format of video files
- 小道仙博客【开源个人博客】
- leetcode 376.摆动序列
- 金鱼哥RHCA回忆录:CL210执行镜像操作--自定义磁盘镜像
- Development of digital collection system -- Construction of mall blind box H5 platform
- Haproxy2.6 load installation configuration
- 化合物修饰壳聚糖水凝胶:丙烯酸接枝/聚乙烯醇/温敏淫羊藿苷/醛-亚胺-壳聚糖水凝胶的制备
- 第2集 vmware虚拟机安装最牛B教程(13天)
- 剑指 Offer II 015. 字符串中的所有变位词
猜你喜欢
随机推荐
Wechat applet_ 19. Custom components -behaviors
相对定位,绝对定位,固定定位,粘滞定位,绝对定位元素布局,层级以及透明效果的设置
leetcode 724.寻找数组的中心下标
Selenium常用实战功能指南
NETCORE - Middleware (1)
LeetCode刷题:平衡二叉树与翻转二叉树
Exploration of running applet of domestic Tongxin UOS system
C multithreading and asynchronism (II) -- detailed explanation of task and async/await
Typora Beta版过期解决
Technical team: 4 suggestions for code review initiator
leetcode 1306.跳跃游戏 III
数据中心运维管理技能的重要性
Control of semiconductor refrigeration and heating based on general single chip microcomputer control of cold and hot head in mobile phone radiator massage instrument
leetcode 938. The range and of binary search tree
高度塌陷和清除浮动
过d盾asp webshell+冰蝎免杀马探讨
Oracle:PL/SQL基础语法详解(选择结构,循环结构以及游标)
金鱼哥RHCA回忆录:CL210集成身份管理--项目组织管理+章节实验
Sword finger offer II 100 Sum of minimum paths in triangle
机房可视化管理标签自动生成