Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Калькулятор через шаблони класу
- #include <iostream>
- using namespace std;
- template <class tType>
- class Calculator
- {
- private:
- tType a;
- tType b;
- tType c;
- public:
- tType sum()
- {
- cout << "Write a" << endl;
- cin >> a;
- cout << "Write b" << endl;
- cin >> b;
- c = a + b;
- cout << c << endl;
- return c;
- }
- tType rizn()
- {
- cout << "Write a" << endl;
- cin >> a;
- cout << "Write b" << endl;
- cin >> b;
- c = a - b;
- cout << c << endl;
- return c;
- }
- tType dob()
- {
- cout << "Write a" << endl;
- cin >> a;
- cout << "Write b" << endl;
- cin >> b;
- c = a * b;
- cout << c << endl;
- return c;
- }
- tType dil()
- {
- cout << "Write a" << endl;
- cin >> a;
- cout << "Write b" << endl;
- cin >> b;
- c = a / b;
- cout << c << endl;
- return c;
- }
- int Vibor()
- {
- int Answer;
- cout << "1 - dodavanja" << endl;
- cout << "2 - vidnimanja" << endl;
- cout << "3 - dobytok" << endl;
- cout << "4 - dilenja" << endl;
- cin >> Answer;
- return Answer;
- }
- Calculator()
- {
- while(1)
- {
- switch(Vibor())
- {
- case 1: sum();break;
- case 2: rizn();break;
- case 3: dob();break;
- case 4: dil();break;
- default:
- cout<<"Íåïðàâèëüíèé âèá³ð";Calculator();break;
- }
- }
- }
- };
- int main ()
- {
- Calculator <float> obj;
- float sum=obj.sum();
- float rizn=obj.rizn();
- float dob=obj.dob();
- float dil=obj.dil();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement