Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <memory>
  4.  
  5. using namespace std;
  6.  
  7. struct zespol
  8. {
  9. double rzeczywista, urojona;
  10. };
  11.  
  12. unique_ptr<zespol> dodawanie(const vector<zespol> &vec)
  13. {
  14. unique_ptr <zespol> suma (new zespol());
  15. for(int i=0;i<vec.size();i++)
  16. {
  17. suma->rzeczywista+=vec[i].rzeczywista;
  18. suma->urojona+=vec[i].urojona;
  19. }
  20. return move(suma);
  21. }
  22.  
  23. int main()
  24. {
  25. vector <zespol> liczby;
  26. liczby.push_back(zespol());
  27. liczby[0].rzeczywista = 8.32;
  28. liczby[0].urojona = 5.2;
  29. liczby.push_back(zespol());
  30. liczby[1].rzeczywista = 1.901;
  31. liczby[1].urojona = 0.98;
  32. liczby.push_back(zespol());
  33. liczby[2].rzeczywista = 4.92;
  34. liczby[2].urojona = 7.1;
  35. unique_ptr<zespol> ptr1=dodawanie(liczby);
  36. cout<<"Czesc rzeczywista: "<<ptr1->rzeczywista<<endl;
  37. cout<<"Czesc urojona: "<<ptr1->urojona<<"i";
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement