Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.55 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.  
  13. int verifyData(int val){
  14.     if (val == 1)
  15.     {
  16.         cout << val << endl;
  17.         return val;
  18.     }
  19.     else if (val == 0)
  20.     {
  21.         cout << val << endl;
  22.         return val;
  23.     }
  24.     return 0;
  25. }
  26.  
  27. void fromFile(string fileInp){
  28.     ifstream ifs(fileInp.c_str());
  29.     if (ifs.is_open()){
  30.         try{
  31.             //bool isValid = true;
  32.             string val = "";
  33.             while (ifs >> val){
  34.                 verifyData(atoi(val.c_str()));
  35.             }
  36.         }
  37.         catch (int e){                                      // wyjatek - bo tak
  38.             cout << "Exception " << e << endl;
  39.         }
  40.     }
  41. }
  42.  
  43. void help()
  44. {
  45.     cout << " Aby poprawnie uruchomic program nalezy podac w parametrach:" << endl;
  46.     cout << "-i nazwaPlikuWejsciowego.txt" << endl;
  47.     cout << "-o nazwaPlikuWyjsciowego.txt" << endl;
  48.     cout << "-p liczba iteracji" << endl;
  49.     cin.get();
  50. }
  51.  
  52. int main(int argc, char* argv[])
  53. {
  54.     string fileInp, fileOut;
  55.     int i = 1;
  56.     int iteration;
  57.  
  58.  
  59.     vector<int> v2(5, NULL);
  60.     vector<vector<int> > v2d2(1,v2);
  61.  
  62.     vector<vector<int> > v2d3(2,v2);
  63.  
  64.     for(int i=0;i<v2d2.size(); i++) {
  65.       for (int j=0;j<v2d2[i].size(); j++)
  66.         cout << v2d2[i][j] << " ";
  67.       cout << endl;
  68.    }
  69.  
  70.  
  71.     if (argc == 7)                                                  // sprawdzanie argumentow
  72.     {
  73.         do
  74.         {
  75.             if (string(argv[i]) == "-i") {
  76.                 fileInp = argv[i + 1];                              // plik wejsciowy
  77.             }
  78.             else if (string(argv[i]) == "-o") {
  79.                 fileOut = argv[i + 1];                              // plik wyjsciowy
  80.             }
  81.             else if (string(argv[i]) == "-p") {
  82.                 iteration = atoi(argv[i + 1]);                      // liczba iteracji
  83.             }
  84.             else                                                    // gdy bledny argument
  85.             {
  86.                 cout << "Wrong arguments in the command line" << endl;
  87.             }
  88.             i = i + 2;
  89.         } while (i < argc);
  90.  
  91.         if (iteration == 0)                                             // jezeli jezeli iteracja rowna zero
  92.             cout << "the number of iterations equal to zero" << endl;
  93.         else if ((iteration > 1) && (iteration < 100000))               // jezeli ok
  94.         {
  95.             fromFile(fileInp);
  96.             for (int i=0; i < iteration; i++)
  97.             {
  98.             cout << "Works fine! Iteration: " << i+1 << endl;
  99.             cin.get();
  100.             }
  101.         }else
  102.         {
  103.             cout << "wrong value of parameters" << endl;
  104.         }
  105.     }
  106.     else if (string(argv[i]) == "-h")                                       // pomoc
  107.     {
  108.         help();
  109.     }
  110.     else                                                            // gdy wszystko zawiedzie
  111.     {
  112.         help();
  113.     }
  114.  
  115.     //_CrtDumpMemoryLeaks();
  116.     return EXIT_SUCCESS;
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement