fork(1) download
  1. #include <cmath>
  2. #include <iostream>
  3. using namespace std;
  4. class Point{
  5. private://Данные -члены(закрытые)
  6. int x,y;
  7. public: //функции -члены
  8. void set(int new_x,int new_y);
  9. int get_x();
  10. int get_y();
  11. double Point operator%(pt);
  12. };
  13. double Point::operator%(Point pt){
  14. int d1=pt.x-x;
  15. int d2=pt.y-y;
  16. return sqrt((double)(d1*d1+d2*d2));}
  17. int main(){
  18. Point pt1,pt2;
  19. pt1.set(10,20);
  20. cout<<"pt1 is"<<pt1.get_x();
  21. cout<<","<<pt1.get_y()<<endl;
  22. pt2.set(-5,-25);
  23. cout<<"pt2 is"<<pt2.get_x();
  24. cout<<","<<pt2.get_y()<<endl;
  25. Point pt1(20,20);
  26. Point pt2(24,23);
  27. cout<<"расстояние "<<pt1%pt2;
  28. return 0;
  29. }
  30. void Point::set(int new_x,int new_y){
  31. if (new_x<0)
  32. new_x*=-1;
  33. if(new_y<0)
  34. new_y*=-1;
  35. x=new_x;
  36. y=new_y;
  37. }
  38. int Point::get_x(){
  39. return x;
  40. }
  41. int Point::get_y(){
  42. return y;
  43. }
  44.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:11:9: error: expected ‘;’ at end of member declaration
  double Point operator%(pt);
         ^
prog.cpp:11:25: error: ‘pt’ has not been declared
  double Point operator%(pt);
                         ^
prog.cpp:11:27: error: ISO C++ forbids declaration of ‘operator%’ with no type [-fpermissive]
  double Point operator%(pt);
                           ^
prog.cpp:13:25: error: declaration of ‘operator%’ as non-function
 double Point::operator%(Point pt){
                         ^
prog.cpp:13:31: error: expected primary-expression before ‘pt’
 double Point::operator%(Point pt){
                               ^
prog.cpp: In function ‘int main()’:
prog.cpp:25:11: error: redeclaration of ‘Point pt1’
  Point pt1(20,20);
           ^
prog.cpp:18:8: error: ‘Point pt1’ previously declared here
  Point pt1,pt2;
        ^
prog.cpp:26:11: error: redeclaration of ‘Point pt2’
  Point pt2(24,23);
           ^
prog.cpp:18:12: error: ‘Point pt2’ previously declared here
  Point pt1,pt2;
            ^
prog.cpp:27:36: error: no match for ‘operator%’ (operand types are ‘Point’ and ‘Point’)
  cout<<"расстояние "<<pt1%pt2;
                                    ^
prog.cpp:27:36: note: candidate is:
prog.cpp:11:15: note: int Point::operator%(int)
  double Point operator%(pt);
               ^
prog.cpp:11:15: note:   no known conversion for argument 1 from ‘Point’ to ‘int’
stdout
Standard output is empty