The complex class
2013-04-21 16:44
155 查看
// File name : complex.h #ifndef _COMPLEX_H_ #define _COMPLEX_H_ #include <iostream> using namespace std; class complex { public: complex(double x = 0, double y = 0) { real = x; imag = y; } complex(complex &src) { real = src.real; imag = src.imag; } ~complex() {} complex operator+(const complex& src) const{ return complex(real + src.real, imag + src.imag); } complex& operator=(const complex& src) { real = src.real; imag = src.imag; return (*this); } void operator++(int) { cout << "call post++"<<endl; imag = imag + 1; } void operator++() { cout << "call pre++"<<endl; real = real + 1; } void print(ostream& out) { if(real != 0) out<<real; if(imag > 0) out<<"+"<<imag<<"j"; else if(imag < 0) out<<imag<<"j"; if(real == 0 && imag == 0) out<<"0"; } private: double real; double imag; }; ostream& operator<<(ostream& out, complex& obj) { obj.print(out); return out; } #endif
相关文章推荐
- A class extends ArrayList, but the instance of the calss do not work in a complex case.
- 异常:Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046}
- Downloading files in Flex using the FileReference class
- org.hibernate.WrongClassException: Object with id: 3 was not of the specified subclass
- C++ philosophy: Changing the accessibility of a class member should never change the meaning of a program.
- Error:Could not determine the class-path for interface com.android.builder.model.AndroidProject
- The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class
- could not find the main class,program will exit
- How to use the xsd generator generate the class
- HDU 6015 Skip the Class(map用法)
- How to: Send Data Using the WebRequest Class
- 动态调用方法Use the NSInvocation class
- jdk版本不同造成问题解决could not find the main class, Program will exit(2)
- How to remove the copyright box on a paper that uses the ACM sig-alternate.cls class file?
- The Environment class in C#
- A Generic JDBC Abstraction Framework(5)--Using the JdbcTemplate Class
- Using the Android Application class to persist data
- Parser Error Message: The base class includes the fieldthe type of control (ASP.
- The serializable class Proname does not declare a static final serialVersionUID field of type long
- The STL Vector Class