Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- class User
- {
- public:
- User();
- User(const User& u);
- User(const char* uname, const char* pass);
- ~User();
- int getCnt() const;
- void setCnt(int cnt);
- friend bool operator==(const User& u1, const User& u2);
- friend bool passCompare(const User& u1, const User& u2);
- private:
- char *username;
- char *password;
- int cnt;
- };
- User::User()
- {
- this->cnt = 0;
- }
- User::User(const char* uname, const char* pass)
- {
- this->username = new char[strlen(uname) + 1];
- strcpy(this->username, uname);
- this->password = new char[strlen(pass) + 1];
- strcpy(this->password, pass);
- this->cnt = 0;
- }
- bool operator==(const User& u1, const User& u2)
- {
- if (strcmp(u1.username, u2.username) == 0)
- {
- return true;
- }
- return false;
- }
- bool passCompare(const User& u1, const User& u2)
- {
- if (strcmp(u1.username, u2.username) == 0 && strcmp(u1.password, u2.password) == 0)
- {
- return true;
- }
- return false;
- }
- User::~User()
- {
- delete[] this->username;
- delete[] this->password;
- }
- User::User(const User& u)
- {
- this->username = new char[strlen(u.username) + 1];
- strcpy(this->username, u.username);
- this->password = new char[strlen(u.password) + 1];
- strcpy(this->password, u.password);
- this->cnt = u.cnt;
- }
- int User::getCnt() const
- {
- return this->cnt;
- }
- void User::setCnt(int cnt)
- {
- this->cnt = cnt;
- }
- bool signIn(User users[], int n, char *uname, char *pass)
- {
- User usr(uname, pass);
- for (int i = 0; i < n; i++)
- {
- if (users[i] == usr)
- {
- if (passCompare(users[i], usr))
- {
- return true;
- }
- users[i].setCnt(users[i].getCnt() + 1);
- }
- }
- return false;
- }
- int main()
- {
- User users[3];
- users[0] = User("Pesho", "1234");
- users[1] = User("Pesho", "12345");
- users[2] = User("Peshoo", "123456");
- if (signIn(users, 3, "Pesho", "12345"))
- {
- cout << "Login: Yes";
- }
- else
- {
- cout << "Login: No";
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment