Advertisement
tei123

struct

Apr 10th, 2018
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. struct TComplex
  7. {
  8. float Re;
  9. float Im;
  10. };
  11.  
  12. void suma(TComplex jeden, TComplex druga)
  13. {
  14. TComplex su;
  15.  
  16. su.Re=jeden.Re+druga.Re;
  17. su.Im=jeden.Im+druga.Im;
  18.  
  19. cout<<"\nCzesc rzeczywista: "<<su.Re<<"\nCzesc urojona: "<<su.Im<<endl;
  20. };
  21.  
  22. void iloczyn(TComplex jeden, TComplex druga)
  23. {
  24. TComplex ilo;
  25. ilo.Re=(jeden.Re*druga.Re-jeden.Im*druga.Im);
  26. ilo.Im=(jeden.Re*druga.Im+druga.Re*jeden.Im);
  27.  
  28.  
  29. cout<<"Czesc rzeczywista: "<<ilo.Re<<" "<<"\nCzesc urojona: "<<ilo.Im<<endl;
  30. };
  31.  
  32. void drukuj(TComplex jeden, TComplex druga)
  33. {
  34. TComplex dr;
  35. TComplex dr2;
  36. dr.Re=jeden.Re;
  37. dr.Im=jeden.Im;
  38. dr2.Re=druga.Re;
  39. dr2.Im=druga.Im;
  40.  
  41. cout<<dr.Re<< "+" <<dr.Im<< "j" <<", "5;
  42. cout<<dr2.Re<< "+" <<dr2.Im<< "j" <<endl;
  43. };
  44.  
  45.  
  46. int main(int argc, char *argv[])
  47. {
  48. TComplex pierwsza;
  49. TComplex druga;
  50.  
  51. cout<<"Podaj pierwsza liczbe\n";
  52. cin>>pierwsza.Re;
  53. cin>>pierwsza.Im;
  54.  
  55. cout<<"Podaj druga liczbe\n";
  56. cin>>druga.Re;
  57. cin>>druga.Im;
  58.  
  59. cout<<"suma to: ";
  60. suma(pierwsza, druga);
  61.  
  62. cout<<"iloczyn to: \n";
  63. iloczyn(pierwsza, druga);
  64. cout<<endl;
  65.  
  66. drukuj(pierwsza, druga);
  67.  
  68. system("PAUSE");
  69. return EXIT_SUCCESS;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement