Advertisement
tei123

przeladowanbiue

Apr 24th, 2018
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6. class Tcomplex{
  7. public:
  8. float Re;
  9. float Im;
  10. Tcomplex();
  11. Tcomplex(float R);
  12. Tcomplex(float R, float I);
  13. friend Tcomplex operator +(Tcomplex R, Tcomplex I);
  14. friend ostream & operator<<(ostream& ekran, Tcomplex x);
  15. friend ostream & operator-(ostream& ekran, Tcomplex x);
  16. friend ostream & operator*(ostream& ekran, Tcomplex x);
  17. friend ostream & operator/(ostream& ekran, Tcomplex x);
  18.  
  19. };
  20.  
  21. Tcomplex::Tcomplex(){
  22. Re=0;
  23. Im=0;
  24. };
  25.  
  26. Tcomplex::Tcomplex(float R){
  27. Re=R;
  28. Im=0;
  29. };
  30.  
  31. Tcomplex::Tcomplex(float R,float I){
  32. Re=R;
  33. Im=I;
  34. };
  35.  
  36. Tcomplex operator +(Tcomplex R, Tcomplex I)
  37. {
  38.  
  39. Tcomplex c;
  40. c.Im=R.Im+I.Im;
  41. c.Re=R.Re+I.Re;
  42.  
  43. return c;
  44. }
  45.  
  46. Tcomplex operator -(Tcomplex R, Tcomplex I)
  47. {
  48.  
  49. Tcomplex c;
  50. c.Im=R.Im-I.Im;
  51. c.Re=R.Re-I.Re;
  52.  
  53. return c;
  54. }
  55.  
  56. Tcomplex operator *(Tcomplex R, Tcomplex I)
  57. {
  58.  
  59. Tcomplex c;
  60. c.Im=R.Im*I.Im;
  61. c.Re=R.Re*I.Re;
  62.  
  63. return c;
  64. }
  65.  
  66. Tcomplex operator /(Tcomplex R, Tcomplex I)
  67. {
  68.  
  69. Tcomplex c;
  70. c.Im=R.Im/I.Im;
  71. c.Re=R.Re/I.Re;
  72.  
  73. return c;
  74. }
  75.  
  76.  
  77. ostream&operator <<(ostream&ekran, Tcomplex x)
  78. {
  79. ekran<<x.Re<<""<<showpos<<x.Im<<"j"<<noshowpos<<endl;
  80. return ekran;
  81. }
  82.  
  83. int main()
  84. {
  85.  
  86. Tcomplex::Tcomplex L1(1,2);
  87. Tcomplex::Tcomplex L2(6,4);
  88. Tcomplex::Tcomplex L3;
  89. L3=L1/L2;
  90. cout<< L3;
  91.  
  92.  
  93. //cout<<L1.Re<<L1.Im;
  94.  
  95.  
  96. system("PAUSE");
  97.  
  98.  
  99. return EXIT_SUCCESS;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement