Advertisement
asiffff

Untitled

Mar 28th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.13 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <windows.h>
  5. #include <conio.h>
  6. struct student
  7. {
  8. int id;
  9. int cla;
  10. long int p_num;
  11. char group[20];
  12. char name[20];
  13. char gender[20];
  14. double bangla,english,math,physics,chemistry,biology;
  15.  
  16. struct student *next,*prev;
  17. }*start=NULL,*end=NULL,*current;
  18.  
  19. void create()
  20. {
  21. if(start==NULL && end==NULL)
  22. {
  23. struct student *new_node;
  24. new_node=(struct student*)malloc(1*sizeof(struct student));
  25. printf("\nEnter Name:\n");
  26. //scanf("%s",&new_node->name);
  27. char e[20];
  28. gets(e);
  29. //strcpy(new_node->name,e);
  30. printf("Enter Class:");
  31. scanf("%d",&new_node->cla);
  32. printf("Enter ID:\n");
  33. scanf("%d",&new_node->id);
  34. printf("Enter Group:\n");
  35. scanf("%s",&new_node->group);
  36. printf("Enter Gender:\n");
  37. scanf("%s",&new_node->gender);
  38. printf("Enter Parents Phone Number:\n");
  39. scanf("%ld",&new_node->p_num);
  40. new_node->next=NULL;
  41. new_node->prev=NULL;
  42. start=new_node;
  43. end=new_node;
  44. current=new_node;
  45. system("cls");
  46. }
  47. else
  48. {
  49. struct student *new_node;
  50. new_node=(struct student*)malloc(1*sizeof(struct student));
  51. printf("\nEnter Name:\n");
  52. scanf("%s",&new_node->name);
  53. printf("Enter Class:");
  54. scanf("%d",&new_node->cla);
  55. printf("Enter ID:");
  56. scanf("%d",&new_node->id);
  57. printf("Enter Group:\n");
  58. scanf("%s",&new_node->group);
  59. printf("Enter Gender:\n");
  60. scanf("%s",&new_node->gender);
  61. printf("Enter Parents Phone Number:\n");
  62. scanf("%ld",&new_node->p_num);
  63. new_node->next=NULL;
  64. new_node->prev=NULL;
  65. current->next=new_node;
  66. new_node->prev=current;
  67. end=new_node;
  68. current=new_node;
  69. system("cls");
  70. }
  71. }
  72. void dis()
  73. {
  74. struct student *c;
  75. c=start;
  76. while(c!=NULL)
  77. {
  78. printf("\n Name : %s ID : %d\n Gender : %s Group : %s Parents Phone Number: %ld\n",c->name,c->id,c->gender,c->group,c->p_num);
  79. c=c->next;
  80. }
  81. }
  82.  
  83. struct teacher
  84. {
  85. int id;
  86. char name[20];
  87. char gender[20];
  88. char group[20];
  89. long int phnum;
  90. struct teacher *next,*prev;
  91.  
  92. }*start1=NULL,*end1=NULL,*current1;
  93. void create1()
  94. {
  95. struct teacher *new_node;
  96. if(start1==NULL && end1==NULL)
  97. {
  98. new_node=(struct teacher*)malloc(1*sizeof(struct teacher));
  99. printf("\nEnter the number of teacher id:\n");
  100. scanf("%d",&new_node->id);
  101. printf("\nEnter your group:\n");
  102. scanf("%s",&new_node->group);
  103. printf("\nEnter the teacher name:\n");
  104. scanf("%s",&new_node->name);
  105. printf("\nEnter the teacher gender:\n");
  106. scanf("%s",&new_node->gender);
  107. printf("\nEnter the teacher phone number:\n");
  108. scanf("%ld",&new_node->phnum);
  109. new_node->next=NULL;
  110. new_node->prev=NULL;
  111.  
  112. start1=new_node;
  113. end1=new_node;
  114. current1=new_node;
  115. system("cls");
  116.  
  117. }
  118. else
  119. {
  120. new_node=(struct teacher*)malloc(1*sizeof(struct teacher));
  121. printf("\nEnter Teacher ID:\n");
  122. scanf("%d",&new_node->id);
  123. printf("\nEnter Teacher Group:\n");
  124. scanf("%s",&new_node->group);
  125. printf("\nEnter the teacher name:\n");
  126. scanf("%s",&new_node->name);
  127. printf("\nEnter the teacher gender:\n");
  128. scanf("%s",&new_node->gender);
  129. printf("\nEnter the teacher phone number:\n");
  130. scanf("%ld",&new_node->phnum);
  131. new_node->next=NULL;
  132. new_node->prev=NULL;
  133.  
  134. current1->next=new_node;
  135. new_node->prev=current1;
  136. current1=new_node;
  137. end1=new_node;
  138. system("cls");
  139. }
  140.  
  141.  
  142.  
  143. }
  144. int search(int a,int y,int y1)
  145. {
  146. struct student *c;
  147. struct teacher *c1;
  148. int po=0;
  149. if(y==1 && y1==0)
  150. {
  151. c=start;
  152. while(c!=NULL)
  153. {
  154. po++;
  155. if(c->id==a)
  156. {
  157. return po;
  158. }
  159. c=c->next;
  160. }
  161. return -1;
  162. }
  163. else if(y==2 && y1==0)
  164. {
  165. c1=start1;
  166. while(c1!=NULL)
  167. {
  168. po++;
  169. if(c1->id==a)
  170. {
  171. return po;
  172. }
  173. c1=c1->next;
  174. }
  175. return -1;
  176.  
  177. }
  178. else
  179. {
  180. c=start;
  181. while(c!=NULL)
  182. {
  183. po++;
  184. if(c->cla==a && c->id==y1)
  185. {
  186. return po;
  187. }
  188. c=c->next;
  189. }
  190. return -1;
  191.  
  192. }
  193. }
  194. void dis1()
  195. {
  196. struct teacher *c;
  197. c=start1;
  198. while(c!=NULL)
  199. {
  200. printf("\nTeacher ID:%d\n",c->id);
  201. printf("Your group:%s\n",c->group);
  202. printf("Teacher Name:%s\n",c->name);
  203. printf("Teacher Gender:%s\n",c->gender);
  204. printf("Teacher Phone number:%ld\n",c->phnum);
  205. c=c->next;
  206. }
  207. }
  208. void result()
  209. {
  210. int cls,id;
  211. printf("\nEnter Class and ID NO:\n");
  212. scanf("%d %d",&cls,&id);
  213. struct student *n,*c;
  214. c=start;
  215. int po=0;
  216. while(c!=NULL)
  217. {
  218. po++;
  219. if(c->cla==cls && c->id==id)
  220. {
  221. break;
  222. }
  223. c=c->next;
  224. }
  225.  
  226.  
  227. }
  228.  
  229. int main()
  230. {
  231. int x,y;
  232. while(1)
  233. {
  234. printf("1.Enter Student Details.\n2.View All Student Details\n3.Search Student Details.\n");
  235. printf("4.Enter Teacher Details.\n5.View All Teacher Details\n6.Search Teacher Details.\n");
  236. scanf("%d",&x);
  237. switch(x)
  238. {
  239. case 1:
  240. {
  241. create();
  242. break;
  243. }
  244. case 2:
  245. {
  246. dis();
  247. getch();
  248. system("cls");
  249. break;
  250. }
  251. case 3:
  252. {
  253. y=1;
  254. printf("Enter Id:\n");
  255. int n;
  256. scanf("%d",&n);
  257. int pos = search(n,y,0);
  258. if(pos==-1)
  259. {
  260. printf("\n Not Found\n");
  261. }
  262. else
  263. {
  264. struct student *b;
  265. b=start;
  266. int j;
  267. for(j=0; j<pos-1; j++)
  268. {
  269. b=b->next;
  270. }
  271. printf("\nName:%s ID:%d\n Gender:%s Group:%s Parents Number: %ld\n",b->name,b->id,b->gender,b->group,b->p_num);
  272. getch();
  273. system("cls");
  274. }
  275. break;
  276. }
  277. case 4:
  278. {
  279. create1();
  280. break;
  281. }
  282. case 5:
  283. {
  284. dis1();
  285. getch();
  286. system("cls");
  287. break;
  288. }
  289. case 6:
  290. {
  291. printf("Enter Id:\n");
  292. int k;
  293. y=2;
  294. scanf("%d",&k);
  295. int pos1 = search(k,y,0);
  296. if(pos1==-1)
  297. {
  298. printf("\n Not Found\n");
  299. }
  300. else
  301. {
  302. struct teacher *c;
  303. c=start1;
  304. int j;
  305. for(j=0; j<pos1-1; j++)
  306. {
  307. c=c->next;
  308. }
  309. printf("\nTeacher ID:%d\n",c->id);
  310. printf("Your group:%s\n",c->group);
  311. printf("Teacher Name:%s\n",c->name);
  312. printf("Teacher Gender:%s\n",c->gender);
  313. printf("Teacher Phone number:%ld\n",c->phnum);
  314. getch();
  315. system("cls");
  316.  
  317. }
  318. break;
  319. }
  320. case 7:
  321. {
  322. int x1,y1;
  323. printf("Enter Class: ");
  324. scanf("%d",&x1);
  325. printf("Enter Student ID: ");
  326. scanf("%d",&y1);
  327. int k;
  328. //y=2;
  329. int pos1 = search(x1,0,y1);
  330. if(pos1==-1)
  331. {
  332. printf("\n Not Found\n");
  333. }
  334. else
  335. {
  336. struct student *c;
  337. c=start;
  338. int j;
  339. for(j=0; j<pos1-1; j++)
  340. {
  341. c=c->next;
  342. }
  343. printf("Bangla :\n");
  344. scanf("%lf",&c->bangla);
  345. printf("English:\n");
  346. scanf("%lf",&c->english);
  347. printf("Math:\n");
  348. scanf("%lf",&c->math);
  349. printf("Physics:\n");
  350. scanf("%lf",&c->physics);
  351. printf("Chemistry:\n");
  352. scanf("%lf",&c->chemistry);
  353. printf("Biology:\n");
  354. scanf("%lf",&c->biology);
  355. //getch();
  356. system("cls");
  357.  
  358. }
  359. break;
  360. }
  361. case 8:
  362. {
  363. int x1,y1;
  364. printf("Enter Class: ");
  365. scanf("%d",&x1);
  366. printf("Enter Student ID: ");
  367. scanf("%d",&y1);
  368. int k;
  369. //y=2;
  370. int pos1 = search(x1,0,y1);
  371. if(pos1==-1)
  372. {
  373. printf("\n Not Found\n");
  374. }
  375. else
  376. {
  377. struct student *c;
  378. c=start;
  379. int j;
  380. for(j=0; j<pos1-1; j++)
  381. {
  382. c=c->next;
  383. }
  384. printf("Bangla : %.2lf\n",c->bangla);
  385. //scanf("%lf",&c->bangla);
  386. printf("English: %.2lf\n",c->english);
  387. //scanf("%lf",&c->english);
  388. printf("Math: %.2lf\n",c->math);
  389. //scanf("%lf",&c->math);
  390. printf("Physics: %.2lf\n",c->physics);
  391. //scanf("%lf",&c->physics);
  392. printf("Chemistry: %.2lf\n",c->chemistry);
  393. //scanf("%lf",&c->chemistry);
  394. printf("Biology: %.2lf\n",c->biology);
  395. //scanf("%lf",c->biology);
  396. getch();
  397. system("cls");
  398.  
  399. }
  400.  
  401.  
  402. }
  403.  
  404. }
  405. }
  406. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement