fork download
  1. #include<iostream>
  2. #include<algorithm>
  3. #include<math.h>
  4. using namespace std;
  5. class Cvector
  6. {
  7. public:
  8. int x,y;
  9. Cvector() { x=0;y=0;}
  10. Cvector(int i){}
  11. Cvector(int,int);
  12. Cvector operator+(Cvector);
  13. Cvector operator-(Cvector);
  14. int operator*(Cvector);
  15. bool operator==(Cvector);
  16. Cvector operator*(int);
  17. Cvector operator=(Cvector);
  18.  
  19. int cross_multiplication(Cvector,Cvector);
  20. float norm();
  21.  
  22. };
  23. Cvector Cvector::operator=(Cvector a)
  24. {
  25. x=a.x;
  26. y=a.y;
  27. return *this;
  28.  
  29. }
  30. bool Cvector::operator==(Cvector b)
  31. {
  32. return (x==b.x && y==b.y);
  33.  
  34. }
  35.  
  36. Cvector Cvector::operator*(int c)
  37. {
  38. Cvector temp;
  39. temp.x=c*x;
  40. temp.y=c*y;
  41. return temp;
  42.  
  43. }
  44. float Cvector::norm()
  45. {
  46. float result=0;
  47. result+=x*x+y*y;;
  48. return sqrt(result);
  49.  
  50.  
  51. }
  52. Cvector::Cvector(int a,int b)
  53. {
  54. x=a;
  55. y=b;
  56.  
  57. }
  58. Cvector Cvector::operator+(Cvector a)
  59. {
  60. Cvector temp;
  61. temp.x=x+a.x;
  62. temp.y=y+a.y;
  63. return temp;
  64.  
  65. }
  66. Cvector Cvector::operator-(Cvector b)
  67. {
  68. Cvector temp;
  69. temp.x=x-b.x;
  70. temp.y=y-b.y;
  71. return temp;
  72.  
  73. }
  74. int Cvector::operator*(Cvector a)
  75. {
  76. return x*a.x+y*a.y;
  77.  
  78.  
  79. }
  80.  
  81. int main()
  82. {
  83. Cvector a(3,4);
  84. Cvector b(4,5);
  85. cout<<b.norm()<<endl;
  86. Cvector c;
  87. c=a*b;
  88. cout<<(a==b)<<endl;
  89.  
  90. return 0;
  91. }
Success #stdin #stdout 0.02s 2724KB
stdin
Standard input is empty
stdout
6.40312
0