Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.78 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <cstdlib>
  3. #include <iostream>
  4. #include <iterator>
  5. #include <vector>
  6. #include <string>
  7. #include <fstream>
  8. #include <algorithm>
  9.  
  10. using namespace std;
  11.  
  12. #define DEAD 0
  13. #define ALIVE 1
  14. #define TEMPVALUE 2
  15. #define NUMBEROFNEIGHORS 4
  16. #define ITERATIONTORESPAWN 3
  17.  
  18.  
  19. // __________________________________________________________________
  20. // ______________________________________________________KLASA BAZOWA
  21. class basicCell
  22. {
  23. public:
  24.     char name;
  25.     int status;
  26.     int validate;
  27.     int flag;
  28.     basicCell();
  29.  
  30.     basicCell(char name, int status, int validate, int flag) : name(name), status(status), validate(validate), flag(flag)
  31.     {
  32.  
  33.     }
  34.     ~basicCell(){};
  35. };
  36.  
  37. // __________________________________________________________________
  38. // __________________________________________________________NORMALNA
  39. class normalCell : public basicCell
  40. {
  41. public:
  42.     normalCell(char name, int status, int validate, int flag): basicCell(name, status, validate, flag)
  43.     {};
  44.     ~normalCell(){};
  45. };
  46. // __________________________________________________________________
  47. // _______________________________________________________HIBERNUJACA
  48. class hibernateCell : public basicCell
  49. {
  50. public:
  51.     int timeToHibernate = 0;
  52.     hibernateCell(int timeToHibernate, char name, int status, int validate, int flag): basicCell(name, status, validate, flag)
  53.     {
  54.  
  55.     };
  56.     ~hibernateCell();
  57. };
  58. // __________________________________________________________________
  59. // _______________________________________________________OGRANICZONA
  60. class limitedCell : public basicCell
  61. {
  62. public:
  63.     int neighbors = 0;
  64.     limitedCell(int neighbors, char name, int status, int validate, int flag): basicCell(name, status, validate, flag)
  65.     {
  66.     };
  67.     ~limitedCell(){};
  68.  
  69. };
  70. // __________________________________________________________________
  71. // _________________________________________________TRUDNO ODRADZALNA
  72. class hardCell : public basicCell
  73. {
  74.     int TTR;
  75.     public:
  76.     hardCell(int TTR, char name, int status, int validate, int flag): basicCell(name, status, validate, flag)
  77.     {
  78.  
  79.     };
  80.     ~hardCell(){};
  81. };
  82. // __________________________________________________________________
  83. // ________________________________________________WERYFIKACJA DANYCH
  84. int verifyData(int val){
  85.     if (val == 1)
  86.     {
  87.         cout << val << endl;
  88.         return val;
  89.     }
  90.     else if (val == 0)
  91.     {
  92.         cout << val << endl;
  93.         return val;
  94.     }
  95.     return 0;
  96. }
  97. // __________________________________________________________________
  98. // _________________________________________________LADOWANIE Z PLIKU
  99. void fromFile(string fileInp){
  100.     ifstream ifs(fileInp.c_str());
  101.     if (ifs.is_open()){
  102.         try{
  103.             string val = "";
  104.             while (ifs >> val){
  105.                 verifyData(atoi(val.c_str()));
  106.             }
  107.         }
  108.         catch (int e){                                      // wyjatek - bo tak
  109.             cout << "Exception " << e << endl;
  110.         }
  111.     }
  112. }
  113. // __________________________________________________________________
  114. // _____________________________________________________________POMOC
  115. void help()
  116. {
  117.     cout << " Aby poprawnie uruchomic program nalezy podac w parametrach:" << endl;
  118.     cout << "-i nazwaPlikuWejsciowego.txt" << endl;
  119.     cout << "-o nazwaPlikuWyjsciowego.txt" << endl;
  120.     cout << "-p liczba iteracji" << endl;
  121.     cin.get();
  122. }
  123. // __________________________________________________________________
  124. // _____________________________________________GLOWNA CZESC PROGRAMU
  125. int main(int argc, char* argv[])
  126. {
  127.  
  128.     normalCell zmienna('w',1,2,3);
  129.  
  130.     int i = zmienna.flag;
  131.  
  132.     cout << i;
  133.     /*
  134.     string fileInp, fileOut;
  135.     int i = 1;
  136.     int iteration;
  137.  
  138.  
  139.     vector<int> v2(5, NULL);
  140.     vector<vector<int> > v2d2(1,v2);
  141.  
  142.     vector<vector<int> > v2d3(2,v2);
  143.  
  144.     for(int i = 0; i < v2d2.size(); i++) {
  145.       for (int j=0; j < v2d2[i].size(); j++)
  146.         cout << v2d2[i][j] << " ";
  147.       cout << endl;
  148.    }
  149.  
  150.  
  151.     if (argc == 7)                                                  // sprawdzanie argumentow
  152.     {
  153.         do
  154.         {
  155.             if (string(argv[i]) == "-i") {
  156.                 fileInp = argv[i + 1];                              // plik wejsciowy
  157.             }
  158.             else if (string(argv[i]) == "-o") {
  159.                 fileOut = argv[i + 1];                              // plik wyjsciowy
  160.             }
  161.             else if (string(argv[i]) == "-p") {
  162.                 iteration = atoi(argv[i + 1]);                      // liczba iteracji
  163.             }
  164.             else                                                    // gdy bledny argument
  165.             {
  166.                 cout << "Wrong arguments in the command line" << endl;
  167.             }
  168.             i = i + 2;
  169.         } while (i < argc);
  170.  
  171.         if (iteration == 0)                                             // jezeli jezeli iteracja rowna zero
  172.             cout << "the number of iterations equal to zero" << endl;
  173.         else if ((iteration > 1) && (iteration < 100000))               // jezeli ok
  174.         {
  175.             fromFile(fileInp);
  176.             for (int i=0; i < iteration; i++)
  177.             {
  178.             cout << "Works fine! Iteration: " << i+1 << endl;
  179.  
  180.  
  181.  
  182.  
  183.             TUTAJ UMIESCIC WSZYSTKIE OBLICZANIE ZALEZNIE OD WARTOSCI POBRANEJ Z PLIKU
  184.  
  185.  
  186.  
  187.  
  188.             cin.get();
  189.             }
  190.         }else
  191.         {
  192.             cout << "wrong value of parameters" << endl;
  193.         }
  194.     }
  195.     else if (string(argv[i]) == "-h")                                       // pomoc
  196.     {
  197.         help();
  198.     }
  199.     else                                                            // gdy wszystko zawiedzie
  200.     {
  201.         help();
  202.     }
  203.  
  204.     //_CrtDumpMemoryLeaks();
  205.     return EXIT_SUCCESS;
  206.     */
  207. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement