Advertisement
Heretiiik

Untitled

Feb 4th, 2017
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.61 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <sstream>
  4. #include <string>
  5.  
  6.  
  7. using namespace std;
  8.  
  9. float secti(float a ,float b) {
  10.     return a + b;
  11. }
  12. float odecti(float a ,float b) {
  13.     return a - b;
  14. }
  15. float nasob(float a ,float b) {
  16.     return a * b;
  17. }
  18. float del(float a ,float b) {
  19.     return a / b;
  20. }
  21.  
  22. // 1
  23. float (*prvni)  (float, float);
  24.  
  25. // 2
  26. float (*calc[])(float,float) = { secti, odecti, nasob, del };
  27.  
  28. void handler(void) {
  29.     float cislo;
  30.     float prvni = 5.4f;
  31.     float druhe = 8.0f;
  32.     string in;
  33.     int op = 0;
  34.     string operace[] = { "scitani", "odecitani", "nasobeni", "deleni" };
  35.    
  36.     cout << "Zadej cisla, pro skonceni stiskni X" << endl;
  37.     /*while (true) {
  38.         if (cin >> cislo) {
  39.             druhe = prvni;
  40.             prvni = cislo;
  41.         } else if (cin >> in) {
  42.             if (in == "X" || in == "x") {
  43.                 break;
  44.             }
  45.         }
  46.     }*/
  47.    
  48.     cout << "Pomoci klaves A a S vyber operaci, klavesa P provede operaci." << endl;
  49.     while (true) {
  50.         cout << operace[op] << endl;
  51.         cin >> in;
  52.        
  53.         if (in == "P" || in == "p" ) {
  54.             cout << (*calc[op])(prvni,druhe) << endl;
  55.            
  56.             return;
  57.         }
  58.        
  59.         if (in == "S" || in == "s" ) {
  60.             op = (++op % 4);
  61.         }
  62.         if (in == "A" || in == "a") {
  63.             if (op == 0) {
  64.                 op = 3;
  65.             } else {
  66.                 --op;
  67.             }
  68.         }
  69.     }
  70.    
  71. }
  72.  
  73.  
  74. int main(int argc, char** argv) {
  75.  
  76.     handler();
  77.    
  78.     // 3
  79.    
  80.    
  81.     return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement