-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSDB.c
More file actions
137 lines (126 loc) · 2.63 KB
/
SDB.c
File metadata and controls
137 lines (126 loc) · 2.63 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
#include "SDB.h"
uint8 count_entries=0;
int main(void)
{
uint32 Student_ID,Student_Year,subjects[3];
uint32 grades[3];
static uint8 count=0;
uint8 IsFull,UsedSize,add_entry,read_entry,existence;
uint32 choice;
puts("Database Module,Welcome :)\n\
Note: The maximum size of the database is 10 entries only.");
while(1)
{
printf("What do you want to do ?\nAdd an entry ? (press 1)\nRead an entry ? (press 2)\
\nRemove an entry ? (press 3)\nCheck existence of an entry ? (press 4)\nView list of entries ? (press 5)\
\nExit ? (press 6)\nyour choice : ");
scanf("%d",&choice);
switch(choice)
{
case (1) ://Add an entry
{
UsedSize=SDB_GetUsedSize();
printf("The used size of the database = %d\n",UsedSize);
IsFull=SDB_IsFull();
if (IsFull==0)//not full
{
printf("Enter your ID : ");
scanf("%d",&Student_ID);
printf("Enter your Year : ");
scanf("%d",&Student_Year);
for (int index = 0; index < 3; ++index)
{
printf("Enter the ID of course %d : ",index+1);
scanf("%d",&subjects[index]);
printf("Enter the grade of course %d (out of 100): ",index+1);
scanf("%d",&grades[index]);
while(grades[index]>100)
{
printf("Invalid grade\n");
printf("Enter the grade of course %d (out of 100): ",index+1);
scanf("%d",&grades[index]);
}
}
add_entry=SDB_AddEntry(Student_ID, Student_Year, &subjects[0], &grades[0]);
if (add_entry==1)//entry created
{
printf("The entry is created successfully\n");
++count;
count_entries=count;
}
else//entry not created
{
printf("The entry is not created\n");
break;
}
}
else//full
{
printf("The database is full.\nNote: The maximum size of the database is 10 entries only.\n");
}
break;
}
case (2) ://Read an entry
{
uint32 id;
printf("Enter your ID : ");
scanf("%d",&id);
read_entry=SDB_ReadEntry(id);
if (read_entry==1)
{
printf("Your ID exist\n");
}
else
{
printf("Your ID not exist\n");
}
break;
}
case (3) ://Remove an entry
{
uint32 id;
printf("Enter your ID : ");
scanf("%d",&id);
SDB_DeleteEntry(id);
break;
}
case (4) ://Check existence of an entry
{
uint32 id;
printf("Enter your ID : ");
scanf("%d",&id);
existence=SDB_IsIdExist(id);
if (existence==1)
{
printf("Your ID exist\n");
}
else
{
printf("Your ID not exist\n");
}
break;
}
case (5) ://View list of entries
{
SDB_GetIdList();
break;
}
case (6) ://exit
{
break;
}
default :
{
printf("Invalid choice\n");
break;
}
}
if(choice==6)
{
break;
}
else{}
puts("");
}
return 0;
}