Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- struct complex
- {
- double re;
- double im;
- };
- void PrintComplexNumber(complex val);
- bool EnterComplexNumber(complex &val);
- int main()
- {
- complex A, B, C;
- if((cout<<"Number A :\n") && !EnterComplexNumber(A))
- cout<<"???????????* ?????®?¤?*\n";
- else
- if((cout<<"Number B :\n") && !EnterComplexNumber(B))
- cout<<"???????????* ?????®?¤?*\n";
- else
- {
- //(a1 + i*b1)*(a2 + i*b2) = a1*a2 - b1*b2 + i*(a1*b2 + a2*b1)
- C.re = (A.re*B.re + A.im*B.im)/(B.re*B.re + B.im*B.im);
- C.im = (A.im*B.re + A.re*B.im)/(B.re*B.re + B.im*B.im);
- cout<<"Vichitanie A/B :\n";
- PrintComplexNumber(C);
- }
- system("pause");
- return 0;
- }
- void PrintComplexNumber(complex val)
- {
- cout<<val.re;
- if(val.im < 0)
- cout<<" - i"<<-val.im;
- else
- cout<<" + i"<<val.im;
- cout<<endl;
- }
- bool EnterComplexNumber(complex &val)
- {
- bool bInput = true;
- cout<<"Vveditb diisnu chastinu : ";
- if(!(cin>>val.re) || cin.get() != '\n')
- bInput = false;
- if(bInput)
- {
- cout<<"Vveditb uuavnu chastinu : ";
- if(!(cin>>val.im) || cin.get() != '\n')
- bInput = false;
- }
- if(!bInput)
- {
- cin.clear();
- cin.sync();
- }
- return bInput;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement