矩形相关操作
来源:互联网 发布:世界经济学家排名 知乎 编辑:程序博客网 时间:2024/06/05 16:39
题目描述
如下结构用来存储图像屏幕上的对象信息。
struct point {int x, y;};
struct rectangle{struct point upper_left, lower_right;};
编写函数,要求可以在rectangle结构变量r上执行以下操作,且r作为实际参数传递
1.计算r的面积
2.计算r的中心,并且以此中心作为point值返回,如果中心的x或y坐标不为整数,取整数值
3.确定点p是否在r内,返回1或0.(p是struct point类型的另外一个实际参数)
输入描述
输入分两行
第一行输入四个整数,分别代表矩形的左上角和右下角坐标
第二行输入两个整数,代表某个点的坐标
输出描述
输出分三行
Area of r is 面积值
Center of r is <中心点坐标>
Point <输入点的坐标> is [not] in r
代码
<span style="font-size:14px;">#include<iostream>using namespace std;struct point{int x, y;};struct rectangle{struct point upper_left, lower_right;};int mj(int x1, int y1, int x2, int y2){int s;s = (x2 - x1)*(y1 - y2);return s;}struct point u(int x1, int y1, int x2, int y2){point p;p.x = (x1 + x2) / 2; p.y = (y1 + y2) / 2;return p;}int r(int x1, int y1, int x2, int y2, int x3, int y3){if ((x1 <= x3) && (x3 <= x2) && (y1 >= y3) && (y3 >= y2))return 1;elsereturn 0;}int main(){int s,a;int x1, x2, y1, y2, x3, y3;struct point b;cin >> x1 >> y1 >> x2 >> y2;cin >> x3 >> y3;struct point upper_left = { x1, y1 };struct point lower_right = { x2, y2 };s = mj(x1, y1, x2, y2);b=u(x1, y1, x2, y2);cout << "Area of r is " << s << endl;cout << "Center of r is <" << b.x<<","<<b.y << ">" << endl;a = r(x1, y1, x2, y2, x3, y3);if (a ==1)cout << "Point " << "<" << x3 << "," << y3 << "> is in r";elsecout << "Point " << "<" << x3 << "," << y3 << "> is not in r";return 0;}</span>
是struct oint类型的另外一个实际参数)
0 0
- 矩形相关操作
- 和矩形相关的操作
- 矩形、区域相关
- 矩形操作工具箱
- cua-mode 可视化矩形操作
- OpenCV矩形rect的操作
- shape相关属性测试(默认矩形)
- opencv2-基本鼠标操作之画矩形
- opencv鼠标操作及GUI矩形绘画
- 矩形框选进行查询操作
- opencv 对于矩形框的操作
- 矩形
- 矩形
- 矩形
- 矩形
- 矩形
- 矩形
- 矩形
- DP 动态规划 Problem B 1002 求最长上升子序列的长度
- HashMap源码分析
- 关于内链优化的几个细节问题
- Disabling contextual LOB creation as createClob() method threw error : java.lang
- 内存管理-----伙伴系统---2
- 矩形相关操作
- 数据结构-链表-作业
- mybaties自动创建代码
- leetcode 083 Remove Duplicates from Sorted List
- pretrain ConvNet 转接和fine-tuning
- 如何在DW中设置自动列宽
- c++实验5-求和
- UVA 11478V Halum 二分答案+差分约束系统
- 我的第一个Python程序