Advertisement
Guest User

Untitled

a guest
Mar 1st, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. using namespace std;
  5. class vec {
  6. private:
  7. double x;
  8. double y;
  9. public:
  10. vec(double n, double m){
  11. x = n;
  12. y = m;
  13. cout <<"конструктор с параметрами\n";
  14. }
  15. vec(){
  16. cout<<"здесь вызывается конструктор по умоч\n";
  17. }
  18. ~vec(){
  19. cout << "вызывается деструктор\n";
  20. }
  21. vec(const vec &a){
  22. cout<<"копирования\n";
  23. }
  24.  
  25. friend vec& operator*= (vec& v1, vec& v2);
  26. friend vec& operator+= (vec& v1, vec& v2);
  27. friend vec& operator+ (const vec& v1, const vec& v2);
  28.  
  29.  
  30. void show(){
  31. cout << x << " " << y;
  32. cout << endl;
  33. }
  34. };
  35. vec& operator*=(vec& v1, vec& v2){
  36. v1.x *= v2.x;
  37. v1.y *= v2.y;
  38. return v1;
  39. }
  40. vec& operator+=(vec& v1, vec& v2){
  41. v1.x += v2.x;
  42. v1.y += v2.y;
  43. return v1;
  44. }
  45. vec v3;
  46. vec& operator+(const vec& v1, const vec& v2){
  47. v3.x = v1.x + v2.x;
  48. v3.y = v1.y + v2.y;
  49. return v3;
  50. }
  51.  
  52. void rr(vec v){
  53. v.show();
  54.  
  55.  
  56. }
  57. int main(){
  58. vec v1;
  59.  
  60. vec v2(2.0,2.0);
  61. vec v3(7.0,6.0);
  62. v1 = v2 + v3;
  63. v1.show();
  64.  
  65.  
  66.  
  67.  
  68. return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement