Fiszu

Multiplication in memory leearning

Jul 23rd, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstdlib>
  4. #include <time.h>
  5. #include <math.h>
  6. #include <windows.h>
  7. #include <string>
  8.  
  9. using namespace std;
  10.  
  11. unsigned long long beg, ended, diff;                        // DEKLARACJA ZMIENNYCH===============================================
  12. string najw[37];
  13. int btime[37];
  14. int q=1,i;
  15.  
  16.  
  17. unsigned long long Losuj(int trudP, int trudK, int pot);    // DEKLARACJA FUNKCJI============================================================
  18.  
  19. int Konmin(int sekundy);
  20.  
  21. int Konsec(int sekundy);
  22.  
  23. int IsBest(int time, int dlug, int tryb, int poz);
  24.  
  25. void Read();
  26.  
  27. void Start();
  28.  
  29. void Stop();
  30.  
  31. int main()                                                  // MAIN============MAIN=================================================
  32. {
  33.     HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  34.     SetConsoleTextAttribute(hConsole, 14);
  35.  
  36.     int poz, tlp, tlk, tryb;                             // DEKLARACJA ZMIENNYCH===============================================
  37.     unsigned long long wynik, odp, a, b;
  38.     bool trwa;
  39.  
  40.  
  41.  
  42. /*
  43.    for (int q = 1; q <= 35; q++)
  44.     {
  45.         cout<<najw[q]<<endl;
  46.     }*/
  47.  
  48.     srand(time(NULL));
  49.  
  50.     while(1){
  51.  
  52.  
  53.  
  54.             trwa = true;
  55.  
  56.     cout<<"Wybierz tryb: "<<endl<<"1. Potegowanie"<<endl<<"2. Mnozenie"<<endl;
  57.     cin>>tryb;
  58.  
  59.   //   Read();
  60.  
  61.      cout<<"Wybierz ilosc cyfr (1-5): "<<endl;
  62.     cin>>i;
  63.  
  64.     Read();
  65.  
  66.     cout<<"Wybierz poziom trydnosci od 1 do 3"<<endl;
  67.     cin>>poz;
  68.  
  69.     switch(poz)
  70.            {
  71.  
  72.            case 1:
  73.  
  74.                tlp = 5;
  75.                tlk = 1;
  76.             break;
  77.  
  78.            case 2:
  79.                tlp = 4;
  80.                tlk = 3;
  81.             break;
  82.  
  83.            case 3:
  84.                tlp = 4;
  85.                tlk = 6;
  86.             break;
  87.  
  88.             default:
  89.                cout<<"Nie ma takiej opcji!"<<endl;
  90.                break;
  91.            }
  92.  
  93.         a = Losuj(tlp, tlk, i);
  94.  
  95.         wynik = a * a;
  96.         b=a;
  97.  
  98.  
  99.         if (tryb == 2)
  100.         {
  101.             b = Losuj(tlp, tlk, i);
  102.             wynik = a * b;
  103.         }
  104.  
  105.      cout<<a<<" X "<<b<<" = ";
  106.      Start();
  107.      while(trwa)
  108.     {
  109.      cin>>odp;
  110.      if(odp == wynik)
  111.      {
  112.          Stop();
  113.          trwa=false;
  114.          IsBest(diff, i, tryb, poz);
  115.      }
  116.      else
  117.      {
  118.          cout<<"ZLE!"<<endl;
  119.      }
  120.  
  121.     }
  122.  
  123.     }
  124.     return 0;
  125. }
  126.  
  127.  
  128.                                                
  129. int Konsec(int sekundy)                         CIALA FUNKCJI======================================================================              
  130. {
  131.     return  sekundy - 60 * (sekundy/60);
  132. }
  133.  
  134. int Konmin(int sekundy)
  135. {
  136.     return sekundy/60;
  137. }
  138.  
  139. unsigned long long Losuj(int trudP, int trudK, int pot)
  140. {
  141.     unsigned long long toret = 0, ilecyfr;
  142.     pot--;
  143.     for(pot; pot>0; pot)
  144.     {
  145.         ilecyfr = pow(10, pot);
  146.  
  147.         if ( ilecyfr%2 != 0)
  148.            ilecyfr++;
  149.  
  150.     toret = toret + (rand()%trudP + trudK) * ilecyfr;
  151.     pot--;
  152.     }
  153.  
  154.     toret = toret + rand()%trudP + trudK;
  155.  
  156.     return toret;
  157. }
  158.  
  159. void Read()
  160. {
  161.  
  162.     ifstream score("score.txt");
  163.     if (score.is_open())
  164.     {
  165.         q=1;
  166.         while( getline (score,najw[q]))
  167.         {
  168.           //  cout<<najw[q]<<endl;
  169.             if(q<=35)
  170.             q++;
  171.         }
  172.         score.close();
  173.     }
  174.     else
  175.     {
  176.         cout<<"error"<<endl;
  177.     }
  178.  
  179.      for (int u=1; u<37; u)
  180.      {
  181.          btime[u] = atoi(najw[u].c_str());
  182.          u++;
  183.  
  184.      }
  185.  
  186. }
  187.  
  188. int IsBest(int time, int dlug, int tryb, int poz)
  189. {
  190.     switch (poz)
  191.     {
  192.     case 2:
  193.         dlug=dlug+5;
  194.         break;
  195.  
  196.     case 3:
  197.         dlug=dlug+10;
  198.         break;
  199.     }
  200.  
  201.     if (tryb == 2)
  202.         dlug = dlug + 15;
  203.  
  204.  
  205.     if(time<btime[dlug])
  206.     {
  207.         cout<<"POBILES REKORD!"<<endl;
  208.         if(btime[dlug]!= 10000)
  209.         {
  210.         cout<<"Poprzedni rekord wynosil "<<Konmin(btime[dlug])<<" min "<<Konsec(btime[dlug])<<" s"<<endl<<endl;
  211.         }
  212.         btime[dlug] = time;
  213.  
  214.         ofstream dozapisu ("score.txt");
  215.         if (dozapisu.is_open())
  216.         {
  217.             for (int q = 1; q <= 35; q++)
  218.             {
  219.                 dozapisu << btime[q]<<endl;
  220.             }
  221.         }
  222.         else cout << "Unable to open file";
  223.  
  224.         dozapisu.close();
  225.  
  226.     }
  227. }
  228.  
  229. void Start()
  230. {
  231.    // cout<<"START!!"<<endl;
  232.     beg = time(NULL);
  233. }
  234.  
  235. void Stop()
  236. {
  237.     cout<<endl<<"Udalo ci sie!"<<endl;
  238.     ended = time(NULL);
  239.     diff = ended - beg;
  240.     cout<<"Twoj czas wynosi: "<<Konmin(diff)<<" minut i "<<Konsec(diff)<<" sekund(y)!"<<endl<<endl;
  241.  
  242.  
  243. }
Add Comment
Please, Sign In to add comment