Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Punkt{
  6. public:
  7. double x;
  8. double y;
  9. };
  10.  
  11. class Wektor{
  12. private:
  13. double x;
  14. double y;
  15.  
  16. Punkt s,k;
  17.  
  18. public:
  19. friend ostream & operator << ( ostream &os, const Wektor &w);
  20.  
  21. Wektor (double x , double y , Punkt s){
  22. setX(x);
  23. setY(y);
  24. setS(s);
  25. obliczK();
  26. }
  27.  
  28. Wektor() {
  29. this->x=0;
  30. this->y=0;
  31. this->s.x=0;
  32. this->s.y=0;
  33. obliczK();
  34. }
  35.  
  36. Wektor (const Wektor &w){
  37. this->x=w.x;
  38. this->y=w.y;
  39. this->s=w.s;
  40. this->k=w.k;
  41. obliczK();
  42. }
  43.  
  44. void setX(int x){
  45. this->x=x;
  46. }
  47. void setY(int y){
  48. this->y=y;
  49. }
  50. void setS(Punkt s){
  51. this->s=s;
  52. }
  53. double getY(){
  54. return y;
  55. }
  56. double getX(){
  57. return x;
  58. }
  59. Punkt getS(){
  60. return s;
  61. }
  62. Punkt getK(){
  63. return k;
  64. }
  65.  
  66. void obliczK(){
  67. Punkt k;
  68. this->k=k;
  69. this->k.x=this->s.x + this->x;
  70. this->k.y=this->s.y + this->y;
  71. }
  72. void show(){
  73. cout<<"Wektor o poczatku w punkcie P["<<this->s.x<<","<<this->s.y<<"] i o kierunku x="<<getX()<<", y="<<getY()<<endl;
  74. }
  75. void toString(){
  76. cout<<"Wektor o poczatku w punkcie P["<<this->s.x<<","<<this->s.y<<"] i o kierunku x="<<getX()<<", y="<<getY()<<endl;
  77. }
  78.  
  79. Wektor operator + (const Wektor &w){
  80. Wektor tmp(x+w.x,y+w.y,s);
  81. return tmp;
  82. }
  83.  
  84. Wektor operator - (void){
  85. Wektor tmp(-x , -y, s);
  86. return tmp;
  87. }
  88.  
  89. };
  90.  
  91. int main(){
  92. Punkt pktS;
  93. pktS.x = 1;
  94. pktS.y = 2;
  95. Wektor wek(2 , 3, pktS);
  96. Wektor wek1(wek);
  97. Wektor wek2;
  98.  
  99. wek.show();
  100. wek1.show();
  101. wek2.show();
  102. Wektor wek3;
  103. wek3 = wek2 + wek;
  104. wek3.toString();
  105. wek3 = -wek3;
  106. wek3.toString();
  107.  
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement