-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassignment3.c
221 lines (202 loc) · 4.43 KB
/
assignment3.c
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
212
213
214
215
216
217
218
219
220
221
// Assignment 3
// Submitted by Ronald T. Tolentino
// TUP / CS203
/* Instructions
Modify assignment 2(name, q1, q2, q3) to use Menu
Menu
Insert record
Delete record
Display //tabular output including ave and remarks
Exit
Select(1 - 4) :
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 3
//Global Variables
char student[MAX][31];
int quiz1[MAX], quiz2[MAX], quiz3[MAX];
int last;
//Functions without return value
void initialize();
void add();
void del();
void display();
//Functions with return value
int menu();
int isfull();
int isempty();
//Functions with return value and parameters
int search(char sn[31]);
float getAverage(int q1, int q2, int q3);
int main()
{
initialize();
while (1)
{
switch (menu())
{
case 1:
add();
break;
case 2:
del();
break;
case 3:
display();
break;
case 4:
printf("Thank You For Using The Program...\n");
printf("Exiting Now...\n");
system("pause");
exit(0);
default:
printf("1 to 4 Only.\n");
system("pause");
}
}
return 0;
}
void initialize()
{
last = -1;
}
void add()
{
char sn[31];
int q1, q2, q3;
if (isfull())
{
system("cls");
printf("Add Student Mode\n");
printf("Array Is Full!.\n");
printf("Please Select Other Menu Option.\n");
system("pause");
}
else
{
system("cls");
printf("Add Student Mode\n");
printf("Input Name: ");
scanf("%s", sn);
printf("Input QUIZ 1: ");
scanf("%d", &q1);
printf("Input QUIZ 2: ");
scanf("%d", &q2);
printf("Input QUIZ 3: ");
scanf("%d", &q3);
last = last + 1;
strcpy(student[last], sn);
quiz1[last] = q1;
quiz2[last] = q2;
quiz3[last] = q3;
printf("Student Records Added\n");
system("pause");
}
}
void del()
{
char sn[31];
int i, p;
if (isempty())
{
printf("DELETE MODE\n");
printf("Array Is Empty.\n");
printf("There Is Nothing To Delete.\n");
printf("Please Select Other Menu Option.\n");
system("pause");
}
else
{
system("cls");
printf("DELETE MODE\n");
printf("Input Student Name: ");
scanf("%s", sn);
p = search(sn);
if (p == -1)
{
printf("DELETE MODE\n");
printf("%s cannot be found.\n", sn);
printf("Please try again.\n");
system("pause");
}
else
{
for (i = p; i < last; i++)
{
strcpy(student[i], student[i + 1]);
quiz1[i] = quiz1[i + 1];
quiz2[i] = quiz2[i + 1];
quiz3[i] = quiz3[i + 1];
}
printf("DELETE MODE\n");
printf("%s is now deleted..\n", sn);
system("pause");
last--;
}
}
}
int search(char sn[31])
{
int i;
for (i = 0; i <= last; i++)
if (strcmp(student[i], sn) == 0)
return i;
return -1;
}
void display()
{
if (isempty())
{
system("cls");
printf("DISPLAY MODE\n");
printf("Array is empty...\n");
printf("There is nothing to display...\n");
printf("Please Select Other Menu Option...\n");
system("pause");
}
else
{
int i;
float ave;
system("cls");
printf("DISPLAY MODE\n");
printf("No. NAME Quiz 1 Quiz 2 Quiz 3 Average Remarks\n");
for (i = 0; i <= last; i++)
{
ave = getAverage(quiz1[i], quiz2[i], quiz3[i]);
printf("%d.) %s %d %d %d %6.2f %s\n", i + 1, student[i], quiz1[i], quiz2[i], quiz3[i], ave, ave >= 75 ? "Passed" : "Failed");
}
system("pause");
}
}
int menu()
{
int m;
system("cls");
printf("Menu\n");
printf("1.) Insert record\n");
printf("2.) Delete record\n");
printf("3.) Display\n");
printf("4.) Exit\n");
printf("Select(1-4): ");
scanf("%d", &m);
return (m);
}
float getAverage(int q1, int q2, int q3)
{
float ave = (q1 + q2 + q3) / 3.0;
return ave;
}
int isfull()
{
return (last == MAX - 1);
}
int isempty()
{
if (last == -1)
return 1;
else
return 0;
}