Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <cassert>
  3.  
  4. using namespace std;
  5.  
  6. const int SIZE_IDENTITY_NUM = 11;
  7.  
  8. class Photo
  9. {
  10. private:
  11.     char* namePhotographer;
  12.     char identityNumAlbum[SIZE_IDENTITY_NUM];
  13.     int placeAlbum;
  14.     int rank;
  15.     void validation(const char*, int, int);
  16. public:
  17.     Photo();
  18.     Photo(const char*, const char*, int, int);
  19.     Photo(const Photo&);
  20.     Photo& operator=(const Photo&);
  21.     ~Photo();
  22.  
  23.     void setName(const char*);
  24.     void setIdentity(const char*);
  25.     void setPlace(int);
  26.     void setRank(int);
  27.  
  28.     const char* getName() const;
  29.     const char* getIdentity() const;
  30.     int getPlace() const;
  31.     int getRank() const;
  32. };
  33.  
  34. void Photo::validation(const char* identityVal, int placeVal, int rankVal)
  35. {
  36.     int counterCapital = 0;
  37.     bool flag = true;
  38.     for (int i = 0; i < strlen(identityVal); i++)
  39.     {
  40.         if (identityVal[i] >= 65 && identityVal[i] <= 90)
  41.         {
  42.             counterCapital++;
  43.         }
  44.         else if (!(identityVal[i] >= '0' && identityVal[i] <= '9'))
  45.         {
  46.             exit(1);
  47.         }
  48.  
  49.         for (int j = i + 1; j < strlen(identityVal); j++)
  50.         {
  51.             if (identityVal[i] == identityVal[j])
  52.             {
  53.                 flag = false;
  54.                 break;
  55.             }
  56.         }
  57.     }
  58.  
  59.     if (strlen(identityVal) != 10 || counterCapital < 4 || flag == false || placeVal <= 0 || rankVal <= 0)
  60.     {
  61.         cout << "Wrong input!\n";
  62.         exit(1);
  63.     }
  64. }
  65.  
  66. Photo::Photo()
  67. {
  68.     namePhotographer = NULL;
  69.     identityNumAlbum[0] = '\0';
  70.     placeAlbum = 0;
  71.     rank = 0;
  72. }
  73.  
  74. Photo::Photo(const char* nameVal, const char* identityVal, int placeVal, int rankVal)
  75. {
  76.     //validation(identityVal, placeVal, rankVal);
  77.     namePhotographer = new char[strlen(nameVal) + 1];
  78.     assert(namePhotographer != NULL);
  79.     strcpy(namePhotographer, nameVal);
  80.  
  81.     strcpy(identityNumAlbum, identityVal);
  82.  
  83.     placeAlbum = placeVal;
  84.     rank = rankVal;
  85. }
  86.  
  87. Photo::Photo(const Photo& copyPhoto)
  88. {
  89.     //validation(copyPhoto.identityNumAlbum, copyPhoto.placeAlbum, copyPhoto.rank);
  90.     namePhotographer = new char[strlen(copyPhoto.namePhotographer) + 1];
  91.     assert(namePhotographer != NULL);
  92.     strcpy(namePhotographer, copyPhoto.namePhotographer);
  93.  
  94.     strcpy(identityNumAlbum, copyPhoto.identityNumAlbum);
  95.  
  96.     placeAlbum = copyPhoto.placeAlbum;
  97.     rank = copyPhoto.rank;
  98. }
  99.  
  100. Photo& Photo::operator=(const Photo& samePhoto)
  101. {
  102.     if (this != &samePhoto)
  103.     {
  104.         delete[] namePhotographer;
  105.         namePhotographer = new char[strlen(samePhoto.namePhotographer) + 1];
  106.         assert(namePhotographer != NULL);
  107.         strcpy(namePhotographer, samePhoto.namePhotographer);
  108.  
  109.         strcpy(identityNumAlbum, samePhoto.identityNumAlbum);
  110.  
  111.         placeAlbum = samePhoto.placeAlbum;
  112.         rank = samePhoto.rank;
  113.     }
  114.     return *this;
  115. }
  116.  
  117. Photo::~Photo()
  118. {
  119.     delete[] namePhotographer;
  120. }
  121.  
  122. void Photo::setName(const char* nameVal)
  123. {
  124.     delete[] namePhotographer;
  125.     namePhotographer = new char[strlen(nameVal) + 1];
  126.     assert(namePhotographer != NULL);
  127.     strcpy(namePhotographer, nameVal);
  128. }
  129.  
  130. void Photo::setIdentity(const char* identityVal)
  131. {
  132.     int counterCapital = 0;
  133.     bool flag = true;
  134.     for (int i = 0; i < strlen(identityVal); i++)
  135.     {
  136.         if (identityVal[i] >= 65 && identityVal[i] <= 90)
  137.         {
  138.             counterCapital++;
  139.         }
  140.         else if (!(identityVal[i] >= '0' && identityVal[i] <= '9'))
  141.         {
  142.             exit(1);
  143.         }
  144.  
  145.         for (int j = i + 1; j < strlen(identityVal); j++)
  146.         {
  147.             if (identityVal[i] == identityVal[j])
  148.             {
  149.                 flag = false;
  150.                 break;
  151.             }
  152.         }
  153.     }
  154.  
  155.     if (strlen(identityVal) != 10 || counterCapital < 4 || flag == false)
  156.     {
  157.         cout << "Wrong input!\n";
  158.         exit(1);
  159.     }
  160.  
  161.     strcpy(identityNumAlbum, identityVal);
  162. }
  163.  
  164. void Photo::setPlace(int placeVal)
  165. {
  166.     if (placeVal <= 0)
  167.     {
  168.         cout << "Wrong input!\n";
  169.         exit(1);
  170.     }
  171.     placeAlbum = placeVal;
  172. }
  173.  
  174. void Photo::setRank(int rankVal)
  175. {
  176.     if (rankVal <= 0)
  177.     {
  178.         cout << "Wrong input!\n";
  179.         exit(1);
  180.     }
  181.     rank = rankVal;
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement