Advertisement
dzieciol

cpp5 zadanie 1b

Nov 4th, 2016
385
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. //ma przyjmować na wejściu tablice a nie zmenne we wszystkich przykladach
  2.  
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. class wektor
  8. {
  9.     float *mac = new float[3];
  10. public:
  11.     //wektor(*float = 1.0, *float = 2.0, *float = 3.0);
  12.     wektor(float*,float*, float*);
  13.     wektor();
  14.     void wyswietl();
  15.     wektor mnoz(wektor a, wektor b);
  16.  
  17. };
  18.  
  19.  
  20. wektor::wektor(float *a, float *b, float *c)
  21. {
  22.     *(mac) = *a;
  23.     *(mac+1) = *b;
  24.     *(mac+2) = *c;
  25. }
  26.  
  27. wektor::wektor()
  28. {
  29.     *(mac) = 1.0;
  30.     *(mac+1) = 2.0;
  31.     *(mac+2) = 3.0;
  32.  
  33. }
  34. void wektor::wyswietl()
  35. {
  36.     cout<<*this->mac<<" : ";
  37.     cout<<*this->mac+1<<" : ";
  38.     cout<<*this->mac+2<<" : ";
  39.  
  40.  
  41. }
  42. wektor wektor::mnoz(wektor a, wektor b)
  43. {
  44.     wektor zwracany;
  45.     for (int i = 0; i<3 ; i++){
  46.          *(zwracany.mac+i) = (*(a.mac+i)) * (*(b.mac+i));
  47.     }
  48.  
  49. return zwracany;
  50. }
  51.  
  52.  
  53.  
  54.  
  55. int main()
  56. {
  57.         wektor jeden;
  58.         jeden.wyswietl();
  59.         float *a, *b, *c;
  60.         float d,e,f;
  61.         d=5;
  62.         e=6;
  63.         f=7;
  64.         a = &d;
  65.         b = &e;
  66.         c = &f;
  67.         wektor dwa(a,b,c);
  68.         cout<<endl;
  69.         dwa.wyswietl();
  70.         wektor trzy  = jeden.mnoz(jeden, dwa);
  71.         cout<<endl;
  72.         trzy.wyswietl();
  73.  
  74. return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement