Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void GetSubstraction(int& a, int b)
  6. {
  7. a-=b;
  8. }
  9. void GetSubstraction(int &aReal, int &aComplex, int bReal, int bComplex)
  10. {
  11. aReal-=bReal;
  12. aComplex-=bComplex;
  13. }
  14. int main()
  15. {
  16. char choise;
  17. cout<<"Press r to substraction two real numbers or c to complex: ";
  18. cin >>choise;
  19. switch (choise)
  20. {
  21. case 'r':
  22. int a, b;
  23. cout<<"Enter first real number: ";
  24. cin>>a;
  25. cout<<"Enter second real number: ";
  26. cin >>b;
  27. GetSubstraction(a,b);
  28. cout<<"Result: "<<a<<endl;
  29. break;
  30. case 'c':
  31. int aReal, aComplex, bReal, bComplex;
  32. cout<<"Enter real part of first number: ";
  33. cin>>aReal;
  34. cout<<"Enter complex part of first number: ";
  35. cin>>aComplex;
  36. cout<<"Enter real part of second number: ";
  37. cin>>bReal;
  38. cout<<"Enter complex part of second number: ";
  39. cin>>bComplex;
  40. GetSubstraction(aReal,aComplex,bReal,bComplex);
  41. if(aComplex>0)
  42. cout<<"Result: "<<aReal<<"+("<<bComplex<<")i"<<endl;
  43. else if(aComplex<0)
  44. cout<<"Result: "<<aReal<<"-("<<bComplex*(-1)<<")i"<<endl;
  45. else
  46. cout<<"Result: "<<aReal<<endl;
  47. break;
  48. default:
  49. cout<< "Wrong pick"<<endl;
  50. break;
  51. }
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement