Advertisement
Guest User

Untitled

a guest
Oct 24th, 2014
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.69 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int aRe, aIm, bRe, bIm;
  6.  
  7. int additionRe(int aRe, int bRe)
  8. {
  9. return (aRe + bRe);
  10.  
  11. }
  12.  
  13. int additionIm(int aIm, int bIm)
  14. {
  15. return (aIm + bIm);
  16.  
  17. }
  18.  
  19. int substractionRe(int aRe, int bRe)
  20. {
  21. return (aRe - bRe);
  22.  
  23. }
  24.  
  25. int substractionIm(int aIm, int bIm)
  26. {
  27. return (aIm - bIm);
  28.  
  29. }
  30.  
  31. int multiplication1(int aRe, int aIm, int bRe, int bIm)
  32. {
  33. return ((aRe * bRe) - (aIm * bIm));
  34.  
  35. }
  36.  
  37. int multiplication2(int aRe, int aIm, int bRe, int bIm)
  38. {
  39. return ((aIm * bRe) + (aRe * bIm));
  40.  
  41. }
  42.  
  43. int division1(int aRe, int aIm, int bRe, int bIm)
  44. {
  45. return (((aRe * bRe) + (aIm * bIm)) / ((bRe * bRe) + (bIm * bIm)));
  46.  
  47. }
  48.  
  49. int division2(int aRe, int aIm, int bRe, int bIm)
  50. {
  51. return (((aIm * bRe) - (aRe * bIm)) / ((bRe * bRe) + (bIm * bIm)));
  52. }
  53.  
  54. int main()
  55. {
  56. int operation = 0;
  57.  
  58. do
  59. {
  60. cout << "***************************************\n";
  61. cout << "** COMPLEX NUMBERS TOOL MENU **\n";
  62. cout << "** **\n";
  63. cout << "** 1. Addition **\n";
  64. cout << "** 2. Substraction **\n";
  65. cout << "** 3. Multiplication **\n";
  66. cout << "** 4. Division **\n";
  67. cout << "** **\n";
  68. cout << "** 5. Exit **\n";
  69. cout << "***************************************\n";
  70. cout << "Choose operation from the menu: ";
  71. cin >> operation;
  72. cout << endl;
  73.  
  74.  
  75.  
  76. switch(operation)
  77. {
  78. case 1: cout << "a(Real part) = "; cin >> aRe;
  79. cout << "a(Imaginery part) = "; cin >> aIm;
  80. cout << "b(Real part) = "; cin >> bRe;
  81. cout << "b(Imaginary part) = "; cin >> bIm;
  82. system("CLS");
  83. cout << "(" << aRe << "+(" << aIm << "i)) + (" << bRe << "+(" << bIm << "i) = " << additionRe(aRe, bRe) << " + (" << additionIm(aIm, bIm) << "i)" << endl; break;
  84. case 2: cout << "a(Real part) = "; cin >> aRe;
  85. cout << "a(Imaginery part) = "; cin >> aIm;
  86. cout << "b(Real part) = "; cin >> bRe;
  87. cout << "b(Imaginary part) = "; cin >> bIm;
  88. system("CLS");
  89. cout << "(" << aRe << "+(" << aIm << "i)) - (" << bRe << "+(" << bIm << "i) = " << substractionRe(aRe, bRe) << " + (" << substractionIm(aIm, bIm) << "i)" << endl; break;;
  90. case 3: cout << "a(Real part) = "; cin >> aRe;
  91. cout << "a(Imaginery part) = "; cin >> aIm;
  92. cout << "b(Real part) = "; cin >> bRe;
  93. cout << "b(Imaginary part) = "; cin >> bIm;
  94. system("CLS");
  95. cout << "(" << aRe << "+(" << aIm << "i)) * (" << bRe << "+(" << bIm << "i) = " << multiplication1(aRe, aIm, bRe, bIm) << " + (" << multiplication2(aRe, aIm, bRe, bIm) << "i)" << endl; break;;;
  96. case 4:cout << "a(Real part) = "; cin >> aRe;
  97. cout << "a(Imaginery part) = "; cin >> aIm;
  98. cout << "b(Real part) = "; cin >> bRe;
  99. cout << "b(Imaginary part) = "; cin >> bIm;
  100. system("CLS");
  101. cout << "(" << aRe << "+(" << aIm << "i)) / (" << bRe << "+(" << bIm << "i) = " << division1(aRe, aIm, bRe, bIm) << " + (" << division2(aRe, aIm, bRe, bIm) << "i)" << endl; break;;;
  102. default:;
  103. }
  104.  
  105.  
  106.  
  107. } while (operation != 5);
  108.  
  109. system("PAUSE");
  110. return EXIT_SUCCESS;
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement