kirill_76rus

team

May 17th, 2020
479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.99 KB | None | 0 0
  1. /*
  2.  * main.cpp
  3.  *
  4.  *  Created on: 17 мая 2020 г.
  5.  *      Author: Fernandez K.A.
  6.  */
  7. #include<iostream>
  8. #include<utility>//connect for map
  9. #include<cmath>//connect for sqrt
  10. using namespace std;
  11. istream& operator >>(istream &inp, pair<int, int> &tmp) { //redefine operator >>
  12.     inp >> tmp.first >> tmp.second;
  13.     return inp;
  14. }
  15. ostream& operator <<(ostream &out, pair<int, int> &tmp) {
  16.     out << tmp.first << tmp.second << '\n';
  17.     return out; //return ostream& from next using cout
  18. }
  19. struct enter { //struct for enter the value of argument's
  20. public:
  21.     pair<int, int> tmp;//pair values of argument's
  22.     enter() {
  23.         cout << "please, enter the value of argument's\n";
  24.     }
  25.     enter(const int &status) {
  26.         if (status != 5) {
  27.             cin >> tmp;//usually situation
  28.         } else {
  29.             int argument;
  30.             cin >> argument;
  31.             tmp.first = tmp.second = argument;//the little magic
  32.         }
  33.     }
  34.     pair<int, int> data() {
  35.         return tmp;//return non-zero pair
  36.     }
  37. };
  38. struct operation {
  39. public:
  40.     int sum(pair<int, int> tmp) {
  41.  
  42.         return tmp.second + tmp.first;
  43.  
  44.     }
  45.     int diff(pair<int, int> tmp) {
  46.  
  47.         return tmp.first - tmp.second;
  48.  
  49.     }
  50.     int division(pair<int, int> tmp) {
  51.         return tmp.second / tmp.first;
  52.     }
  53.     int mult(pair<int, int> tmp) {
  54.         return tmp.first * tmp.second;
  55.     }
  56.     int sqr(pair<int, int> tmp) {
  57.         return sqrt(tmp.first);
  58.     }
  59. };
  60.  
  61. struct arg {
  62. public:
  63.     arg() {
  64.         cout << "please, enter the value of argument\n";
  65.     }
  66.     arg(const int &sel) {
  67.         enter cur(sel);
  68.         operation tmp;
  69.         switch (sel) {
  70.         case 1:
  71.             cout << tmp.sum(cur.data()) << endl;
  72.             break;
  73.         case 2:
  74.             cout << tmp.diff(cur.data()) << endl;
  75.             break;
  76.         case 3:
  77.             cout << tmp.division(cur.data()) << endl;
  78.             break;
  79.         case 4:
  80.             cout << tmp.mult(cur.data()) << endl;
  81.             break;
  82.         case 5:
  83.             cout << tmp.sqr(cur.data()) << endl;
  84.             break;
  85.         }
  86.     }
  87.  
  88. };
  89. int main() {
  90.     int val;
  91.     cout
  92.             << "enter number of operation:\n 1-sum \n 2-differense \n 3-divisions \n 4-multiplication\n 5-sqrt";
  93.     cin >> val;
  94.     arg tmp(val);
  95.     return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment