Advertisement
Nayeemzaman

Untitled

Apr 10th, 2019
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.72 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include <stdlib.h>
  4.  
  5. typedef struct Node
  6. {
  7. char id[20];
  8. char phone[20];
  9. char dept[20];
  10. char bg[5];
  11. char adress[20];
  12. char name[20];
  13. struct Node *next;
  14. } node;
  15.  
  16. void insert_after(node *p,char name[20], char id[20], char dept[20], char bg[5], char cont[20])
  17. {
  18. while(p->next != NULL)
  19. {
  20. p = p->next;
  21. }
  22. p->next = (node *)malloc(sizeof(node));
  23.  
  24. strcpy(p->next->name,name);
  25. strcpy(p->next->id,id);
  26. strcpy(p->next->dept,dept);
  27. strcpy(p->next->bg,bg);
  28. strcpy(p->next->phone,cont);
  29. p->next->next = NULL;
  30. }
  31. void insert_first(node *p,char name[20], char id[20], char dept[20], char bg[5], char cont[20])
  32. {
  33. node *temp;
  34. temp = (node *)malloc(sizeof(node));
  35.  
  36. strcpy(temp->name,name);
  37. strcpy(temp->id,id);
  38. strcpy(temp->dept,dept);
  39. strcpy(temp->bg,bg);
  40. strcpy(temp->phone,cont);
  41.  
  42. temp->next = p->next;
  43. p->next = temp;
  44. }
  45. void edit_data(node *p,char id[])
  46. {
  47. int n,ct=0;
  48. char name1[20];
  49. char id1[20];
  50. char dept1[20];
  51. char bg1[20];
  52. char phone1[20];
  53. //node *temp = search(p,id);
  54. p = p->next;
  55. while(p != NULL)
  56. {
  57. if(strcmp(p->id,id) == 0)
  58. {
  59. printf("\n---------------------------------------------------------------\n");
  60. printf(" ****Student's Data To Edit**** ");
  61. printf("\n---------------------------------------------------------------\n");
  62.  
  63. printf("1.Student name : %s\n", p->name);
  64. printf("2.Student ID : %s\n", p->id);
  65. printf("3.Student Department : %s\n", p->dept);
  66. printf("4.Student Blood group: %s\n", p->bg);
  67. printf("5.Student Contact : %s\n\n",p->phone);
  68.  
  69. printf("Select your option to Edit: ");
  70.  
  71. scanf("%d",&n);
  72.  
  73. if(n == 1)
  74. {
  75. printf("Enter the name: ");
  76. scanf(" %[^\n]s",name1);
  77. strcpy(p->name,name1);
  78. }
  79. else if(n == 2)
  80. {
  81. printf("Enter the ID: ");
  82. scanf(" %s",id1);
  83. strcpy(p->id,id1);
  84. }
  85. else if(n == 3)
  86. {
  87. printf("Enter the Department: ");
  88. scanf("%s",dept1);
  89. strcpy(p->dept,dept1);
  90. }
  91. else if(n == 4)
  92. {
  93. printf("Enter the Blood Group: ");
  94. scanf("%s",bg1);
  95. strcpy(p->bg,bg1);
  96. }
  97. else if(n == 5)
  98. {
  99. printf("Enter the Contact: ");
  100. scanf("%s",phone1);
  101. strcpy(p->phone,phone1);
  102. }
  103. else
  104. {
  105. printf("\nError Selection!!\n");
  106. }
  107. }
  108. ct++;
  109. p = p -> next;
  110. }
  111. if(ct == 0)
  112. printf("\nElement not Found!\n");
  113.  
  114. }
  115.  
  116. int search(node *p, char id[20])
  117. {
  118. p = p->next;
  119. while(p != NULL)
  120. {
  121. if(strcmp(p->id,id) == 0)
  122. {
  123. printf("\n---------------------------------------------------------------\n");
  124. printf(" ****Displaying Searched Information**** ");
  125. printf("\n---------------------------------------------------------------\n");
  126.  
  127. printf("Student name : %s\n", p->name);
  128. printf("Student ID : %s\n", p->id);
  129. printf("Student Department : %s\n", p->dept);
  130. printf("Student Blood group: %s\n", p->bg);
  131. printf("Student Contact : %s\n\n",p->phone);
  132.  
  133. return;
  134. }
  135. p = p -> next;
  136. }
  137. printf("Sorry!Element not found.\n");
  138. return;
  139. }
  140. void blood_grp(node *p, char bg[5])
  141. {
  142. int ct=0;
  143. p = p->next;
  144. printf("\n---------------------------------------------------------------\n");
  145. printf(" ****Information of Desired Blood Group**** ");
  146. printf("\n---------------------------------------------------------------\n");
  147.  
  148. while(p != NULL)
  149. {
  150. if(strcmp(p->bg,bg)==0)
  151. {
  152. ct++;
  153. printf("\nStudent Name : %s\n",p->name);
  154. printf("Blood Group : %s\n",p->bg);
  155. printf("Contact number: %s\n",p->phone);
  156. }
  157. p = p->next;
  158. }
  159. if(ct == 0)
  160. printf("\nNot found\n");
  161. }
  162.  
  163. void dept_search(node *p, char dept[20])
  164. {
  165. int ct=0;
  166. p = p->next;
  167. printf("\n---------------------------------------------------------------\n");
  168. printf(" ****Department Wise Student Information**** ");
  169. printf("\n---------------------------------------------------------------\n");
  170.  
  171. while(p != NULL)
  172. {
  173. if(strcmp(p->dept,dept)==0)
  174. {
  175. ct++;
  176. printf("Student name : %s\n", p->name);
  177. printf("Student ID : %s\n", p->id);
  178. printf("Student Department : %s\n", p->dept);
  179. printf("Student Blood group: %s\n", p->bg);
  180. printf("Student Contact : %s\n\n", p->phone);
  181. }
  182. p = p->next;
  183. }
  184. if(ct == 0)
  185. printf("\nNot found\n");
  186. }
  187. void delete(node *p, char id[20])
  188. {
  189. int ct=0;
  190. node *temp;
  191. while(p->next != NULL)
  192. {
  193. if(strcmp(p->next->id,id) == 0)
  194. {
  195. ct++;
  196. temp = p->next;
  197. p->next = temp->next;
  198. free(temp);
  199. return 0;
  200. }
  201. p = p->next;
  202. }
  203. if(ct == 0)
  204. {
  205. printf("Element Not Found!!\n");
  206. }
  207. }
  208.  
  209. void display(node *p)
  210. {
  211. while(p -> next != NULL)
  212. {
  213. printf("Student name : %s\n", p->next->name);
  214. printf("Student ID : %s\n", p->next->id);
  215. printf("Student Department : %s\n", p->next->dept);
  216. printf("Student Blood group: %s\n", p->next->bg);
  217. printf("Student Contact : %s\n\n", p->next->phone);
  218. //printf("Student name: %s\n", p->next->name);
  219. p = p->next;
  220. }
  221. }
  222. void check_id(node *p,char id[])
  223. {
  224. while(p->next != NULL)
  225. {
  226. if(strcmp(p->next->id,id)==0)
  227. {
  228. printf("\nThis ID Already exists!\n");
  229. printf("Enter a new ID please! :- ");
  230. scanf("%s",id);
  231. }
  232. p = p->next;
  233. }
  234. }
  235.  
  236. int main()
  237. {
  238. system("color f0");
  239. int s;
  240. char q;
  241. char name[20];
  242. char id[20];
  243. char dept[20];
  244. char bg[20];
  245. char phone[20];
  246.  
  247. node *start = (node *)malloc(sizeof(node));
  248. start -> next = NULL;
  249.  
  250. while(1)
  251. {
  252.  
  253. printf("\n----------------------------------------------------------------------------\n");
  254. printf(" Welcome to Student Database Management System" );
  255. printf("\n----------------------------------------------------------------------------\n");
  256. printf("\tLog in as:\n");
  257. printf(" \n\t\t 1. ADMIN \n\n\t\t 0. EXIT");
  258. printf("\n----------------------------------------------------------------------------\n");
  259. printf(" " );
  260. printf("\n----------------------------------------------------------------------------\n");
  261. printf("\n\tEnter Choice:\t\t");
  262. int choice;
  263. scanf("%d",&choice);
  264. switch(choice)
  265. {
  266. case 1:
  267. while(1)
  268. {
  269. printf("\n\n1. Insert Student Data\n");
  270. printf("2. Delete Student Data\n");
  271. printf("3. Display\n");
  272. printf("4. Search\n");
  273. printf("5. Insert at first\n");
  274. printf("6. Edit Student information\n");
  275. printf("7. Search Blood Group\n");
  276. printf("8. Search Department\n");
  277. printf("9. Exit\n");
  278.  
  279. printf("\nEnter your choice: ");
  280.  
  281. scanf(" %c",&q);
  282.  
  283. switch(q)
  284. {
  285. case '1':
  286. system("CLS");
  287. printf("\nIf your want to EXIT press '0' else press any key\n");
  288. scanf("%d",&s);
  289.  
  290. if(s == 0)
  291. break;
  292. else
  293. {
  294. printf("\n---------------------------------------------------------------\n");
  295. printf(" Enter Student information ");
  296. printf("\n---------------------------------------------------------------\n");
  297. printf("Enter name: ");
  298. scanf(" %[^\n]s", name);
  299. printf("Enter ID: ");
  300. scanf("%s", id);
  301. check_id(start,id);
  302. printf("Enter Department: ");
  303. scanf(" %s", dept);
  304. printf("Enter Blood Group: ");
  305. scanf("%s", bg);
  306. printf("Enter contact: ");
  307. scanf("%s", phone);
  308.  
  309. insert_after(start,name,id,dept,bg,phone);
  310. }
  311. break;
  312.  
  313. case '2':
  314. system("CLS");
  315. printf("\nIf your want to EXIT press '0' else press any key\n");
  316. scanf("%d",&s);
  317.  
  318. if(s == 0)
  319. break;
  320. else
  321. {
  322. printf("Enter a Student's ID to Delete data: ");
  323. scanf("%s", id);
  324. delete(start,id);
  325. }
  326. break;
  327.  
  328. case '3':
  329. system("CLS");
  330. printf("\nIf your want to EXIT press '0' else press any key\n");
  331. scanf("%d",&s);
  332.  
  333. if(s == 0)
  334. break;
  335. else
  336. {
  337. printf("\n---------------------------------------------------------------\n");
  338. printf(" ****Student's personal information**** ");
  339. printf("\n---------------------------------------------------------------\n");
  340. display(start);
  341. }
  342. break;
  343. case '4':
  344. system("CLS");
  345. printf("\nIf your want to EXIT press '0' else press any key\n");
  346. scanf("%d",&s);
  347.  
  348. if(s == 0)
  349. break;
  350. else
  351. {
  352. printf("Enter the ID: ");
  353. scanf("%s",id);
  354. search(start,id);
  355. }
  356. break;
  357. case '5':
  358. system("CLS");
  359. printf("\nIf your want to EXIT press '0' else press any key\n");
  360. scanf("%d",&s);
  361.  
  362. if(s == 0)
  363. break;
  364. else
  365. {
  366. printf("\n\nEnter student information\n\n");
  367. printf("Enter name: ");
  368. scanf(" %[^\n]s", name);
  369. printf("Enter ID: ");
  370. scanf("%s", id);
  371. printf("Enter Department: ");
  372. scanf(" %[^\n]s", dept);
  373. printf("Enter Blood Group: ");
  374. scanf("%s", bg);
  375. printf("Enter contact: ");
  376. scanf("%s", phone);
  377.  
  378. insert_first(start,name,id,dept,bg,phone);
  379. }
  380. break;
  381. case '6':
  382. system("CLS");
  383. printf("\nIf your want to EXIT press '0' else press any key\n");
  384. scanf("%d",&s);
  385.  
  386. if(s == 0)
  387. break;
  388. else
  389. {
  390. printf("\nEnter the ID to Edit data: ");
  391. scanf("%s",id);
  392. edit_data(start,id);
  393. }
  394. break;
  395. case '7':
  396. system("CLS");
  397. printf("\nIf your want to EXIT press '0' else press any key\n");
  398. scanf("%d",&s);
  399.  
  400. if(s == 0)
  401. break;
  402. else
  403. {
  404. printf("\nEnter the desired Blood Group: ");
  405. scanf("%s",bg);
  406. blood_grp(start,bg);
  407. }
  408. break;
  409. case '8':
  410. system("CLS");
  411. printf("\nIf your want to EXIT press '0' else press any key\n");
  412. scanf("%d",&s);
  413.  
  414. if(s == 0)
  415. break;
  416. else
  417. {
  418. printf("\nEnter Department Name: ");
  419. scanf("%s",dept);
  420. dept_search(start,dept);
  421. }
  422. break;
  423. case '0':
  424. exit(0);
  425. default:
  426. system("CLS");
  427. printf("Invalid choice.Try again!\n");
  428. break;
  429. }
  430. }
  431. case 0:
  432. exit(0);
  433. }
  434.  
  435.  
  436. }
  437. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement