Advertisement
Paszta

obiektowka laby 6 - l. zespolone ale dzielenie moze nie dz

Nov 20th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. 1.
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. class liczby_zespolone{
  7. private:
  8. int re, im;
  9. public:
  10. liczby_zespolone(int a=0,int b=0){
  11. re=a;
  12. im=b;
  13. }
  14. void operator +(liczby_zespolone &B){
  15. re=re+B.re;
  16. im = im+B.im;
  17. }
  18.  
  19. liczby_zespolone operator -(liczby_zespolone &B){
  20. liczby_zespolone wynik;
  21. wynik.re=re-B.re;
  22. wynik.im=im-B.im;
  23.  
  24. return wynik;
  25. }
  26.  
  27. liczby_zespolone operator *(liczby_zespolone &B){
  28. liczby_zespolone m;
  29. m.re=(re*B.re) - (im*B.im);
  30. m.im=(re*B.im) + (im*B.re);
  31.  
  32. return m;
  33. }
  34.  
  35. liczby_zespolone operator /(liczby_zespolone &B){
  36. liczby_zespolone n;
  37. n.re=((re*B.re) - (im*B.im))/((B.re*B.re)+(B.im*B.im));
  38. n.im=((re*B.im) + (im*B.re))/((B.re*B.re)+(B.im*B.im));
  39. return n;
  40. }
  41.  
  42.  
  43.  
  44. void druk(){
  45. cout << "Liczba zespolona wynosi:" << "z=" << re << "+i(" << im << ")" << endl;
  46. }
  47. };
  48.  
  49. int main()
  50. {
  51. liczby_zespolone L1(2,6);
  52. liczby_zespolone L2(7,-3);
  53. liczby_zespolone L3;
  54. liczby_zespolone L4;
  55. liczby_zespolone L5;
  56.  
  57. L1.druk();
  58. L2.druk();
  59. L3.druk();
  60.  
  61. cout << "Opcja 1: wynik dodawania L1 i L2" << endl;
  62. L1+L2;
  63. L1.druk();
  64.  
  65. cout << "Opcja 2: wynik odejmowania L1 i L2" << endl;
  66. L3 = L1 - L2;
  67. L3.druk();
  68.  
  69. cout << "Opcja 2: mnozenia L1 i L3" << endl;
  70. L4 = L1*L3;
  71. L4.druk();
  72.  
  73.  
  74. cout << "Opcja 2: dzielenie L4 i L3" << endl;
  75. L5 = L4/L3;
  76. L5.druk();
  77. return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement