Language: C++

Last login: Mon May 15 19:53:01 on ttys000
[2444924881@pc038029m ~]$ cd workspace/practicalprogramming/0515/
[2444924881@pc038029m 0515]$ echo 10 | ./a.out > res.dat 
^C
[2444924881@pc038029m 0515]$ echo 4 | ./a.out > res.dat 
[2444924881@pc038029m 0515]$ gnuplot plot.plt 
[2444924881@pc038029m 0515]$ echo 7 | ./a.out > res.dat 
[2444924881@pc038029m 0515]$ gnuplot plot.plt 
[2444924881@pc038029m 0515]$ vim 
._res.png           basem.cc            res.dat
a.out               koch_curve.cc       res.png
ans.dat             min_max_and_sum.cc  
base2.cc            plot.plt            
[2444924881@pc038029m 0515]$ vim koch_curve.cc 


































[2444924881@pc038029m 0515]$ xco
xcode-select  xcodebuild    xcompmgr      xconsole      
[2444924881@pc038029m 0515]$ vim koch_curve.cc 
[2444924881@pc038029m 0515]$ vim koch_curve.cc 







  point operator-(const point &p)const{
    return point(x-p.x,y-p.y);
  }

  point operator*(const double k)const{
    return point(k*x,k*y);
  }

  double norm()const{
    return sqrt(x*x+y*y);
  }

  double dist(const point &p)const{
    return (*this-p).norm();
  }

  void show()const{ cout << setprecision(6) << x << " " << y << endl; }
};

void print_kochcurve(const point &p1,const point &p2,int n);

int main(){
  int n;
  cin >> n;
  point p1(0,0),p2(100,0);
  p1.show();
  print_kochcurve(p1,p2,n);

  return 0;
}

void print_kochcurve(const point &p1,const point &p2,int n){
  if(n==0){
    p2.show();
    return;
  }

  point s,t,u;

  s = (p1*2.0 + p2)*(1./3);
  t = (p1 + p2*2.0)*(1./3);

  u = (p1 + p2)*(1./2);
  double len = p1.dist(s)*sqrt(3)/2;
  point v = p2-p1;
  point tmp(-v.get_y(),v.get_x());
  tmp = tmp*(1./tmp.norm());

  u = u + tmp*len;

  print_kochcurve(p1,s,n-1);
  print_kochcurve(s,u,n-1);
  print_kochcurve(u,t,n-1);
  print_kochcurve(t,p2,n-1);

}

Compiler output:
a.cc:2:12: error: stray '@' in program
    2 | [2444924881@pc038029m ~]$ cd workspace/practicalprogramming/0515/
      |            ^
a.cc:3:12: error: stray '@' in program
    3 | [2444924881@pc038029m 0515]$ echo 10 | ./a.out > res.dat
      |            ^
a.cc:5:12: error: stray '@' in program
    5 | [2444924881@pc038029m 0515]$ echo 4 | ./a.out > res.dat
      |            ^
a.cc:6:12: error: stray '@' in program
    6 | [2444924881@pc038029m 0515]$ gnuplot plot.plt
      |            ^
a.cc:7:12: error: stray '@' in program
    7 | [2444924881@pc038029m 0515]$ echo 7 | ./a.out > res.dat
      |            ^
a.cc:8:12: error: stray '@' in program
    8 | [2444924881@pc038029m 0515]$ gnuplot plot.plt
      |            ^
a.cc:9:12: error: stray '@' in program
    9 | [2444924881@pc038029m 0515]$ vim
      |            ^
a.cc:14:12: error: stray '@' in program
   14 | [2444924881@pc038029m 0515]$ vim koch_curve.cc
      |            ^
a.cc:49:12: error: stray '@' in program
   49 | [2444924881@pc038029m 0515]$ xco
      |            ^
a.cc:51:12: error: stray '@' in program
   51 | [2444924881@pc038029m 0515]$ vim koch_curve.cc
      |            ^
a.cc:52:12: error: stray '@' in program
   52 | [2444924881@pc038029m 0515]$ vim koch_curve.cc
      |            ^
a.cc:1:1: error: 'Last' does not name a type
    1 | Last login: Mon May 15 19:53:01 on ttys000
      | ^~~~
