Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int aRe, aIm, bRe, bIm;
- int additionRe(int aRe, int bRe)
- {
- return (aRe + bRe);
- }
- int additionIm(int aIm, int bIm)
- {
- return (aIm + bIm);
- }
- int substractionRe(int aRe, int bRe)
- {
- return (aRe - bRe);
- }
- int substractionIm(int aIm, int bIm)
- {
- return (aIm - bIm);
- }
- int multiplication1(int aRe, int aIm, int bRe, int bIm)
- {
- return ((aRe * bRe) - (aIm * bIm));
- }
- int multiplication2(int aRe, int aIm, int bRe, int bIm)
- {
- return ((aIm * bRe) + (aRe * bIm));
- }
- int division1(int aRe, int aIm, int bRe, int bIm)
- {
- return (((aRe * bRe) + (aIm * bIm)) / ((bRe * bRe) + (bIm * bIm)));
- }
- int division2(int aRe, int aIm, int bRe, int bIm)
- {
- return (((aIm * bRe) - (aRe * bIm)) / ((bRe * bRe) + (bIm * bIm)));
- }
- int main()
- {
- int operation = 0;
- do
- {
- cout << "***************************************\n";
- cout << "** COMPLEX NUMBERS TOOL MENU **\n";
- cout << "** **\n";
- cout << "** 1. Addition **\n";
- cout << "** 2. Substraction **\n";
- cout << "** 3. Multiplication **\n";
- cout << "** 4. Division **\n";
- cout << "** **\n";
- cout << "** 5. Exit **\n";
- cout << "***************************************\n";
- cout << "Choose operation from the menu: ";
- cin >> operation;
- cout << endl;
- switch(operation)
- {
- case 1: cout << "a(Real part) = "; cin >> aRe;
- cout << "a(Imaginery part) = "; cin >> aIm;
- cout << "b(Real part) = "; cin >> bRe;
- cout << "b(Imaginary part) = "; cin >> bIm;
- system("CLS");
- cout << "(" << aRe << "+(" << aIm << "i)) + (" << bRe << "+(" << bIm << "i) = " << additionRe(aRe, bRe) << " + (" << additionIm(aIm, bIm) << "i)" << endl; break;
- case 2: cout << "a(Real part) = "; cin >> aRe;
- cout << "a(Imaginery part) = "; cin >> aIm;
- cout << "b(Real part) = "; cin >> bRe;
- cout << "b(Imaginary part) = "; cin >> bIm;
- system("CLS");
- cout << "(" << aRe << "+(" << aIm << "i)) - (" << bRe << "+(" << bIm << "i) = " << substractionRe(aRe, bRe) << " + (" << substractionIm(aIm, bIm) << "i)" << endl; break;;
- case 3: cout << "a(Real part) = "; cin >> aRe;
- cout << "a(Imaginery part) = "; cin >> aIm;
- cout << "b(Real part) = "; cin >> bRe;
- cout << "b(Imaginary part) = "; cin >> bIm;
- system("CLS");
- cout << "(" << aRe << "+(" << aIm << "i)) * (" << bRe << "+(" << bIm << "i) = " << multiplication1(aRe, aIm, bRe, bIm) << " + (" << multiplication2(aRe, aIm, bRe, bIm) << "i)" << endl; break;;;
- case 4:cout << "a(Real part) = "; cin >> aRe;
- cout << "a(Imaginery part) = "; cin >> aIm;
- cout << "b(Real part) = "; cin >> bRe;
- cout << "b(Imaginary part) = "; cin >> bIm;
- system("CLS");
- cout << "(" << aRe << "+(" << aIm << "i)) / (" << bRe << "+(" << bIm << "i) = " << division1(aRe, aIm, bRe, bIm) << " + (" << division2(aRe, aIm, bRe, bIm) << "i)" << endl; break;;;
- default:;
- }
- } while (operation != 5);
- system("PAUSE");
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement