Advertisement
Maku779

CCS1203_A3_BasicCalcu_OutsideClass

Dec 7th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.04 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. class myAdd
  6. {
  7.   public:
  8.     int myAddi(int num1, int num2);
  9. };
  10.  
  11. int myAdd::myAddi(int num1, int num2)
  12. {
  13.     int ans;
  14.     ans = num1 + num2;
  15.     cout << " " << num1 << " + " << num2 << " = " << ans;
  16.  
  17.     return 0;
  18. }
  19.  
  20. class mySub
  21. {
  22.   public:
  23.     int mySubd(int num1, int num2);
  24. };
  25.  
  26. int mySub::mySubd(int num1, int num2)
  27. {
  28.     int ans;
  29.     ans = num1 - num2;
  30.     cout << " " << num1 << " - " << num2 << " = " << ans;
  31.  
  32.     return 0;
  33. }
  34.  
  35. class myMul
  36. {
  37.   public:
  38.     int myMult(int num1, int num2);
  39. };
  40.  
  41. int myMul::myMult(int num1, int num2)
  42. {
  43.     int ans;
  44.     ans = num1 * num2;
  45.     cout << " " << num1 << " * " << num2 << " = " << ans;
  46.  
  47.     return 0;
  48. }
  49.  
  50. class myDiv
  51. {
  52.   public:
  53.     int myDivi(int num1, int num2);
  54. };
  55.  
  56. int myDiv::myDivi(int num1, int num2)
  57. {
  58.     int ans;
  59.     ans = num1 / num2;
  60.     cout << " " << num1 << " / " << num2 << " = " << ans;
  61.  
  62.     return 0;
  63. }
  64.  
  65. class myMod
  66. {
  67.   public:
  68.     int myModu(int num1, int num2);
  69. };
  70.  
  71. int myMod::myModu(int num1, int num2)
  72. {
  73.     cout << "- Quotient: " << num1 << " ÷ " << num2 << " = " << num1 / num2 << endl;
  74.     cout << "- Remainder: " << num1 << " % " << num2 << " = " << num1 % num2;
  75.  
  76.     return 0;
  77. }
  78.  
  79. int main()
  80. {
  81.     int ans = 0;
  82.     int num1, num2;
  83.     char sel;
  84.     string dw;
  85.     do
  86.     {
  87.         system("cls");
  88.         cout << "------------------------------" << endl;
  89.         cout << "----    Ry's Calculator   ----" << endl;
  90.         cout << "------------------------------" << endl;
  91.         cout << "- Enter first number: ";
  92.         cin >> num1;
  93.         cout << "- Enter second number: ";
  94.         cin >> num2;
  95.         cout << "------------------------------" << endl;
  96.         cout << " Choose operation:\n-" << endl;
  97.         cout << "- 1. + Addition" << endl;
  98.         cout << "- 2. - Subtraction" << endl;
  99.         cout << "- 3. * Multiplication" << endl;
  100.         cout << "- 4. / Division" << endl;
  101.         cout << "- 5. % Modulo" << endl;
  102.         cout << "-\n Selected Operation: ";
  103.         cin >> sel;
  104.         cout << "------------------------------" << endl;
  105.         if (sel == '1' || sel == '+')
  106.         {
  107.             myAdd myOb1;
  108.             myOb1.myAddi(num1, num2);
  109.         }
  110.         if (sel == '2' || sel == '-')
  111.         {
  112.             mySub myOb2;
  113.             myOb2.mySubd(num1, num2);
  114.         }
  115.         if (sel == '3' || sel == '*')
  116.         {
  117.             myMul myOb3;
  118.             myOb3.myMult(num1, num2);
  119.         }
  120.         if (sel == '4' || sel == '/')
  121.         {
  122.             myDiv myOb4;
  123.             myOb4.myDivi(num1, num2);
  124.         }
  125.         if (sel == '5' || sel == '%')
  126.         {
  127.             myMod myOb5;
  128.             myOb5.myModu(num1, num2);
  129.         }
  130.         cout << "\n------------------------------" << endl;
  131.         cout << "- Do you want to use the\n- calculator again??::  ";
  132.         cin >> dw;
  133.     } while (dw.compare("Y") == 0 || dw.compare("y") == 0 || dw.compare("yes") == 0 || dw.compare("Yes") || dw.compare("YES") == 0);
  134.  
  135.     return 0;
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement