C++,怎么用同一个类的对象对另一个类的对象进行初始化。
#include<iostream>#include<cmath>usingnamespacestd;classpoint{intx,y;public:point(int...
#include<iostream>
#include<cmath>
using namespace std;
class point{
int x,y;
public:
point(int xx=0,int yy=0){
x=xx;
y=yy;
}
point(point &p){
x=p.x;
y=p.y;
}
void SetPoint(int xx,int yy){
x=xx;
y=yy;
}
void Getxy(int &xx,int &yy){
xx=x;
yy=x;
}
};
class Triangle{
point p1,p2,p3;
public:
Triangle(int x1=1,int x2=2,int x3=3,int y1=1,int y2=2,int y3=3){p1.SetPoint(x1,y1);
p2.SetPoint(x2,y2);
p3.SetPoint(x3,y3);
}
Triangle(point &p11,point &p22,point &p33){ p1.x=p11.x; //这里,用一个对象初始化另一个对象,是不是必须再在point里加语句?//
p1.y=y11.y;
p2.x=p22.x;
p2.y=p22.y;
p3.x=p33.x;
p3.y=p33.y;
}
void SetPoint(int xx,int yy){
p1.x=xx;
p1.y=yy;
}
void SetPoint(point &p){
p2.x=p.x;
p2.y=p.y;
}
void Getxy(int *x1,int *y1){
*x1=p1.x;
*y1=p1.y;
}
void Getxy(int &xx,int &yy){
xx=p2.x
yy=p2.y
}
void Getxy(point &p){
p.x=p3.x;
p.y=p3.y;
}
void zou(double &a,double &b,point &p,int *x1,int *y1,int &xx,int &yy){
a=(sqrt((*x1-xx)*(*x1-xx)+(*y-yy)*(*y-yy))+sqrt((*x1-p.x)*(*x1-p.x)+(*y-p.y)*(*y-p.y))+sqrt((xx-p.x)*(xx-p.x)+(yy-p.y)*(yy-p.y)))/2;
b=sqrt(a*(a-sqrt((*x1-xx)*(*x1-xx)+(*y-yy)*(*y-yy)))*(a-sqrt((*x1-p.x)*(*x1-p.x)+(*y-p.y)*(*y-p.y)))*(a-sqrt((xx-p.x)*(xx-p.x)+(yy-p.y)*(yy-p.y))));
}
void OutPut(double &a,double &b) {cout<<"顶点的坐标分别为("<<*x1<<","<<*y1<<"),("<<xx<<","<<yy<<"),("<<p.x<<","<<*p.y<<"),周长为"<<2*a<<"面积为"<<b<<endl;
}
};
void main(){
int xx,yy,x1,y1;
double a,b;
point p;
Triangle t;
cin>>xx>>yy>>p.x>>p.y;
t.SetPoint(&,yy);
t.Getxy(&x1,&y1);
t.Getxy(xx,yy);
t.Getxy(p);
t.zou(a,b,p,&x1,&y1,int &xx,int &yy);
t.OutPut(a,b);
} 展开
#include<cmath>
using namespace std;
class point{
int x,y;
public:
point(int xx=0,int yy=0){
x=xx;
y=yy;
}
point(point &p){
x=p.x;
y=p.y;
}
void SetPoint(int xx,int yy){
x=xx;
y=yy;
}
void Getxy(int &xx,int &yy){
xx=x;
yy=x;
}
};
class Triangle{
point p1,p2,p3;
public:
Triangle(int x1=1,int x2=2,int x3=3,int y1=1,int y2=2,int y3=3){p1.SetPoint(x1,y1);
p2.SetPoint(x2,y2);
p3.SetPoint(x3,y3);
}
Triangle(point &p11,point &p22,point &p33){ p1.x=p11.x; //这里,用一个对象初始化另一个对象,是不是必须再在point里加语句?//
p1.y=y11.y;
p2.x=p22.x;
p2.y=p22.y;
p3.x=p33.x;
p3.y=p33.y;
}
void SetPoint(int xx,int yy){
p1.x=xx;
p1.y=yy;
}
void SetPoint(point &p){
p2.x=p.x;
p2.y=p.y;
}
void Getxy(int *x1,int *y1){
*x1=p1.x;
*y1=p1.y;
}
void Getxy(int &xx,int &yy){
xx=p2.x
yy=p2.y
}
void Getxy(point &p){
p.x=p3.x;
p.y=p3.y;
}
void zou(double &a,double &b,point &p,int *x1,int *y1,int &xx,int &yy){
a=(sqrt((*x1-xx)*(*x1-xx)+(*y-yy)*(*y-yy))+sqrt((*x1-p.x)*(*x1-p.x)+(*y-p.y)*(*y-p.y))+sqrt((xx-p.x)*(xx-p.x)+(yy-p.y)*(yy-p.y)))/2;
b=sqrt(a*(a-sqrt((*x1-xx)*(*x1-xx)+(*y-yy)*(*y-yy)))*(a-sqrt((*x1-p.x)*(*x1-p.x)+(*y-p.y)*(*y-p.y)))*(a-sqrt((xx-p.x)*(xx-p.x)+(yy-p.y)*(yy-p.y))));
}
void OutPut(double &a,double &b) {cout<<"顶点的坐标分别为("<<*x1<<","<<*y1<<"),("<<xx<<","<<yy<<"),("<<p.x<<","<<*p.y<<"),周长为"<<2*a<<"面积为"<<b<<endl;
}
};
void main(){
int xx,yy,x1,y1;
double a,b;
point p;
Triangle t;
cin>>xx>>yy>>p.x>>p.y;
t.SetPoint(&,yy);
t.Getxy(&x1,&y1);
t.Getxy(xx,yy);
t.Getxy(p);
t.zou(a,b,p,&x1,&y1,int &xx,int &yy);
t.OutPut(a,b);
} 展开
若以下回答无法解决问题,邀请你更新回答
1个回答
2015-04-08
展开全部
就只是语法问题而已
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询