Advertisement
Lauda

Untitled

Nov 26th, 2012
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.87 KB | None | 0 0
  1. #ifndef COMPLEX_H_INCLUDED
  2. #define COMPLEX_H_INCLUDED
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. class Complex
  8. {
  9.     private:
  10.         double real, imag;
  11.  
  12.     public:
  13.         // Konstruktori
  14.         Complex();
  15.         Complex(double, double);
  16.         Complex(const Complex&);
  17.  
  18.         double getReal() const;
  19.         double getImag() const;
  20.         void setReal(double);
  21.         void setImag(double);
  22.  
  23.         Complex& operator=(const Complex&);
  24.         Complex& operator+=(const Complex&);
  25.         Complex& operator-=(const Complex&);
  26.         Complex& operator*=(const Complex&);
  27.         Complex& operator/=(const Complex&);
  28.         const Complex& operator++();
  29.         const Complex operator++(int);
  30.  
  31.         friend Complex operator+(const Complex&, const Complex&);
  32.         friend Complex operator-(const Complex&, const Complex&);
  33.         friend Complex operator*(const Complex&, const Complex&);
  34.         friend Complex operator/(const Complex&, const Complex&);
  35.         friend bool operator==(const Complex&, const Complex&);
  36.         friend bool operator!=(const Complex&, const Complex&);
  37.         friend ostream& operator<<(ostream&, const Complex&);
  38.         friend istream& operator>>(istream&, const Complex&);
  39.  
  40. };
  41.  
  42.  
  43. #endif // COMPLEX_H_INCLUDED
  44.  
  45.  
  46. /* Errors:
  47. D:\FTN\Programiranje\Complex\complex.h||In function 'std::istream& operator>>(std::istream&, Complex&)':|
  48. D:\FTN\Programiranje\Complex\complex.h|10|error: 'double Complex::real' is private|
  49. D:\FTN\Programiranje\Complex\complex.cpp|156|error: within this context|
  50. D:\FTN\Programiranje\Complex\complex.h|10|error: 'double Complex::imag' is private|
  51. D:\FTN\Programiranje\Complex\complex.cpp|156|error: within this context|
  52. ||=== Build finished: 4 errors, 0 warnings ===|
  53. */
  54.  
  55. // complex.cpp:
  56. istream &operator>>(istream &in, Complex &z)
  57. {
  58.  
  59.   in >> z.real >> z.imag;
  60.  
  61.     return in;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement