fork download
  1. #include <iostream>
  2. #include <list>
  3. #include <sstream>
  4. #include <string>
  5. using std::stringstream;
  6. #include <cmath>
  7. using namespace std;
  8.  
  9.  
  10. template<unsigned short n>
  11. class Point {
  12.  
  13. public:
  14. list <float> coords = {0.0};
  15. Point <n>() = default;
  16. Point <n>(list<float> coords){
  17.  
  18. this-> coords=coords;
  19. }
  20.  
  21. string toString(){
  22. string sone;
  23. ostringstream ss;
  24. sone.append("(");
  25. auto it3= coords.begin();
  26. while ((it3) != coords.end()){
  27. ss << (*it3);
  28. sone.append(ss.str());
  29. ss.str("");
  30. ++it3;
  31. }
  32. sone.append(")");
  33. return sone;
  34. }
  35.  
  36. float distanceFrom (Point <n> v){
  37. float s=0;
  38. list<float> coords;
  39. auto it1= coords.begin();
  40. auto it2= v.coords.begin();
  41. while ((it1) != coords.end()){
  42. s+=(*it1 -*it2)*(*it1-*it2);
  43. it1++;
  44. it2++;
  45. }
  46. return sqrt(s);
  47. }
  48. friend std::ostream& operator <<(std::ostream& out, const Point<n>& v)
  49. {
  50. out << "("<<"Test"<<")";
  51. return out;
  52. }
  53. };
  54.  
  55. int main() {
  56. // your code goes here
  57. Point<2> v3 { list<float>{2.0,3.0} };
  58. cout << v3.toString () << endl;
  59. return 0;
  60. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
(23)