Advertisement
alvsjo

"complex"

Oct 6th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. //Main
  2. #include <iostream>
  3.  
  4. // include header mora ici sa ""
  5. #include "Complex.h"
  6.  
  7.  
  8. using namespace std;
  9.  
  10.  
  11.  
  12. /**< default vrijednost je nasumicna */
  13.  
  14.         /**< cout - posetak stampe, endl - novi red  */
  15.  
  16. /**< sve dok je dvotacka prenosi se pravo pristupa (najcesce sa pise sa sekcijama) */
  17.  
  18. int main()
  19. {
  20.  
  21.     Complex c1;
  22.  
  23. /**< ovdje, klasa se ne smatra varijablom nego objektom */
  24.  
  25.     c1.SetData(32,10);
  26.     c1.PrintFunkcija();
  27.     cout << c1.Abs()<< endl;
  28.  
  29.  
  30.     return 0;
  31. }
  32.  
  33. //Header
  34.  
  35. class Complex
  36. {
  37. private:
  38.     float real;
  39.     float img;
  40. public:
  41.     void PrintFunkcija();
  42.     void SetData(float r, float i);
  43.     float Abs();
  44. };
  45.  
  46.  
  47.  
  48. //Klasa
  49. #include "Complex.h"
  50. #include <math.h>
  51. #include "iostream"
  52.  
  53. using namespace std;
  54.  
  55.  
  56.  
  57. void Complex::PrintFunkcija()
  58. {
  59.       cout << "Podaci " << real << " " << img << endl;
  60. }
  61.  
  62.  
  63. void Complex::SetData( float r, float i)
  64.     {
  65.         real=r;
  66.         img=i;
  67.     }
  68.  
  69. float Complex::Abs()
  70.     {
  71.         return sqrt(real*real + img*img);
  72.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement