当前位置:编程学习 > C/C++ >>

C++编程老是错错错!!!!

补充:里面的一些函数我写的不对的可以帮忙改改特别是copare函数,重载-,和重载*,好像也出了问题,

追问:#include<iostream.h>
//using namespace std;
class Point
{
public:
 Point(){}
 Point(float x,float y,float z) :a(x),b(y),c(z){}
 Point(const Point &){}
 ~Point(){}
 float negate();
 float norm();
 void print();
 Point operator +(Point &t1);
 Point operator -(Point &t1);
 Point operator *(Point &t1);
  friend istream & operator >>(istream  &input,Point &t)
{
 cout<<"input the point:";
 input>>t.a >>t.b >>t.c ;
 return input;
}
 friend bool operator ==(Point &t1,Point &t2)

 if(t1.a==t2.a&&t1.b==t2.b&&t1.c==t2.c)
  cout<<"正确1";
 return true;
}
    friend bool operator !=(Point t1,Point t2)

 if(t1.a!=t2.a||t1.b!=t2.b||t1.c!=t2.c)
  cout<<"正确2";
 return true;
}
 void compare(Point &t1,Point &t2)
 {
  if(operator==(t1,t2))
  {t1.print();cout<<"==";t2.print();}
     if(operator!=(t1,t2))
  {t1.print();cout<<"!=";t2.print();}
 }
  
private:
 float a;
 float b;
 float c;
};

float Point::negate()
{
 float j,k,l;
 j=-a;k=-b;l=-c;
 cout<<"the negate point is:"<<"("<<j<<","<<k<<","<<l<<")"<<endl;
 return(0);
}
float Point::norm()
{
 float n;
 n=a*a+b*b+c*c;
 return n;
}

void Point:: print()
{
 cout<<"the normal point is: "<<"("<<a<<","<<b<<","<<c<<")"<<endl;
}


Point Point::operator +(Point &t1)
{
 Point t;
 t.a=t1.a+a;
 t.b=t1.b+b;
 t.c=t1.c+c;
cout<<"("<<t.a <<","<<t.b<<","<<t.c<<")"<<endl;
return t;
}

Point Point:: operator -(Point &t1)
{
 Point t;
 t.a=t1.a-a;
 t.b=t1.b-b;
 t.b=t1.c-c;
cout<<"("<<t.a <<","<<t.b<<","<<t.c<<")"<<endl;
return t;
}
 Point Point::operator *(Point &t1)
{
 Point t;
 t.a=t1.a*a;
 t.b=t1.b*b;
 t.b=t1.c*c;
cout<<t.a+t.b+t.c<<endl;
return t;
}
 
int main()
{
 Point t1,t2,t3;
 cin>>t1>>t2;
 t1.print();
 t2.print();
 t1.negate();
 t2.negate();
 cout<<"t1+t2=";
 t3=t1+t2;
 cout<<"t1-t2=";
    t3=t1-t2;
 cout<<"t1*t2=";
 t3=t1*t2;
 compare(t1,t2);
    cout<<"the norm of the point is:"<<t1.norm()<<endl;
 cout<<"the norm of the point is:"<<t2.norm()<<endl;
 return 0;
}
帮我调出来加分,

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,