Здравствуйте! У меня задание на матрицу доступа пользователей. Код все написал, но есть одна не решенная деталь. Создаю массив с пользователями и для каждого из них разделил их доступы. Но при проверке почему то проверятся только 1ый пользователь (users[0]), а остальных он просто выдает за ошибку ( за else). Прошу помогите, в чем ошибка
C++ (Qt) |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
| #include <conio.h>
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;
int main(){
string id="";
string items[5]={"File1","File2","Floopy","CD-ROM","Hard Disk"};
string rights[6];
string users[5];
users[0]="Admin";
users[1]="Guest";
users[2]="Stud";
users[3]="Personal";
users[4]="Home";
rights[0]="Полный доступ";
rights[1]="Передача прав";
rights[2]="Запись";
rights[3]="Чтение";
rights[4]="Чтение, Запись";
rights[5]="Полный запрет";
int rights1[25];
rights1[0]=0;
rights1[1]=0;
rights1[2]=0;
rights1[3]=0;
rights1[4]=0;
rights1[5]=0;
rights1[6]=4;
rights1[7]=3;
rights1[8]=2;
rights1[9]=5;
rights1[10]=0;
rights1[11]=4;
rights1[12]=3;
rights1[13]=1;
rights1[14]=2;
rights1[15]=0;
rights1[16]=3;
rights1[17]=2;
rights1[18]=5;
rights1[19]=4;
rights1[20]=0;
rights1[21]=3;
rights1[22]=2;
rights1[23]=4;
rights1[24]=1;
string operation="";
setlocale(LC_ALL,"russian");
string login;
cout<<"Введите логин:";
cin>>login;
for (int i=0; i!=5;i++)
{
if (login==users[i])
{
cout<<"Добро пожаловать в систему, "<<login<<endl;
cout<<"Перечень ваших прав: "<<login<<endl;
cout<< items[0] + "-"<<rights[rights1[i]]<<endl;
cout<< items[1] + "-"<<rights[rights1[i+5]]<<endl;
cout<< items[2] + "-"<<rights[rights1[i+10]]<<endl;
cout<< items[3] + "-"<<rights[rights1[i+15]]<<endl;
cout<< items[4] + "-"<<rights[rights1[i+20]]<<endl;
break;
}
else if (login!=users[i]){ cout<<"Ошибка! Введите правильные данные!"<<endl;
main();}
}
do {
cout <<"Жду ваших указаний "<<login<<":";
cin>>operation;
if (operation=="exit"){
cout<<"Выход из системы... Нажмите любую клавишу";
break;
}
else if (operation=="read"){
int O;
cout<<"Перечень объектов"<<endl;
cout<<"[0] - [" <<items[0]<<"]\n";
cout<<"[1] - [" <<items[1]<<"]\n";
cout<<"[2] - [" <<items[2] <<"]\n";
cout<<"[3] - [" <<items[3]<<"]\n";
cout<<"[4] - [" <<items[4] <<"]\n";
cout<<"Над каким обьектом выполняется операция?"<<endl;
cin>>O;
switch(O){
case 0: cout<<"Выбран объект "<<items[0]<<endl; break;
case 1: cout<<"Выбран объект "<<items[1]<<endl; break;
case 2: cout<<"Выбран объект "<<items[2]<<endl; break;
case 3: cout<<"Выбран объект "<<items[3]<<endl; break;
case 4: cout<<"Выбран объект "<<items[4]<<endl; break;
default: cout<<"Объект " <<O<<" не найден!!!"<<endl; break;
}
}
cout<<"Открыть выбранный объект?"<<endl;
cin>>operation;
if (operation=="yes"){
system("notepad D:\File1.txt");
}
}while(true);
_getch();
return 0;
} |
|