a.cc:64:3: error: 'point' does not name a type; did you mean 'int'?
   64 |   point operator*(const double k)const{
      |   ^~~~~
      |   int
a.cc:68:16: error: non-member function 'double norm()' cannot have cv-qualifier
   68 |   double norm()const{
      |                ^~~~~
a.cc: In function 'double norm()':
a.cc:69:17: error: 'x' was not declared in this scope
   69 |     return sqrt(x*x+y*y);
      |                 ^
a.cc:69:21: error: 'y' was not declared in this scope
   69 |     return sqrt(x*x+y*y);
      |                     ^
a.cc:69:12: error: 'sqrt' was not declared in this scope
   69 |     return sqrt(x*x+y*y);
      |            ^~~~
a.cc: At global scope:
a.cc:72:21: error: 'point' does not name a type; did you mean 'int'?
   72 |   double dist(const point &p)const{
      |                     ^~~~~
      |                     int
a.cc:72:30: error: non-member function 'double dist(const int&)' cannot have cv-qualifier
   72 |   double dist(const point &p)const{
      |                              ^~~~~
a.cc: In function 'double dist(const int&)':
a.cc:73:14: error: invalid use of 'this' in non-member function
   73 |     return (*this-p).norm();
      |              ^~~~
a.cc: At global scope:
a.cc:76:14: error: non-member function 'void show()' cannot have cv-qualifier
   76 |   void show()const{ cout << setprecision(6) << x << " " << y << endl; }
      |              ^~~~~
a.cc: In function 'void show()':
a.cc:76:21: error: 'cout' was not declared in this scope
   76 |   void show()const{ cout << setprecision(6) << x << " " << y << endl; }
      |                     ^~~~
a.cc:76:29: error: 'setprecision' was not declared in this scope
   76 |   void show()const{ cout << setprecision(6) << x << " " << y << endl; }
      |                             ^~~~~~~~~~~~
a.cc:76:48: error: 'x' was not declared in this scope
   76 |   void show()const{ cout << setprecision(6) << x << " " << y << endl; }
      |                                                ^
a.cc:76:60: error: 'y' was not declared in this scope
   76 |   void show()const{ cout << setprecision(6) << x << " " << y << endl; }
      |                                                            ^
a.cc:76:65: error: 'endl' was not declared in this scope
   76 |   void show()const{ cout << setprecision(6) << x << " " << y << endl; }
      |                                                                 ^~~~
a.cc: At global scope:
a.cc:77:1: error: expected declaration before '}' token
   77 | };
      | ^
a.cc:79:28: error: 'point' does not name a type; did you mean 'int'?
   79 | void print_kochcurve(const point &p1,const point &p2,int n);
      |                            ^~~~~
      |                            int
a.cc:79:44: error: 'point' does not name a type; did you mean 'int'?
   79 | void print_kochcurve(const point &p1,const point &p2,int n);
      |                                            ^~~~~
      |                                            int
a.cc: In function 'int main()':
a.cc:83:3: error: 'cin' was not declared in this scope
   83 |   cin >> n;
      |   ^~~
a.cc:84:3: error: 'point' was not declared in this scope; did you mean 'int'?
   84 |   point p1(0,0),p2(100,0);
      |   ^~~~~
      |   int
a.cc:85:3: error: 'p1' was not declared in this scope
   85 |   p1.show();
      |   ^~
a.cc:86:22: error: 'p2' was not declared in this scope
   86 |   print_kochcurve(p1,p2,n);
      |                      ^~
a.cc: At global scope:
a.cc:91:28: error: 'point' does not name a type; did you mean 'int'?
   91 | void print_kochcurve(const point &p1,const point &p2,int n){
      |                            ^~~~~
      |                            int
a.cc:91:44: error: 'point' does not name a type; did you mean 'int'?
   91 | void print_kochcurve(const point &p1,const point &p2,int n){
      |                                            ^~~~~
      |                                            int
a.cc: In function 'void print_kochcurve(const int&, const int&, int)':
a.cc:93:8: error: request for member 'show' in 'p2', which is of non-class type 'const int'
   93 |     p2.show();
      |        ^~~~
a.cc:97:3: error: 'point' was not declared in this scope; did you mean 'int'?
   97 |   point s,t,u;
      |   ^~~~~
      |   int
a.cc:99:3: error: 's' was not declared in this scope
   99 |   s = (p1*2.0 + p2)*(1./3);
      |   ^
a.cc:100:3: error: 't' was not declared in this scope
  100 |   t = (p1 + p2*2.0)*(1./3);
      |   ^
a.cc:102:3: error: 'u' was not declared in this scope
  102 |   u = (p1 + p2)*(1./2);
      |   ^
a.cc:103:19: error: request for member 'dist' in 'p1', which is of non-class type 'const int'
  103 |   double len = p1.dist(s)*sqrt(3)/2;
      |                   ^~~~
a.cc:103:27: error: 'sqrt' was not declared in this scope
  103 |   double len = p1.dist(s)*sqrt(3)/2;
      |                           ^~~~
a.cc:104:8: error: expected ';' before 'v'
  104 |   point v = p2-p1;
      |        ^~
      |        ;
a.cc:105:8: error: expected ';' before 'tmp'
  105 |   point tmp(-v.get_y(),v.get_x());
      |        ^~~~
      |        ;
a.cc:106:3: error: 'tmp' was not declared in this scope
  106 |   tmp = tmp*(1./tmp.norm());
      |   ^~~