题目
1,设计一个点类point,再设计一个矩形类,矩形类使用point类的两个坐标点作为矩形的对角顶点,并可以输出4
提问时间:2021-03-16
答案
段并输出其属性(斜率、长度、两个端点坐标),
再设计一个矩形类,矩形类使用线段类作为矩形的一条边,并可以输出四个坐标点和面积.最后设计
一个主函数用来测试以上两个类的功能.*/
#include <iostream>
#include <math.h>
using namespace std;
class POINT
{
public:
int x;
int y;
};
class line
{
public:
float getLen();
float getSlope();
void setline(POINT a,POINT b);
void display();
line()
line(int a,int b,int c,int d)
line(){};
public:
POINT one,two;
};
class figure
{
public:
float getArea();
void disPoit();
public:
line top,left,buttom,right;
};
//设置线段
void line::setline(POINT a,POINT b)
{
one = a; two = b;
}
//求线段的长度
float line::getLen()
{
float len;
len = sqrt((two.y-one.y)*(two.y-one.y) + (two.x-one.x)*(two.x-one.x));
return len;
}
//求线段的斜率
float line::getSlope()
{
float slope;
slope = (two.y-one.y) / (two.x-one.x);
return slope;
}
//输出线段的斜率、长度、
void line::display()
{
cout << "斜率:" << getSlope() << endl;
cout << "长度:" << getLen() << endl;
cout << "两个端点坐标分别为:" << "(" << one.x << "," << one.y <<")"
<< "(" << two.x << "," << two.y <<")" << endl;
}
//求矩形的面积
float figure::getArea()
{
float area;
area = top.getLen() * left.getLen();
return area;
}
//输出四个端点
void figure::disPoit()
{
cout << "四个端点坐标分别为:"
<< "(" << top.one.x << "," << top.one.y <<")"
<< "(" << left.one.x << "," << left.one.y <<")"
<< "(" << buttom.one.x << "," << buttom.one.y <<")"
<< "(" << right.one.x << "," << right.one.y <<")"
<< endl;
}
int main()
{
cout << "" << endl;
figure f;
POINT a,b,c,d;
a.x = 1;
a.y = 1;
b.x = 3;
b.y = 1;
c.x = 3;
c.y = 3;
d.x = 1;
d.y = 3;
f.top.setline(a,b);
f.left.setline(b,c);
f.buttom.setline(c,d);
f.right.setline(d,a);
f.disPoit();
cout << "矩形的面积:" << f.getArea() << endl;
return 0;
}
再设计一个矩形类,矩形类使用线段类作为矩形的一条边,并可以输出四个坐标点和面积.最后设计
一个主函数用来测试以上两个类的功能.*/
#include <iostream>
#include <math.h>
using namespace std;
class POINT
{
public:
int x;
int y;
};
class line
{
public:
float getLen();
float getSlope();
void setline(POINT a,POINT b);
void display();
line()
line(int a,int b,int c,int d)
line(){};
public:
POINT one,two;
};
class figure
{
public:
float getArea();
void disPoit();
public:
line top,left,buttom,right;
};
//设置线段
void line::setline(POINT a,POINT b)
{
one = a; two = b;
}
//求线段的长度
float line::getLen()
{
float len;
len = sqrt((two.y-one.y)*(two.y-one.y) + (two.x-one.x)*(two.x-one.x));
return len;
}
//求线段的斜率
float line::getSlope()
{
float slope;
slope = (two.y-one.y) / (two.x-one.x);
return slope;
}
//输出线段的斜率、长度、
void line::display()
{
cout << "斜率:" << getSlope() << endl;
cout << "长度:" << getLen() << endl;
cout << "两个端点坐标分别为:" << "(" << one.x << "," << one.y <<")"
<< "(" << two.x << "," << two.y <<")" << endl;
}
//求矩形的面积
float figure::getArea()
{
float area;
area = top.getLen() * left.getLen();
return area;
}
//输出四个端点
void figure::disPoit()
{
cout << "四个端点坐标分别为:"
<< "(" << top.one.x << "," << top.one.y <<")"
<< "(" << left.one.x << "," << left.one.y <<")"
<< "(" << buttom.one.x << "," << buttom.one.y <<")"
<< "(" << right.one.x << "," << right.one.y <<")"
<< endl;
}
int main()
{
cout << "" << endl;
figure f;
POINT a,b,c,d;
a.x = 1;
a.y = 1;
b.x = 3;
b.y = 1;
c.x = 3;
c.y = 3;
d.x = 1;
d.y = 3;
f.top.setline(a,b);
f.left.setline(b,c);
f.buttom.setline(c,d);
f.right.setline(d,a);
f.disPoit();
cout << "矩形的面积:" << f.getArea() << endl;
return 0;
}
举一反三
已知函数f(x)=x,g(x)=alnx,a∈R.若曲线y=f(x)与曲线y=g(x)相交,且在交点处有相同的切线,求a的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
最新试题
- 1某企业投资300 000元购入一台设备,该设备预计残值为2 800元,可使用5年,折旧按双倍余额递减法计算.设备投产后每年销售收入增加额分别为200 000元、150 000元、80 000元,100
- 2水泥22元50KG,沙子127/m3,水3.4元/吨,按照比例砌一方麻石需要多少成本?
- 3—— of the teachers in out school are women teachers.
- 43句中翻英求教在线等
- 5确定线段中点的方法怎样把线段分成相等
- 6已知数列{an}的前n项和为Sn,满足2Sn+3=3an(n是正整数),{bn}是等差数列,且b2=a1,b4=a1+4
- 7有40名同学排队,要求每行人数相同,有几种排法、
- 8在某一变化过程中,有两个变量x,y在某一法则的作用下如果对于x的每一个值y都有唯一的值与其相对应
- 9m为何值时,关于X的方程5/X减1/X减2=m+4/X平方减2X无解?
- 10Our earth is in danger so taking action to protect it is important为什么要用taking
热门考点
- 1每做完一种样品的焰色反应实验后,要用硫酸溶液将铂丝洗净.这句话怎么错了?
- 2HEX COUPLING NUTS怎么翻译
- 3为什么难以结晶的无定型聚合物的聚合物在溶液、熔体或橡胶态时构象容易变化?
- 4甲乙两车做匀速直线运动,若两车在相同时间内经过的路程之比是1:2,则速度之比( ),若两车经过相同路程
- 5英语翻译
- 6请你逆用因式分解法写出一个一元二次方程,要求二次项系数不为1,且其两根互为倒数.
- 7将12摩尔一氧化氮倒扣于水中再通氧气,反应后气体剩余4毫升,则通入氧气的体积是多少毫升
- 8已知实数x,y满足 2x+y-2>=0,x-2y+k>=0,x-1
- 9已知行列式f(x)=|(中间是个4*4的行列式我写后面)|.求x^3的系数.x 1 1 2 1
- 10简算41.2×8.1+4.12×23-412×0.04