首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

初学者问 这程序语法错哪了,最好不改主函数

2012-04-21 
菜鸟问 这程序语法哪里错了,最好不改主函数#includeiostream#includeiomanipusing namespace stdchar

菜鸟问 这程序语法哪里错了,最好不改主函数
#include"iostream"
#include"iomanip"

using namespace std;
char c1=',';

class Point
{

  public:
  static int count1,count2;
  friend void show();
  friend void ShowPoint(Point &p, double x, double y);
  Point (double a11,double c11);
  Point(double a11);
  ~Point();
  Point (Point &w);
  Point ();
  Point(const Point&);
  void show()
  {
  cout<<std::setprecision(16)<<"Point["<<i1<<"] : "<<'('<<x1<<c1<<' '<<y1<<')'<<'\n';

  }
  void show()const
  {
  cout<<std::setprecision(16)<<"Point["<<i1<<"] : "<<'('<<x1<<c1<<' '<<y1<<')'<<'\n';

  }
  double x1,y1,aa1,cc1; int i1;
  static void showCounter()
  {
  std::cout<<"Current"<<' '<<":"<<' '<<count1<<' '<< "points.\n";

  }
  double x(){return x1;}
  double x()const{return x1;}
  double x(double m){x1=m; return x1;}
  double y(double n){y1=n; return y1;}
  double y(){return y1;}
  double y()const{return y1;}
  double getX(){return x1;}
  double getY(){return y1;}
  double setX(double x){x1=x; return x1;}
  double setY(double y){y1=y; return y1;}
  Point& setPoint(double a,double b);
  double setPoint(double a)
  {
  x1=a;y1=a;
  return x1;
  }
  static void showSumOfPoint()
  {
  std::cout<<"In total : "<<count2<< " points.\n";

  }
  Point copy(Point p)
  {
  x1=p.x1;
  y1=p.y1;
  return *this;
  }
  Point inverse()
  {
  Point::x1=Point::x1+Point::y1;
  Point::y1=Point::x1-Point::y1;
  Point::x1=Point::x1-Point::y1;
  return *this;
  }
  Point inverse(Point p)
  {
  p.x1=p.x1+p.y1;
  p.y1=p.x1-p.y1;
  p.x1=p.x1-p.y1;
  return *this;
  }
  bool isEqual(Point p)
  {
  if (p.x1==Point::x1&&p.y1==Point::y1)
  return true;
  else
  return false;
  }
  bool isEqual(Point p)const
  {
  if (p.x1==Point::x1&&p.y1==Point::y1)
  return true;
  else
  return false;
  }



};
  Point::Point(const Point&p):x1(p.x1),y1:(p.y1)
  {

  }
  Point& Point:: setPoint(double a,double b)
  {
  x1=a,y1=b;
  }
  Point::Point (double a11,double c11):x1(a11),y1(c11)
  {
  count2++;


  }

  Point::Point ():x1(0),y1(0){ count2++;}

  Point::~Point(){}

  Point::Point(Point &w): x1(w.x1),y1(w.y1)
  {
  count2++;
  }
  Point::Point(double a11):x1(a11),y1(a11)
  {
  count2++;
  }
int Point::count1;
int Point::count2;
void ShowPoint(Point p)
  {
  cout<<std::setprecision(16)<<"Point : ("<<p.x()<<", "<<p.y()<<")"<<endl;
  }
void ShowPoint(double x, double y)
  {
  Point p(x, y);
  cout<<std::setprecision(16)<<"Point : ("<<p.x()<<", "<<p.y()<<")"<<endl;
  }

void ShowPoint(Point &p, double x, double y)
  {
  cout<<std::setprecision(16)<<"Point : ("<<p.x(x)<<", "<<p.x(y)<<")"<<endl;
  }














int main()
{
  int l(0);
  char c;
  double a, b;
  Point p, q, pt[60];
  while(std::cin>>a>>c>>b)
  {
  if(a == b)
  p.copy(pt[l].setPoint(a, b));
  if(a > b)
  p.copy(pt[l].setPoint(a, b).inverse());
  if(a < b)
  p.inverse(pt[l].setPoint(a, b));
  if(a < 0)
  q.copy(p).inverse();
  if(b < 0)
  q.inverse(p).copy(pt[l]);
  pt[l++].show();
  p.show();
  }
  q.show();
  cout<<"==========gorgeous separator=========="<<endl;
  double x(0), y(0);
  for(int i = 0; i < l; i++)
  x += pt[i].x(), y -= pt[i].y();
  pt[l].x(y), pt[l].y(x);
  q.copy(pt[l]).show();
  for(int i = 0; i <= l; i++)
  pt[i].show();
  cout<<"==========gorgeous separator=========="<<endl;
  const Point const_point(3, 3);
  const_point.show();
  for(int i = 0; i <= l; i++)
  {
  if(const_point.isEqual(pt[i]))
  {
  ShowPoint(const_point);
  ShowPoint(const_point.x(), const_point.y());
  ShowPoint(Point(const_point.x(), const_point.y()));
  }
  }
  const_point.showSumOfPoint();
}


[解决办法]
相应地方改为:

C/C++ code
Point::Point(const Point&p):x1(p.x1),y1(p.y1){}Point& Point:: setPoint(double a,double b){    x1=a,y1=b;    return *this;   //这个函数其实可以不用换回的,一定要返回的话就返回这个吧}
[解决办法]
语法错误
C/C++ code
 Point::Point(const Point&p):x1(p.x1),y1:(p.y1) //多了个:  {  } 

热点排行