22 个解决方案
#1
什么叫通过类求解?
是不是编写一个三角形的类?
已知三点直接计算不是可以得出周长了么?
是不是编写一个三角形的类?
已知三点直接计算不是可以得出周长了么?
#2
是啊,编写一个三角形的类然后就求周长啊!!!救救我阿!!!!
#3
差劲!
#4
差劲!!!
#5
搂主,我想这个问题应该很大程度上是一个平面几何的问题。如果你在几何的角度能够解决问题,我想问题就解决了。
我这样子分析,三角形由三个不在同一直线上点构成,如此可以抽象出你的三角形类的基本成员数据包含三个点。计算三个点的任意两点之间的距离,三个距离的和即为所求的周长。
这是我的想法,也许还有更简单的想法,你去思考吧。
我这样子分析,三角形由三个不在同一直线上点构成,如此可以抽象出你的三角形类的基本成员数据包含三个点。计算三个点的任意两点之间的距离,三个距离的和即为所求的周长。
这是我的想法,也许还有更简单的想法,你去思考吧。
#6
#include <iostream>
#include <math.h>
using namespace std;
class Triangle {
public:
struct Coor {
int x;
int y;
Coor() :
x(0), y(0) {
}
Coor(int x, int y) :
x(x), y(y) {
}
};
Triangle(const Coor& d1, const Coor& d2, const Coor& d3) {
this->d1 = d1;
this->d2 = d2;
this->d3 = d3;
}
double GetZhouChang() {
return GetLength(d1, d2) + GetLength(d2, d3) + GetLength(d3, d1);
}
private:
double GetLength(const Coor& d1, const Coor& d2) {
return pow(pow(abs(d1.x - d2.x), 2) + pow(abs(d1.y - d2.y), 2), 0.5);
}
Coor d1;
Coor d2;
Coor d3;
};
int main(int argc, char* argv[]) {
Triangle triangle(Triangle::Coor(1, 2), Triangle::Coor(3, 5), Triangle::Coor(2, 4));
cout << triangle.GetZhouChang() << endl;
}
#include <math.h>
using namespace std;
class Triangle {
public:
struct Coor {
int x;
int y;
Coor() :
x(0), y(0) {
}
Coor(int x, int y) :
x(x), y(y) {
}
};
Triangle(const Coor& d1, const Coor& d2, const Coor& d3) {
this->d1 = d1;
this->d2 = d2;
this->d3 = d3;
}
double GetZhouChang() {
return GetLength(d1, d2) + GetLength(d2, d3) + GetLength(d3, d1);
}
private:
double GetLength(const Coor& d1, const Coor& d2) {
return pow(pow(abs(d1.x - d2.x), 2) + pow(abs(d1.y - d2.y), 2), 0.5);
}
Coor d1;
Coor d2;
Coor d3;
};
int main(int argc, char* argv[]) {
Triangle triangle(Triangle::Coor(1, 2), Triangle::Coor(3, 5), Triangle::Coor(2, 4));
cout << triangle.GetZhouChang() << endl;
}
#7
高深,还有没有更简便的??
#8
又把老师布置的作业朝这里发,管理员封了他吧。
#9
这么简单得还高深?一些基本得东西不想学,就想得到一个傻瓜级得答案是不现实得。
#10
哦哦,我只是想交流交流啦,虽是老师的作业,老师的作业就不可以讨论了吗???
我还要更易读的啊!!!!
我还要更易读的啊!!!!
#11
因为我用到了类的组合,但无法实现,应该怎么解决问题啊!!!???!!!
#12
快来人啊!!!
#13
你这哪是交流啊?这个是非常简单的东西,你只希望从别人那得到,而不是交流
人家已经告诉你怎么做了,只是你看不懂。我想比jamesfancy(边城狂人) 的答案更简单的方法是没有的。还能怎么简单呢?你要是看不懂,再怎么问也没有用
人家已经告诉你怎么做了,只是你看不懂。我想比jamesfancy(边城狂人) 的答案更简单的方法是没有的。还能怎么简单呢?你要是看不懂,再怎么问也没有用
#14
那能够不使用那个struct吗?我就是不想要那个struct.
#15
不要总“就是不想要”,设计程序应该多考虑合理性,你这个就是不想要非常不make sense
#16
晕了,没的救了到处求救还是没结果!!
#17
如果啥都按你想的,你自己写出来不就好了
#18
写一个triangle类,里面包含了三个点(2D或者3D)。在构造函数以及operator=()函数中判断这三个点是否能够成为一个真正的三角形,如果重点或者共线的话,就抛个异常。然后再写一个perimeter函数求出周长即可。有时间的话写一个class template。
#19
学过数学的都知道
#20
#include"iostream.h"
#include"math.h"
class dian{
public:
dian(float xx=0,float yy=0){
x=xx;y=yy;}
float getx(){return x;}
float gety(){return y;}
private:
float x; //x坐标
float y; //y坐标
};
class bianchang1
{
public:
bianchang1(dian xd1,dian xd2);
double getbc1(void){return bc1;}
private:
dian d1,d2;
double bc1;
};
bianchang1::bianchang1(dian xd1,dian xd2):d1(xd1),d2(xd2)
{
double x1=double(d1.getx()-d2.getx());
double y1=double(d1.gety()-d2.gety());
bc1=sqrt(x1*x1+y1*y1);
}
class bianchang2
{
public:
bianchang2(dian xd1,dian xd3);
double getbc2(void){return bc2;}
private:
dian d1,d3;
double bc2;
};
bianchang2::bianchang2(dian xd1,dian xd3):d1(xd1),d3(xd3)
{
double x2=double(d1.getx()-d3.getx());
double y2=double(d1.gety()-d3.gety());
bc2=sqrt(x2*x2+y2*y2);
}
class bianchang3
{
public:
bianchang3(dian xd2,dian xd3);
double getbc3(void){return bc3;}
private:
dian d2,d3;
double bc3;
};
bianchang3::bianchang3(dian xd2,dian xd3):d2(xd2),d3(xd3)
{
double x3=double(d2.getx()-d3.getx());
double y3=double(d2.gety()-d3.gety());
bc3=sqrt(x3*x3+y3*y3);
}
float pd();
double zhouchang();
double a,b,c;
float jieguo = 0 ;
void main()
{
dian d1(1,3),d2(2,3),d3(0,0);
bianchang1 bc1(d1,d2);a=bc1.getbc1();
bianchang2 bc2(d1,d3);b=bc2.getbc2();
bianchang3 bc3(d2,d3);c=bc3.getbc3();
cout<<"a="<<bc1.getbc1()<<endl;
cout<<"b="<<bc2.getbc2()<<endl;
cout<<"c="<<bc3.getbc3()<<endl;
jieguo = pd();
zhouchang();
}
float pd()
{
cout<<"判断是否能构成三角形"<<endl;
if(a+b>c && a+c>b && b+c>a)
{
cout<<"此三点能构成三角形!!!";
return jieguo = 1;
}
else {
cout<<"此三点不能构成三角形."<<endl;
return jieguo = 0;
}
}
double zhouchang()
{
double zc;
if(jieguo == 1 )
{
zc=a+b+c;
cout<<"此三角形的周长为:"<<zc<<endl;
}
return 0;
}
//弄了个这么样的,怎么才能改成是随自己任意输入三点的样式呢?
一万个感谢!!!!
#include"math.h"
class dian{
public:
dian(float xx=0,float yy=0){
x=xx;y=yy;}
float getx(){return x;}
float gety(){return y;}
private:
float x; //x坐标
float y; //y坐标
};
class bianchang1
{
public:
bianchang1(dian xd1,dian xd2);
double getbc1(void){return bc1;}
private:
dian d1,d2;
double bc1;
};
bianchang1::bianchang1(dian xd1,dian xd2):d1(xd1),d2(xd2)
{
double x1=double(d1.getx()-d2.getx());
double y1=double(d1.gety()-d2.gety());
bc1=sqrt(x1*x1+y1*y1);
}
class bianchang2
{
public:
bianchang2(dian xd1,dian xd3);
double getbc2(void){return bc2;}
private:
dian d1,d3;
double bc2;
};
bianchang2::bianchang2(dian xd1,dian xd3):d1(xd1),d3(xd3)
{
double x2=double(d1.getx()-d3.getx());
double y2=double(d1.gety()-d3.gety());
bc2=sqrt(x2*x2+y2*y2);
}
class bianchang3
{
public:
bianchang3(dian xd2,dian xd3);
double getbc3(void){return bc3;}
private:
dian d2,d3;
double bc3;
};
bianchang3::bianchang3(dian xd2,dian xd3):d2(xd2),d3(xd3)
{
double x3=double(d2.getx()-d3.getx());
double y3=double(d2.gety()-d3.gety());
bc3=sqrt(x3*x3+y3*y3);
}
float pd();
double zhouchang();
double a,b,c;
float jieguo = 0 ;
void main()
{
dian d1(1,3),d2(2,3),d3(0,0);
bianchang1 bc1(d1,d2);a=bc1.getbc1();
bianchang2 bc2(d1,d3);b=bc2.getbc2();
bianchang3 bc3(d2,d3);c=bc3.getbc3();
cout<<"a="<<bc1.getbc1()<<endl;
cout<<"b="<<bc2.getbc2()<<endl;
cout<<"c="<<bc3.getbc3()<<endl;
jieguo = pd();
zhouchang();
}
float pd()
{
cout<<"判断是否能构成三角形"<<endl;
if(a+b>c && a+c>b && b+c>a)
{
cout<<"此三点能构成三角形!!!";
return jieguo = 1;
}
else {
cout<<"此三点不能构成三角形."<<endl;
return jieguo = 0;
}
}
double zhouchang()
{
double zc;
if(jieguo == 1 )
{
zc=a+b+c;
cout<<"此三角形的周长为:"<<zc<<endl;
}
return 0;
}
//弄了个这么样的,怎么才能改成是随自己任意输入三点的样式呢?
一万个感谢!!!!
#21
#include"iostream.h"
#include"math.h"
class dian{
public:
dian(float xx=0,float yy=0){
x=xx;y=yy;}
float getx(){return x;}
float gety(){return y;}
private:
float x; //x坐标
float y; //y坐标
};
class bianchang1
{
public:
bianchang1(dian xd1,dian xd2);
double getbc1(void){return bc1;}
private:
dian d1,d2;
double bc1;
};
bianchang1::bianchang1(dian xd1,dian xd2):d1(xd1),d2(xd2)
{
double x1=double(d1.getx()-d2.getx());
double y1=double(d1.gety()-d2.gety());
bc1=sqrt(x1*x1+y1*y1);
}
class bianchang2
{
public:
bianchang2(dian xd1,dian xd3);
double getbc2(void){return bc2;}
private:
dian d1,d3;
double bc2;
};
bianchang2::bianchang2(dian xd1,dian xd3):d1(xd1),d3(xd3)
{
double x2=double(d1.getx()-d3.getx());
double y2=double(d1.gety()-d3.gety());
bc2=sqrt(x2*x2+y2*y2);
}
class bianchang3
{
public:
bianchang3(dian xd2,dian xd3);
double getbc3(void){return bc3;}
private:
dian d2,d3;
double bc3;
};
bianchang3::bianchang3(dian xd2,dian xd3):d2(xd2),d3(xd3)
{
double x3=double(d2.getx()-d3.getx());
double y3=double(d2.gety()-d3.gety());
bc3=sqrt(x3*x3+y3*y3);
}
float pd();
double zhouchang();
double a,b,c;
float jieguo = 0 ;
void main()
{
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
int nPoint1x, nPoint1y, nPoint2x, nPoint2y, nPoint3x, nPoint3y;
cout << "请输入顶点1的x坐标:" << endl;
cin >> nPoint1x;
cout << "请输入顶点1的y坐标:" << endl;
cin >> nPoint1y;
cout << "请输入顶点2的x坐标:" << endl;
cin >> nPoint2x;
cout << "请输入顶点2的y坐标:" << endl;
cin >> nPoint2y;
cout << "请输入顶点3的x坐标:" << endl;
cin >> nPoint3x;
cout << "请输入顶点3的y坐标:" << endl;
cin >> nPoint3y;
dian d1(nPoint1x, nPoint1y),d2(nPoint2x, nPoint2y),d3(nPoint3x, nPoint3y);
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
bianchang1 bc1(d1,d2);a=bc1.getbc1();
bianchang2 bc2(d1,d3);b=bc2.getbc2();
bianchang3 bc3(d2,d3);c=bc3.getbc3();
cout<<"a="<<bc1.getbc1()<<endl;
cout<<"b="<<bc2.getbc2()<<endl;
cout<<"c="<<bc3.getbc3()<<endl;
jieguo = pd();
zhouchang();
}
float pd()
{
cout<<"判断是否能构成三角形"<<endl;
if(a+b>c && a+c>b && b+c>a)
{
cout<<"此三点能构成三角形!!!";
return jieguo = 1;
}
else {
cout<<"此三点不能构成三角形."<<endl;
return jieguo = 0;
}
}
double zhouchang()
{
double zc;
if(jieguo == 1 )
{
zc=a+b+c;
cout<<"此三角形的周长为:"<<zc<<endl;
}
return 0;
}
#include"math.h"
class dian{
public:
dian(float xx=0,float yy=0){
x=xx;y=yy;}
float getx(){return x;}
float gety(){return y;}
private:
float x; //x坐标
float y; //y坐标
};
class bianchang1
{
public:
bianchang1(dian xd1,dian xd2);
double getbc1(void){return bc1;}
private:
dian d1,d2;
double bc1;
};
bianchang1::bianchang1(dian xd1,dian xd2):d1(xd1),d2(xd2)
{
double x1=double(d1.getx()-d2.getx());
double y1=double(d1.gety()-d2.gety());
bc1=sqrt(x1*x1+y1*y1);
}
class bianchang2
{
public:
bianchang2(dian xd1,dian xd3);
double getbc2(void){return bc2;}
private:
dian d1,d3;
double bc2;
};
bianchang2::bianchang2(dian xd1,dian xd3):d1(xd1),d3(xd3)
{
double x2=double(d1.getx()-d3.getx());
double y2=double(d1.gety()-d3.gety());
bc2=sqrt(x2*x2+y2*y2);
}
class bianchang3
{
public:
bianchang3(dian xd2,dian xd3);
double getbc3(void){return bc3;}
private:
dian d2,d3;
double bc3;
};
bianchang3::bianchang3(dian xd2,dian xd3):d2(xd2),d3(xd3)
{
double x3=double(d2.getx()-d3.getx());
double y3=double(d2.gety()-d3.gety());
bc3=sqrt(x3*x3+y3*y3);
}
float pd();
double zhouchang();
double a,b,c;
float jieguo = 0 ;
void main()
{
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
int nPoint1x, nPoint1y, nPoint2x, nPoint2y, nPoint3x, nPoint3y;
cout << "请输入顶点1的x坐标:" << endl;
cin >> nPoint1x;
cout << "请输入顶点1的y坐标:" << endl;
cin >> nPoint1y;
cout << "请输入顶点2的x坐标:" << endl;
cin >> nPoint2x;
cout << "请输入顶点2的y坐标:" << endl;
cin >> nPoint2y;
cout << "请输入顶点3的x坐标:" << endl;
cin >> nPoint3x;
cout << "请输入顶点3的y坐标:" << endl;
cin >> nPoint3y;
dian d1(nPoint1x, nPoint1y),d2(nPoint2x, nPoint2y),d3(nPoint3x, nPoint3y);
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
bianchang1 bc1(d1,d2);a=bc1.getbc1();
bianchang2 bc2(d1,d3);b=bc2.getbc2();
bianchang3 bc3(d2,d3);c=bc3.getbc3();
cout<<"a="<<bc1.getbc1()<<endl;
cout<<"b="<<bc2.getbc2()<<endl;
cout<<"c="<<bc3.getbc3()<<endl;
jieguo = pd();
zhouchang();
}
float pd()
{
cout<<"判断是否能构成三角形"<<endl;
if(a+b>c && a+c>b && b+c>a)
{
cout<<"此三点能构成三角形!!!";
return jieguo = 1;
}
else {
cout<<"此三点不能构成三角形."<<endl;
return jieguo = 0;
}
}
double zhouchang()
{
double zc;
if(jieguo == 1 )
{
zc=a+b+c;
cout<<"此三角形的周长为:"<<zc<<endl;
}
return 0;
}
#22
现在好了,没有用struct.虽然花了很多时间,但会了,学到了不少,感谢csdn,感谢边城狂人
感谢pbdwadr,感谢Jim_King_2000() ,一起努力,不断成长!
感谢pbdwadr,感谢Jim_King_2000() ,一起努力,不断成长!
#1
什么叫通过类求解?
是不是编写一个三角形的类?
已知三点直接计算不是可以得出周长了么?
是不是编写一个三角形的类?
已知三点直接计算不是可以得出周长了么?
#2
是啊,编写一个三角形的类然后就求周长啊!!!救救我阿!!!!
#3
差劲!
#4
差劲!!!
#5
搂主,我想这个问题应该很大程度上是一个平面几何的问题。如果你在几何的角度能够解决问题,我想问题就解决了。
我这样子分析,三角形由三个不在同一直线上点构成,如此可以抽象出你的三角形类的基本成员数据包含三个点。计算三个点的任意两点之间的距离,三个距离的和即为所求的周长。
这是我的想法,也许还有更简单的想法,你去思考吧。
我这样子分析,三角形由三个不在同一直线上点构成,如此可以抽象出你的三角形类的基本成员数据包含三个点。计算三个点的任意两点之间的距离,三个距离的和即为所求的周长。
这是我的想法,也许还有更简单的想法,你去思考吧。
#6
#include <iostream>
#include <math.h>
using namespace std;
class Triangle {
public:
struct Coor {
int x;
int y;
Coor() :
x(0), y(0) {
}
Coor(int x, int y) :
x(x), y(y) {
}
};
Triangle(const Coor& d1, const Coor& d2, const Coor& d3) {
this->d1 = d1;
this->d2 = d2;
this->d3 = d3;
}
double GetZhouChang() {
return GetLength(d1, d2) + GetLength(d2, d3) + GetLength(d3, d1);
}
private:
double GetLength(const Coor& d1, const Coor& d2) {
return pow(pow(abs(d1.x - d2.x), 2) + pow(abs(d1.y - d2.y), 2), 0.5);
}
Coor d1;
Coor d2;
Coor d3;
};
int main(int argc, char* argv[]) {
Triangle triangle(Triangle::Coor(1, 2), Triangle::Coor(3, 5), Triangle::Coor(2, 4));
cout << triangle.GetZhouChang() << endl;
}
#include <math.h>
using namespace std;
class Triangle {
public:
struct Coor {
int x;
int y;
Coor() :
x(0), y(0) {
}
Coor(int x, int y) :
x(x), y(y) {
}
};
Triangle(const Coor& d1, const Coor& d2, const Coor& d3) {
this->d1 = d1;
this->d2 = d2;
this->d3 = d3;
}
double GetZhouChang() {
return GetLength(d1, d2) + GetLength(d2, d3) + GetLength(d3, d1);
}
private:
double GetLength(const Coor& d1, const Coor& d2) {
return pow(pow(abs(d1.x - d2.x), 2) + pow(abs(d1.y - d2.y), 2), 0.5);
}
Coor d1;
Coor d2;
Coor d3;
};
int main(int argc, char* argv[]) {
Triangle triangle(Triangle::Coor(1, 2), Triangle::Coor(3, 5), Triangle::Coor(2, 4));
cout << triangle.GetZhouChang() << endl;
}
#7
高深,还有没有更简便的??
#8
又把老师布置的作业朝这里发,管理员封了他吧。
#9
这么简单得还高深?一些基本得东西不想学,就想得到一个傻瓜级得答案是不现实得。
#10
哦哦,我只是想交流交流啦,虽是老师的作业,老师的作业就不可以讨论了吗???
我还要更易读的啊!!!!
我还要更易读的啊!!!!
#11
因为我用到了类的组合,但无法实现,应该怎么解决问题啊!!!???!!!
#12
快来人啊!!!
#13
你这哪是交流啊?这个是非常简单的东西,你只希望从别人那得到,而不是交流
人家已经告诉你怎么做了,只是你看不懂。我想比jamesfancy(边城狂人) 的答案更简单的方法是没有的。还能怎么简单呢?你要是看不懂,再怎么问也没有用
人家已经告诉你怎么做了,只是你看不懂。我想比jamesfancy(边城狂人) 的答案更简单的方法是没有的。还能怎么简单呢?你要是看不懂,再怎么问也没有用
#14
那能够不使用那个struct吗?我就是不想要那个struct.
#15
不要总“就是不想要”,设计程序应该多考虑合理性,你这个就是不想要非常不make sense
#16
晕了,没的救了到处求救还是没结果!!
#17
如果啥都按你想的,你自己写出来不就好了
#18
写一个triangle类,里面包含了三个点(2D或者3D)。在构造函数以及operator=()函数中判断这三个点是否能够成为一个真正的三角形,如果重点或者共线的话,就抛个异常。然后再写一个perimeter函数求出周长即可。有时间的话写一个class template。
#19
学过数学的都知道
#20
#include"iostream.h"
#include"math.h"
class dian{
public:
dian(float xx=0,float yy=0){
x=xx;y=yy;}
float getx(){return x;}
float gety(){return y;}
private:
float x; //x坐标
float y; //y坐标
};
class bianchang1
{
public:
bianchang1(dian xd1,dian xd2);
double getbc1(void){return bc1;}
private:
dian d1,d2;
double bc1;
};
bianchang1::bianchang1(dian xd1,dian xd2):d1(xd1),d2(xd2)
{
double x1=double(d1.getx()-d2.getx());
double y1=double(d1.gety()-d2.gety());
bc1=sqrt(x1*x1+y1*y1);
}
class bianchang2
{
public:
bianchang2(dian xd1,dian xd3);
double getbc2(void){return bc2;}
private:
dian d1,d3;
double bc2;
};
bianchang2::bianchang2(dian xd1,dian xd3):d1(xd1),d3(xd3)
{
double x2=double(d1.getx()-d3.getx());
double y2=double(d1.gety()-d3.gety());
bc2=sqrt(x2*x2+y2*y2);
}
class bianchang3
{
public:
bianchang3(dian xd2,dian xd3);
double getbc3(void){return bc3;}
private:
dian d2,d3;
double bc3;
};
bianchang3::bianchang3(dian xd2,dian xd3):d2(xd2),d3(xd3)
{
double x3=double(d2.getx()-d3.getx());
double y3=double(d2.gety()-d3.gety());
bc3=sqrt(x3*x3+y3*y3);
}
float pd();
double zhouchang();
double a,b,c;
float jieguo = 0 ;
void main()
{
dian d1(1,3),d2(2,3),d3(0,0);
bianchang1 bc1(d1,d2);a=bc1.getbc1();
bianchang2 bc2(d1,d3);b=bc2.getbc2();
bianchang3 bc3(d2,d3);c=bc3.getbc3();
cout<<"a="<<bc1.getbc1()<<endl;
cout<<"b="<<bc2.getbc2()<<endl;
cout<<"c="<<bc3.getbc3()<<endl;
jieguo = pd();
zhouchang();
}
float pd()
{
cout<<"判断是否能构成三角形"<<endl;
if(a+b>c && a+c>b && b+c>a)
{
cout<<"此三点能构成三角形!!!";
return jieguo = 1;
}
else {
cout<<"此三点不能构成三角形."<<endl;
return jieguo = 0;
}
}
double zhouchang()
{
double zc;
if(jieguo == 1 )
{
zc=a+b+c;
cout<<"此三角形的周长为:"<<zc<<endl;
}
return 0;
}
//弄了个这么样的,怎么才能改成是随自己任意输入三点的样式呢?
一万个感谢!!!!
#include"math.h"
class dian{
public:
dian(float xx=0,float yy=0){
x=xx;y=yy;}
float getx(){return x;}
float gety(){return y;}
private:
float x; //x坐标
float y; //y坐标
};
class bianchang1
{
public:
bianchang1(dian xd1,dian xd2);
double getbc1(void){return bc1;}
private:
dian d1,d2;
double bc1;
};
bianchang1::bianchang1(dian xd1,dian xd2):d1(xd1),d2(xd2)
{
double x1=double(d1.getx()-d2.getx());
double y1=double(d1.gety()-d2.gety());
bc1=sqrt(x1*x1+y1*y1);
}
class bianchang2
{
public:
bianchang2(dian xd1,dian xd3);
double getbc2(void){return bc2;}
private:
dian d1,d3;
double bc2;
};
bianchang2::bianchang2(dian xd1,dian xd3):d1(xd1),d3(xd3)
{
double x2=double(d1.getx()-d3.getx());
double y2=double(d1.gety()-d3.gety());
bc2=sqrt(x2*x2+y2*y2);
}
class bianchang3
{
public:
bianchang3(dian xd2,dian xd3);
double getbc3(void){return bc3;}
private:
dian d2,d3;
double bc3;
};
bianchang3::bianchang3(dian xd2,dian xd3):d2(xd2),d3(xd3)
{
double x3=double(d2.getx()-d3.getx());
double y3=double(d2.gety()-d3.gety());
bc3=sqrt(x3*x3+y3*y3);
}
float pd();
double zhouchang();
double a,b,c;
float jieguo = 0 ;
void main()
{
dian d1(1,3),d2(2,3),d3(0,0);
bianchang1 bc1(d1,d2);a=bc1.getbc1();
bianchang2 bc2(d1,d3);b=bc2.getbc2();
bianchang3 bc3(d2,d3);c=bc3.getbc3();
cout<<"a="<<bc1.getbc1()<<endl;
cout<<"b="<<bc2.getbc2()<<endl;
cout<<"c="<<bc3.getbc3()<<endl;
jieguo = pd();
zhouchang();
}
float pd()
{
cout<<"判断是否能构成三角形"<<endl;
if(a+b>c && a+c>b && b+c>a)
{
cout<<"此三点能构成三角形!!!";
return jieguo = 1;
}
else {
cout<<"此三点不能构成三角形."<<endl;
return jieguo = 0;
}
}
double zhouchang()
{
double zc;
if(jieguo == 1 )
{
zc=a+b+c;
cout<<"此三角形的周长为:"<<zc<<endl;
}
return 0;
}
//弄了个这么样的,怎么才能改成是随自己任意输入三点的样式呢?
一万个感谢!!!!
#21
#include"iostream.h"
#include"math.h"
class dian{
public:
dian(float xx=0,float yy=0){
x=xx;y=yy;}
float getx(){return x;}
float gety(){return y;}
private:
float x; //x坐标
float y; //y坐标
};
class bianchang1
{
public:
bianchang1(dian xd1,dian xd2);
double getbc1(void){return bc1;}
private:
dian d1,d2;
double bc1;
};
bianchang1::bianchang1(dian xd1,dian xd2):d1(xd1),d2(xd2)
{
double x1=double(d1.getx()-d2.getx());
double y1=double(d1.gety()-d2.gety());
bc1=sqrt(x1*x1+y1*y1);
}
class bianchang2
{
public:
bianchang2(dian xd1,dian xd3);
double getbc2(void){return bc2;}
private:
dian d1,d3;
double bc2;
};
bianchang2::bianchang2(dian xd1,dian xd3):d1(xd1),d3(xd3)
{
double x2=double(d1.getx()-d3.getx());
double y2=double(d1.gety()-d3.gety());
bc2=sqrt(x2*x2+y2*y2);
}
class bianchang3
{
public:
bianchang3(dian xd2,dian xd3);
double getbc3(void){return bc3;}
private:
dian d2,d3;
double bc3;
};
bianchang3::bianchang3(dian xd2,dian xd3):d2(xd2),d3(xd3)
{
double x3=double(d2.getx()-d3.getx());
double y3=double(d2.gety()-d3.gety());
bc3=sqrt(x3*x3+y3*y3);
}
float pd();
double zhouchang();
double a,b,c;
float jieguo = 0 ;
void main()
{
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
int nPoint1x, nPoint1y, nPoint2x, nPoint2y, nPoint3x, nPoint3y;
cout << "请输入顶点1的x坐标:" << endl;
cin >> nPoint1x;
cout << "请输入顶点1的y坐标:" << endl;
cin >> nPoint1y;
cout << "请输入顶点2的x坐标:" << endl;
cin >> nPoint2x;
cout << "请输入顶点2的y坐标:" << endl;
cin >> nPoint2y;
cout << "请输入顶点3的x坐标:" << endl;
cin >> nPoint3x;
cout << "请输入顶点3的y坐标:" << endl;
cin >> nPoint3y;
dian d1(nPoint1x, nPoint1y),d2(nPoint2x, nPoint2y),d3(nPoint3x, nPoint3y);
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
bianchang1 bc1(d1,d2);a=bc1.getbc1();
bianchang2 bc2(d1,d3);b=bc2.getbc2();
bianchang3 bc3(d2,d3);c=bc3.getbc3();
cout<<"a="<<bc1.getbc1()<<endl;
cout<<"b="<<bc2.getbc2()<<endl;
cout<<"c="<<bc3.getbc3()<<endl;
jieguo = pd();
zhouchang();
}
float pd()
{
cout<<"判断是否能构成三角形"<<endl;
if(a+b>c && a+c>b && b+c>a)
{
cout<<"此三点能构成三角形!!!";
return jieguo = 1;
}
else {
cout<<"此三点不能构成三角形."<<endl;
return jieguo = 0;
}
}
double zhouchang()
{
double zc;
if(jieguo == 1 )
{
zc=a+b+c;
cout<<"此三角形的周长为:"<<zc<<endl;
}
return 0;
}
#include"math.h"
class dian{
public:
dian(float xx=0,float yy=0){
x=xx;y=yy;}
float getx(){return x;}
float gety(){return y;}
private:
float x; //x坐标
float y; //y坐标
};
class bianchang1
{
public:
bianchang1(dian xd1,dian xd2);
double getbc1(void){return bc1;}
private:
dian d1,d2;
double bc1;
};
bianchang1::bianchang1(dian xd1,dian xd2):d1(xd1),d2(xd2)
{
double x1=double(d1.getx()-d2.getx());
double y1=double(d1.gety()-d2.gety());
bc1=sqrt(x1*x1+y1*y1);
}
class bianchang2
{
public:
bianchang2(dian xd1,dian xd3);
double getbc2(void){return bc2;}
private:
dian d1,d3;
double bc2;
};
bianchang2::bianchang2(dian xd1,dian xd3):d1(xd1),d3(xd3)
{
double x2=double(d1.getx()-d3.getx());
double y2=double(d1.gety()-d3.gety());
bc2=sqrt(x2*x2+y2*y2);
}
class bianchang3
{
public:
bianchang3(dian xd2,dian xd3);
double getbc3(void){return bc3;}
private:
dian d2,d3;
double bc3;
};
bianchang3::bianchang3(dian xd2,dian xd3):d2(xd2),d3(xd3)
{
double x3=double(d2.getx()-d3.getx());
double y3=double(d2.gety()-d3.gety());
bc3=sqrt(x3*x3+y3*y3);
}
float pd();
double zhouchang();
double a,b,c;
float jieguo = 0 ;
void main()
{
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
int nPoint1x, nPoint1y, nPoint2x, nPoint2y, nPoint3x, nPoint3y;
cout << "请输入顶点1的x坐标:" << endl;
cin >> nPoint1x;
cout << "请输入顶点1的y坐标:" << endl;
cin >> nPoint1y;
cout << "请输入顶点2的x坐标:" << endl;
cin >> nPoint2x;
cout << "请输入顶点2的y坐标:" << endl;
cin >> nPoint2y;
cout << "请输入顶点3的x坐标:" << endl;
cin >> nPoint3x;
cout << "请输入顶点3的y坐标:" << endl;
cin >> nPoint3y;
dian d1(nPoint1x, nPoint1y),d2(nPoint2x, nPoint2y),d3(nPoint3x, nPoint3y);
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
bianchang1 bc1(d1,d2);a=bc1.getbc1();
bianchang2 bc2(d1,d3);b=bc2.getbc2();
bianchang3 bc3(d2,d3);c=bc3.getbc3();
cout<<"a="<<bc1.getbc1()<<endl;
cout<<"b="<<bc2.getbc2()<<endl;
cout<<"c="<<bc3.getbc3()<<endl;
jieguo = pd();
zhouchang();
}
float pd()
{
cout<<"判断是否能构成三角形"<<endl;
if(a+b>c && a+c>b && b+c>a)
{
cout<<"此三点能构成三角形!!!";
return jieguo = 1;
}
else {
cout<<"此三点不能构成三角形."<<endl;
return jieguo = 0;
}
}
double zhouchang()
{
double zc;
if(jieguo == 1 )
{
zc=a+b+c;
cout<<"此三角形的周长为:"<<zc<<endl;
}
return 0;
}
#22
现在好了,没有用struct.虽然花了很多时间,但会了,学到了不少,感谢csdn,感谢边城狂人
感谢pbdwadr,感谢Jim_King_2000() ,一起努力,不断成长!
感谢pbdwadr,感谢Jim_King_2000() ,一起努力,不断成长!