Advertisement
endreweast

Calculate

Dec 2nd, 2015
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.99 KB | None | 0 0
  1. //Калькулятор через шаблони класу
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. template <class tType>
  7. class Calculator
  8. {
  9.    private:
  10.           tType a;
  11.           tType b;
  12.           tType c;
  13.    public:
  14.           tType sum()
  15.           {
  16.           cout << "Write a" << endl;
  17.           cin >> a;
  18.           cout << "Write b" << endl;
  19.           cin >> b;
  20.           c = a + b;
  21.           cout << c << endl;
  22.           return c;
  23.           }
  24.          
  25.           tType rizn()
  26.           {
  27.           cout << "Write a" << endl;
  28.           cin >> a;
  29.           cout << "Write b" << endl;
  30.           cin >> b;
  31.           c = a - b;
  32.           cout << c << endl;
  33.           return c;
  34.           }
  35.           tType dob()
  36.           {
  37.           cout << "Write a" << endl;
  38.           cin >> a;
  39.           cout << "Write b" << endl;
  40.           cin >> b;
  41.           c = a * b;
  42.           cout << c << endl;
  43.           return c;
  44.           }
  45.           tType dil()
  46.           {
  47.           cout << "Write a" << endl;
  48.           cin >> a;
  49.           cout << "Write b" << endl;
  50.           cin >> b;
  51.           c = a / b;
  52.           cout << c << endl;
  53.           return c;
  54.           }
  55.           int Vibor()
  56.            {
  57.               int Answer;
  58.               cout << "1 - dodavanja" << endl;
  59.               cout << "2 - vidnimanja" << endl;
  60.               cout << "3 - dobytok" << endl;
  61.               cout << "4 - dilenja" << endl;
  62.               cin >> Answer;
  63.               return Answer;
  64.           }
  65.           Calculator()
  66.    {
  67.     while(1)
  68.     {
  69.         switch(Vibor())
  70.         {
  71.         case 1: sum();break;
  72.         case 2: rizn();break;
  73.         case 3: dob();break;
  74.         case 4: dil();break;
  75.         default:
  76.         cout<<"Íåïðàâèëüíèé âèá³ð";Calculator();break;
  77.                }
  78.     }
  79. }
  80. };
  81. int main ()
  82. {
  83.     Calculator <float> obj;
  84.     float sum=obj.sum();
  85.     float rizn=obj.rizn();
  86.     float dob=obj.dob();
  87.     float dil=obj.dil();
  88.     return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement