-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathallmethods.c
More file actions
211 lines (208 loc) · 5.47 KB
/
allmethods.c
File metadata and controls
211 lines (208 loc) · 5.47 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
//
// Created by mr hendy on 2/14/2023.
//
#include "allmethods.h"
Student *allRecords[classSize];
Adminpass *ad;
static int numOfStudent = 0;
void addStudentRecord(Student *st)
{
int found = 0;
if (numOfStudent == classSize)
{
printf("ClassRoom is full!!!\n");
return;
}
// check if student has already registered
for (int i = 0; i < classSize; ++i)
{
if (allRecords[i] != 0 || allRecords[i] != NULL)
{
if (allRecords[i]->id == st->id)
{
found = 1;
printf("This student has already registed please try again with another id!\n");
break;
}
}
}
// if not found ,then add
if (found == 0)
{
// allRecords[numOfStudent] = st;
// numOfStudent++;
for (int i = 0; i < classSize; ++i)
{
if (allRecords[i] == 0 || allRecords[i] == NULL)
{
allRecords[i] = st;
return;
}
}
printf("Addetion Done corectly!.\n");
}
}
void editStudentGrade()
{
char *pass = malloc(10 * sizeof(char));
printf("Enter Admin PassWord: ");
scanf(" %[^\n]%*c", pass);
if (strcmp(pass, ad->password) == 0)
{
int id, grade;
printf("Enter Student id: ");
scanf("%d", &id);
for (int i = 0; i < classSize; i++)
{
if (allRecords[i] != 0 || allRecords[i] != NULL)
{
if (allRecords[i]->id == id)
{
printf("Enter grade of student with id=%d new grade: ", id);
scanf("%d", &grade);
allRecords[i]->Grade = grade;
return;
}
}
}
printf("Student not found!");
}
else
{
printf("The password is false please try again!");
}
}
void editAdminPassword()
{
char *pass = (char *)malloc(strlen(ad->password) + 1);
char *NewPass = (char *)malloc(strlen(ad->password) + 1);
printf("Enter Admin Passwords\n");
scanf(" %[^\n]s", pass);
printf("admin Password at struct %s\n", ad->password);
printf("admin Password u entered %s\n", pass);
// getchar();
//ad->password=NULL;
if (strcmp(pass, ad->password) == 0)
{
ad->password=NULL;
printf("Please enter new password :\n");
scanf(" %[^\n]s", NewPass);
printf("admin Password %s\n", NewPass);
ad->password = NewPass;
printf("admin Password %s\n", ad->password);
}
else
{
printf("The password is false please try again!");
}
}
Student *readStudent()
{
Student *st = (Student *)malloc(sizeof(Student));
printf("Enter Name\n");
st->name = malloc(30 * sizeof(char));
fflush(stdin);
fgets(st->name, 30 * sizeof(char), stdin);
printf("Enter ID\n");
scanf("%d", &(st->id));
printf("Enter age\n");
scanf("%d", &(st->age));
readGrade:
printf("Enter Grade range between [0,100]\n");
scanf("%d", &(st->Grade));
if(st->Grade >100 || st->Grade <0){
goto readGrade;
}
printf("\
Enter Gender\n\
0-male\n\
1-female\n");
scanf("%d", &(st->gender));
fflush(stdin);
printf("Enter password: \n");
// char *pass = (char *)malloc(strlen(ad->password) + 1);
st->password = malloc( sizeof(char) *passwordsize);
scanf(" %s", st->password);
addStudentRecord(st);
return st;
}
void viewStudentRecord(int targetId)
{
int found = 0;
for (int i = 0; i < classSize; ++i)
{
if (allRecords[i] != 0 || allRecords[i] != NULL)
{
if (targetId == allRecords[i]->id)
{
//printf("%u\n", allRecords[i]);
printf("Name : %s\n", allRecords[i]->name);
printf(", ID : %d\n", allRecords[i]->id);
printf(", age : %d\n", allRecords[i]->age);
printf(", Grade : %d\n", allRecords[i]->Grade);
printf(", Gender : %s\n", allRecords[i]->gender == 0 ? "Male" : "Female");
//printf(" , Password %s \n", allRecords[i]->password);
found = 1;
return;
}
}
}
if (found == 0)
{
printf("Student not Found ,Enter Valid ID\n");
}
}
void removeStudentRecord(int id)
{
int found = 0;
for (int i = 0; i < classSize; ++i)
{
if (allRecords[i] != 0 || allRecords[i] != NULL)
{
if (id == allRecords[i]->id)
{
free(allRecords[i]);
allRecords[i] = NULL;
found = 1;
numOfStudent--;
return;
}
}
}
if (found == 0)
{
printf("Student not Found ,Enter Valid ID");
}
}
void viewAllStudentRecord()
{
for (int i = 0; i < classSize; ++i)
{
if (allRecords[i] != 0 || allRecords[i] != NULL)
{
viewStudentRecord(allRecords[i]->id);
}
}
}
int findPosition(int id)
{
for (int i = 0; i < classSize; i++)
{
if (allRecords[i]->id == id)
{
return i;
}
}
}
void editStudentPassword(int i)
{
printf("Please, enter your new password: \n");
scanf(" %[^\n]s", allRecords[i]->password);
printf("The password has been updated");
}
void editStudentName(int i)
{
printf("Please, enter your name: \n");
scanf(" %[^\n]s", allRecords[i]->name);
printf("Your name has been updated");
}