Advertisement
Guest User

Untitled

a guest
Dec 1st, 2015
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5. struct complex
  6. {
  7.     double re;
  8.     double im;
  9. };
  10.  
  11. void PrintComplexNumber(complex val);
  12. bool EnterComplexNumber(complex &val);
  13.  
  14. int main()
  15. {
  16.     complex A, B, C;
  17.     if((cout<<"Number A :\n") && !EnterComplexNumber(A))
  18.         cout<<"???????????* ?????®?¤?*\n";
  19.     else
  20.     if((cout<<"Number B :\n") && !EnterComplexNumber(B))
  21.         cout<<"???????????* ?????®?¤?*\n";
  22.     else
  23.     {
  24.         //(a1 + i*b1)*(a2 + i*b2) = a1*a2 - b1*b2 + i*(a1*b2 + a2*b1)
  25.         C.re = (A.re*B.re + A.im*B.im)/(B.re*B.re + B.im*B.im);
  26.         C.im = (A.im*B.re + A.re*B.im)/(B.re*B.re + B.im*B.im);
  27.         cout<<"Vichitanie A/B :\n";
  28.         PrintComplexNumber(C);
  29.     }
  30.     system("pause");
  31.     return 0;
  32. }
  33.  
  34. void PrintComplexNumber(complex val)
  35. {
  36.     cout<<val.re;
  37.     if(val.im < 0)
  38.         cout<<" - i"<<-val.im;
  39.     else
  40.         cout<<" + i"<<val.im;
  41.     cout<<endl;
  42. }
  43.  
  44. bool EnterComplexNumber(complex &val)
  45. {
  46.     bool bInput = true;
  47.     cout<<"Vveditb diisnu chastinu : ";
  48.     if(!(cin>>val.re) || cin.get() != '\n')
  49.         bInput = false;
  50.     if(bInput)
  51.     {
  52.         cout<<"Vveditb uuavnu chastinu : ";
  53.         if(!(cin>>val.im) || cin.get() != '\n')
  54.             bInput = false;
  55.     }
  56.     if(!bInput)
  57.     {
  58.         cin.clear();
  59.         cin.sync();
  60.     }
  61.     return bInput;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement