Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cassert>
- using namespace std;
- const int SIZE_IDENTITY_NUM = 11;
- class Photo
- {
- private:
- char* namePhotographer;
- char identityNumAlbum[SIZE_IDENTITY_NUM];
- int placeAlbum;
- int rank;
- void validation(const char*, int, int);
- public:
- Photo();
- Photo(const char*, const char*, int, int);
- Photo(const Photo&);
- Photo& operator=(const Photo&);
- ~Photo();
- void setName(const char*);
- void setIdentity(const char*);
- void setPlace(int);
- void setRank(int);
- const char* getName() const;
- const char* getIdentity() const;
- int getPlace() const;
- int getRank() const;
- };
- void Photo::validation(const char* identityVal, int placeVal, int rankVal)
- {
- int counterCapital = 0;
- bool flag = true;
- for (int i = 0; i < strlen(identityVal); i++)
- {
- if (identityVal[i] >= 65 && identityVal[i] <= 90)
- {
- counterCapital++;
- }
- else if (!(identityVal[i] >= '0' && identityVal[i] <= '9'))
- {
- exit(1);
- }
- for (int j = i + 1; j < strlen(identityVal); j++)
- {
- if (identityVal[i] == identityVal[j])
- {
- flag = false;
- break;
- }
- }
- }
- if (strlen(identityVal) != 10 || counterCapital < 4 || flag == false || placeVal <= 0 || rankVal <= 0)
- {
- cout << "Wrong input!\n";
- exit(1);
- }
- }
- Photo::Photo()
- {
- namePhotographer = NULL;
- identityNumAlbum[0] = '\0';
- placeAlbum = 0;
- rank = 0;
- }
- Photo::Photo(const char* nameVal, const char* identityVal, int placeVal, int rankVal)
- {
- //validation(identityVal, placeVal, rankVal);
- namePhotographer = new char[strlen(nameVal) + 1];
- assert(namePhotographer != NULL);
- strcpy(namePhotographer, nameVal);
- strcpy(identityNumAlbum, identityVal);
- placeAlbum = placeVal;
- rank = rankVal;
- }
- Photo::Photo(const Photo& copyPhoto)
- {
- //validation(copyPhoto.identityNumAlbum, copyPhoto.placeAlbum, copyPhoto.rank);
- namePhotographer = new char[strlen(copyPhoto.namePhotographer) + 1];
- assert(namePhotographer != NULL);
- strcpy(namePhotographer, copyPhoto.namePhotographer);
- strcpy(identityNumAlbum, copyPhoto.identityNumAlbum);
- placeAlbum = copyPhoto.placeAlbum;
- rank = copyPhoto.rank;
- }
- Photo& Photo::operator=(const Photo& samePhoto)
- {
- if (this != &samePhoto)
- {
- delete[] namePhotographer;
- namePhotographer = new char[strlen(samePhoto.namePhotographer) + 1];
- assert(namePhotographer != NULL);
- strcpy(namePhotographer, samePhoto.namePhotographer);
- strcpy(identityNumAlbum, samePhoto.identityNumAlbum);
- placeAlbum = samePhoto.placeAlbum;
- rank = samePhoto.rank;
- }
- return *this;
- }
- Photo::~Photo()
- {
- delete[] namePhotographer;
- }
- void Photo::setName(const char* nameVal)
- {
- delete[] namePhotographer;
- namePhotographer = new char[strlen(nameVal) + 1];
- assert(namePhotographer != NULL);
- strcpy(namePhotographer, nameVal);
- }
- void Photo::setIdentity(const char* identityVal)
- {
- int counterCapital = 0;
- bool flag = true;
- for (int i = 0; i < strlen(identityVal); i++)
- {
- if (identityVal[i] >= 65 && identityVal[i] <= 90)
- {
- counterCapital++;
- }
- else if (!(identityVal[i] >= '0' && identityVal[i] <= '9'))
- {
- exit(1);
- }
- for (int j = i + 1; j < strlen(identityVal); j++)
- {
- if (identityVal[i] == identityVal[j])
- {
- flag = false;
- break;
- }
- }
- }
- if (strlen(identityVal) != 10 || counterCapital < 4 || flag == false)
- {
- cout << "Wrong input!\n";
- exit(1);
- }
- strcpy(identityNumAlbum, identityVal);
- }
- void Photo::setPlace(int placeVal)
- {
- if (placeVal <= 0)
- {
- cout << "Wrong input!\n";
- exit(1);
- }
- placeAlbum = placeVal;
- }
- void Photo::setRank(int rankVal)
- {
- if (rankVal <= 0)
- {
- cout << "Wrong input!\n";
- exit(1);
- }
- rank = rankVal;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement