Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 34 additions & 26 deletions Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ const int MAX = 100;
template<typename T,typename F>
int myfind(T* begin,T* end,F f) {
for (T* itr = begin; itr != end; itr++) {

?

if (f(*itr) == 1) {
return itr - begin;
}
}
return -1;

Expand Down Expand Up @@ -61,9 +61,11 @@ class Staff : public AbstractUser {
cout << "Staff: " << username << ", Salary: " << salary << endl;
}
bool hasAccessToSee(AbstractUser* user) const override {
if (? != nullptr) {
if (dynamic_cast<Student *>(user) != nullptr) {
return true;
}

return false;
}

private:
Expand All @@ -80,62 +82,69 @@ class Admin : public Staff {
cout << "Admin ";
Staff::displayRole();
}
?
bool hasAccessToSee(AbstractUser* user) const override {
if (dynamic_cast<Admin *>(user) == nullptr) {
return true;
}
return false;
}
};

AbstractUser* current_user;
AbstractUser* users[100];
int user_cnt;
AbstractUser* G_current_user;
AbstractUser* G_users[100];
int G_user_cnt;

void print() {
if (!current_user) {
if (!G_current_user) {
return;
}
for (AbstractUser* user : users) {
if (?) {
for (AbstractUser* user : G_users) {
if (G_current_user->hasAccessToSee(user) == true) {
if (user == nullptr) {
return;
}
user->displayRole();
}
}
}

void addStudent(string username, string password, int grade) {
int index = ?;
int index = myfind(G_users, G_users + G_user_cnt, [username](const AbstractUser *us){ if (username == us->getUsername()){return 1;} else {return 0;}});
if (index != -1) {
return;
}
if (dynamic_cast<Admin*>(current_user) == nullptr){
if (dynamic_cast<Admin*>(G_current_user) == nullptr){
cout << "permision denied"<<endl;
return;
}
Student* st = new Student(username, password, grade);
users[user_cnt ++] = st;
G_users[G_user_cnt ++] = st;
}

int main() {
Student s("erfan", "pass1", 12);
Student s2("rasool", "pass2", 12);
Staff st("alireza", "staffpass", 1000);
Staff st("kiyan", "staffpass", 1000);
Staff st2("kiyan", "staffpass", 1000);
Admin a("yalda", "adminpass",1200);
user_cnt = 5;
users[0] = &s;
?
?
?
?
G_user_cnt = 5;
G_users[0] = &s;
G_users[1] = &s2;
G_users[2] = &st;
G_users[3] = &st2;
G_users[4] = &a;

while (1) {
string username, password;
cout << "username: ";
cin >> username;
cout << "password:";
cin >> password;
int index = myfind(users, users + user_cnt, ?);
int index = myfind(G_users, G_users + G_user_cnt, [username](const AbstractUser *us){ if (username == us->getUsername()){return 1;} else {return 0;}});
if (index!=-1) {
current_user = users[index];
G_current_user = G_users[index];
break;
}

}
int choice;
while (1) {
Expand All @@ -150,10 +159,9 @@ int main() {
int grade;
cin >> user >> pass >> grade;
addStudent(user, pass, grade);

}

}

return 0;
}
}