1 solutions
-
0
C++ :
#include <iostream> using namespace std; class Complex { int real,imag; public: Complex( ):real(0),imag(0){} Complex(int r,int i):real(r),imag(i){} friend Complex operator *(Complex& c1,Complex& c2); friend istream & operator>>(istream & input,Complex& c); friend ostream & operator<<(ostream & out,Complex& c); }; istream & operator>>(istream &input,Complex& c) {input>>c.real>>c.imag; return input;} ostream & operator<<(ostream & out,Complex& c) { out<<c.real; if (c.imag>0) out<<"+"; if (c.imag!=0) out<<c.imag<<"i"<<endl; return out;} Complex operator *(Complex& c1,Complex& c2) {Complex c; c.real=c1.real*c2.real-c1.imag*c2.imag; c.imag=c1.imag*c2.real+c1.real*c2.imag; return c; } int main() {Complex c1,c2,c3; cin>>c1>>c2; c3=c1*c2; cout<<c3; return 0;}
- 1
Information
- ID
- 17023
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By