Advertisement
Mahfuz123

Algo_Project

Aug 10th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.30 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. #include<stdbool.h>
  5.  
  6.  
  7. char t_name[50];
  8. char t_mail[50];
  9. char t_pass[50];
  10. char t_id[50];
  11.  
  12. char st_name[50];
  13. char st_mail[50];
  14. char st_pass[50];
  15. char st_id[50];
  16.  
  17. int result[100] = {0};
  18. int st;
  19.  
  20. struct node
  21. {
  22. char name[50];
  23. char code[20];
  24. struct node *next;
  25.  
  26. }*head = NULL;
  27.  
  28. void total_courses()
  29. {
  30. struct node *new_node, *current;
  31.  
  32. new_node = (struct node*)malloc(sizeof(struct node));
  33. new_node->next = NULL;
  34.  
  35. strcpy(new_node->name, "Algorithm");
  36. strcpy(new_node->code, "CSE214");
  37.  
  38. head = new_node;
  39. current = new_node;
  40.  
  41. struct node *new_node1 = (struct node*)malloc(sizeof(struct node));
  42. new_node1->next = NULL;
  43.  
  44. strcpy(new_node1->name, "Data Communication");
  45. strcpy(new_node1->code, "CSE212");
  46.  
  47. current->next = new_node1;
  48. current = new_node1;
  49.  
  50. }
  51.  
  52. void t_course()
  53. {
  54.  
  55.  
  56. struct node *current = head;
  57.  
  58. printf("\nCourseList: \n\n");
  59. while(current != NULL)
  60. {
  61.  
  62. printf("Course Name: %s\n", current->name);
  63. printf("Course Code: %s\n\n", current->code);
  64.  
  65.  
  66. current = current->next;
  67. }
  68.  
  69. printf("\n\n");
  70.  
  71. }
  72.  
  73. void t_logIn()
  74. {
  75. char m[50], p[50];
  76.  
  77. printf("\n\n**** Log-In ****\n\n");
  78.  
  79. printf("Enter mail: ");
  80. scanf(" %[^\n]", m);
  81.  
  82. printf("\nEnter password: ");
  83. scanf(" %[^\n]", p);
  84.  
  85.  
  86. if( (strcmp(m, t_mail) != 0) && (strcmp(p, t_pass) != 0) )
  87. {
  88.  
  89. printf("\nError Data\n");
  90. t_logIn();
  91. }
  92. else
  93. {
  94.  
  95. printf("\n\t**** Log-In Successful ****\n\n");
  96. }
  97. }
  98.  
  99. void t_signUp()
  100. {
  101.  
  102. printf("\nEnter name: ");
  103. scanf(" %[^\n]", t_name);
  104. printf("\nEnter mail: ");
  105. scanf(" %[^\n]", t_mail);
  106. printf("\nEnter id: ");
  107. scanf(" %[^\n]", t_id);
  108. printf("\nEnter pass: ");
  109. scanf(" %[^\n]", t_pass);
  110.  
  111. printf("\n\t\t**** Sign-Up Successful ****\n");
  112.  
  113.  
  114. }
  115.  
  116. void s_logIn()
  117. {
  118. char m[50], p[50];
  119.  
  120. printf("\n\n**** Log-In ****\n\n");
  121.  
  122. printf("Enter mail: ");
  123. scanf(" %[^\n]", m);
  124.  
  125. printf("\nEnter password: ");
  126. scanf(" %[^\n]", p);
  127.  
  128.  
  129. if( (strcmp(m, st_mail) != 0) && (strcmp(p, st_pass) != 0) )
  130. {
  131.  
  132. printf("\nError Data\n");
  133. s_logIn();
  134. }
  135. else
  136. {
  137.  
  138. printf("\n\t**** Log-In Successful ****\n\n");
  139. }
  140. }
  141.  
  142. void s_signUp()
  143. {
  144. printf("\nEnter name: ");
  145. scanf(" %[^\n]", st_name);
  146. printf("\nEnter mail: ");
  147. scanf(" %[^\n]", st_mail);
  148. printf("\nEnter id: ");
  149. scanf(" %[^\n]", st_id);
  150. printf("\nEnter pass: ");
  151. scanf(" %[^\n]", st_pass);
  152.  
  153. printf("\n\t\t**** Sign-Up Successful ****\n");
  154. }
  155. void Student()
  156. {
  157. int n;
  158.  
  159. printf("\nNew to this site(1/0): ");
  160. scanf("%d", &n);
  161.  
  162. if(n == 1)
  163. {
  164.  
  165. s_signUp();
  166. s_logIn();
  167. }
  168. else
  169. {
  170.  
  171. s_logIn();
  172. }
  173. }
  174.  
  175. void Teacher()
  176. {
  177. int n;
  178.  
  179. printf("\nNew to this site(1/0): ");
  180. scanf("%d", &n);
  181.  
  182. if(n == 1)
  183. {
  184.  
  185. t_signUp();
  186. t_logIn();
  187. }
  188. else
  189. {
  190.  
  191. t_logIn();
  192. }
  193. }
  194.  
  195. void t_profile()
  196. {
  197. printf("\n\t*** Profile ***\n\n");
  198.  
  199. printf("\tName: %s\n", t_name);
  200. printf("\tEmail: %s\n", t_mail);
  201. printf("\tId : %s\n", t_id);
  202.  
  203. printf("\n\n");
  204. }
  205.  
  206. void st_profile()
  207. {
  208. printf("\n*** Profile ***\n\n");
  209.  
  210. printf("Name: %s\n", st_name);
  211. printf("Email: %s\n", st_mail);
  212. printf("Id : %s\n", st_id);
  213.  
  214. printf("\n\n");
  215. }
  216.  
  217.  
  218. void swap(int* a, int* b)
  219. {
  220. int t = *a;
  221. *a = *b;
  222. *b = t;
  223. }
  224.  
  225. int partition (int ara[], int low, int high)
  226. {
  227. int pivot = ara[high];
  228. int i = (low - 1);
  229.  
  230. for (int j = low; j <= high- 1; j++)
  231. {
  232.  
  233. if (ara[j] > pivot)
  234. {
  235. i++;
  236. swap(&ara[i], &ara[j]);
  237. }
  238. }
  239.  
  240. swap(&ara[i + 1], &ara[high]);
  241.  
  242. return (i + 1);
  243. }
  244.  
  245. void quickSort(int ara[], int low, int high)
  246. {
  247. if (low < high)
  248. {
  249.  
  250. int pi = partition(ara, low, high);
  251.  
  252. quickSort(ara, low, pi - 1);
  253. quickSort(ara, pi + 1, high);
  254. }
  255. }
  256.  
  257. void s_result()
  258. {
  259.  
  260. printf("\nResult : \n");
  261. for(int i=0; i<st; i++)
  262. {
  263.  
  264.  
  265. printf("Roll %d: %d\n", i+1, result[i]);
  266. }
  267.  
  268. printf("\n\n");
  269. }
  270.  
  271. int main()
  272. {
  273. char ch, c;
  274. int n, a = 0, b, d;
  275.  
  276. printf("\n\n\t\t\t****** Welcome to our College management system ******\n\n");
  277.  
  278. printf("\n\tChoose category: \n\n");
  279. printf("\t1. Teacher\n");
  280. printf("\t2. Student\n\n");
  281.  
  282. scanf("%d", &n);
  283.  
  284. if(n == 1)
  285. {
  286.  
  287. Teacher();
  288. a = 1;
  289. }
  290. else
  291. {
  292.  
  293. Student();
  294. }
  295.  
  296.  
  297. while(1)
  298. {
  299. if(a == 1)
  300. {
  301.  
  302. printf("\n\t***** Welcome to Teacher Portal *****\n\n");
  303. printf("\tChose an option:\n");
  304. printf("\t1.Profile\n\t2.Course\n\t3.Add result\n\t4.Show Student's result\n\t5.Exit\n");
  305.  
  306. scanf("%d", &b);
  307.  
  308. if(b == 1)
  309. {
  310.  
  311. t_profile();
  312. }
  313. else if(b == 2)
  314. {
  315. total_courses();
  316. t_course();
  317. }
  318. else if(b == 3)
  319. {
  320.  
  321. int i;
  322. printf("\nEnter the number of student in class: ");
  323. scanf("%d", &st);
  324.  
  325. printf("\nAdd result: \n");
  326.  
  327. for(i=0; i<st; i++)
  328. {
  329.  
  330. printf("Roll %d: ", i+1);
  331. scanf("%d", &result[i]);
  332. }
  333.  
  334. quickSort(result, 0, st-1);
  335.  
  336. FILE *fp;
  337.  
  338. fp = fopen("result.txt", "w");
  339.  
  340. for(i=0; i<st; i++)
  341. {
  342.  
  343. fprintf(fp, "Roll %d: %d\n",i+1, result[i]);
  344. }
  345.  
  346. fclose(fp);
  347.  
  348. }
  349. else if(b == 4)
  350. {
  351.  
  352. s_result();
  353. printf("\n");
  354. }
  355. else if(b == 5)
  356. {
  357.  
  358. break;
  359. }
  360. }
  361. else
  362. {
  363.  
  364.  
  365. printf("\n\t***** Welcome to Student Portal *****\n\n");
  366. printf("\tChose an option:\n");
  367. printf("\t1.Profile\n\t2.Course\n\t3.See result\n\t4.Exit\n");
  368. scanf("%d", &b);
  369.  
  370. if(b == 1)
  371. {
  372.  
  373. st_profile();
  374. }
  375. else if(b == 2)
  376. {
  377.  
  378. total_courses();
  379. t_course();
  380. }
  381. else if(b == 3)
  382. {
  383.  
  384. FILE *fp;
  385.  
  386. fp = fopen("result.txt", "r");
  387.  
  388. if(fp == NULL)
  389. {
  390.  
  391. printf("\n\nResult has not published Yet\n\n");
  392. }
  393. else
  394. {
  395.  
  396. int a;
  397.  
  398. while(a != EOF)
  399. {
  400.  
  401. a = fgetc(fp);
  402.  
  403. putchar((char)a);
  404. }
  405.  
  406. printf("\n\n");
  407. }
  408. }
  409. else if(b == 4)
  410. {
  411.  
  412. break;
  413. }
  414. }
  415. }
  416.  
  417. printf("\n\n\t\t********* Thank You :-) *********\n\n");
  418.  
  419. return 0;
  420. }
  421.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement