fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #define MAX 100
  5.  
  6. typedef struct {
  7. int id;
  8. char studentID[20];
  9. char name[50];
  10. char department[30];
  11. char message[200];
  12. int resolved;
  13. char solution[200];
  14. } Complaint;
  15.  
  16. Complaint complaints[MAX];
  17. int count = 0;
  18. //function remove new line
  19.  
  20. void trimNewline(char *s)
  21. {
  22. s[strcspn(s, "\n")] = '\0';
  23. }
  24. //department chack
  25.  
  26. int validDepartment(const char *dept)
  27. {
  28. return (strcmp(dept, "CSE") == 0 || strcmp(dept, "EEE") == 0 || strcmp(dept, "CCE") == 0 || strcmp(dept, "Other") == 0);
  29. }
  30. //1)complaint add function
  31.  
  32. void addComplaint(void) {
  33. if (count >= MAX)
  34. {
  35. puts("Complaint list is full!");
  36. return;
  37. }
  38. getchar();
  39.  
  40. complaints[count].id = count + 1;
  41.  
  42. printf("Student ID : ");
  43. fgets(complaints[count].studentID, sizeof(complaints[count].studentID), stdin);
  44. trimNewline(complaints[count].studentID);
  45.  
  46. while(1) {
  47. printf("Department (CSE/EEE/CCE/Other): ");
  48. fgets(complaints[count].department, sizeof(complaints[count].department), stdin);
  49. trimNewline(complaints[count].department);
  50.  
  51. if (validDepartment(complaints[count].department))
  52. break;
  53. else
  54. printf(" Invalid department! Please enter one of: CSE, EEE, CCE, Other.\n");
  55. }
  56.  
  57. char anon;
  58. printf("Do you want to keep your name anonymous? (Y/N): ");
  59. scanf(" %c", &anon);
  60. getchar();
  61.  
  62. if (anon == 'Y' || anon == 'y') {
  63. strcpy(complaints[count].name, "Anonymous");
  64. } else {
  65. printf("Your Name : ");
  66. fgets(complaints[count].name, sizeof(complaints[count].name), stdin);
  67. trimNewline(complaints[count].name);
  68. }
  69.  
  70. printf("Complaint message : ");
  71. fgets(complaints[count].message, sizeof(complaints[count].message), stdin);
  72. trimNewline(complaints[count].message);
  73.  
  74. complaints[count].resolved = 0;
  75. complaints[count].solution[0] = '\0';
  76.  
  77. printf(" Complaint submitted with ID #%d\n", complaints[count].id);
  78. count++;
  79. }
  80. //2)view all function
  81. void viewAll(void) {
  82. if (count == 0)
  83. {
  84. puts("No complaints yet.");
  85. return;
  86. }
  87.  
  88. puts("\n--- Pending Complaints ---");
  89. for (int i = 0; i < count; i++) {
  90. if (complaints[i].resolved==0) {
  91. printf("\nID : %d\n", complaints[i].id);
  92.  
  93. if (strcmp(complaints[i].name, "Anonymous") == 0) {
  94. printf("Student ID: Hidden\n");
  95. printf("Name : Anonymous\n");
  96. } else {
  97. printf("Student ID: %s\n", complaints[i].studentID);
  98. printf("Name : %s\n", complaints[i].name);
  99. }
  100.  
  101. printf("Dept : %s\n", complaints[i].department);
  102. printf("Message : %s\n", complaints[i].message);
  103. }
  104. }
  105.  
  106. puts("\n--- Resolved Complaints ---");
  107. for (int i = 0; i < count; i++) {
  108. if (complaints[i].resolved) {
  109. printf("\nID : %d\n", complaints[i].id);
  110.  
  111. if (strcmp(complaints[i].name, "Anonymous") == 0) {
  112. printf("Student ID: Hidden\n");
  113. printf("Name : Anonymous\n");
  114. } else {
  115. printf("Student ID: %s\n", complaints[i].studentID);
  116. printf("Name : %s\n", complaints[i].name);
  117. }
  118.  
  119. printf("Dept : %s\n", complaints[i].department);
  120. printf("Message : %s\n", complaints[i].message);
  121. printf("Solution : %s\n",
  122. complaints[i].solution[0] ? complaints[i].solution : "(no details)");
  123. }
  124. }
  125. }
  126. //3)view department complaints
  127. void viewDepartmentComplaints(void)
  128. {
  129. if (count == 0) { puts("No complaints yet."); return; }
  130.  
  131. char dept[30];
  132. getchar(); // newline remove
  133. while(1) {
  134. printf("Enter department to view (CSE/EEE/CCE/Other): ");
  135. fgets(dept, sizeof(dept), stdin);
  136. trimNewline(dept);
  137. if (validDepartment(dept))
  138. break;
  139. else
  140. printf(" Invalid department! Please enter one of: CSE, EEE, CCE, Other.\n");
  141. }
  142.  
  143. int found = 0;
  144. printf("\n--- Complaints for %s Department ---\n", dept);
  145. for (int i = 0; i < count; i++) {
  146. if (strcmp(complaints[i].department, dept) == 0) {
  147. found = 1;
  148. printf("\nID : %d\n", complaints[i].id);
  149. if (strcmp(complaints[i].name, "Anonymous") == 0) {
  150. printf("Student ID: Hidden\n");
  151. printf("Name : Anonymous\n");
  152. } else {
  153. printf("Student ID: %s\n", complaints[i].studentID);
  154. printf("Name : %s\n", complaints[i].name);
  155. }
  156. printf("Status : %s\n", complaints[i].resolved ? "Resolved" : "Pending");
  157. printf("Message : %s\n", complaints[i].message);
  158. if (complaints[i].resolved) {
  159. printf("Solution : %s\n", complaints[i].solution[0] ? complaints[i].solution : "(no details)");
  160. }
  161. }
  162. }
  163. if (!found) {
  164. printf("No complaints found for department %s.\n", dept);
  165. }
  166. }
  167. //4)solvecommplaint function
  168. void solveComplaint(void) {
  169. if (count == 0) {
  170. puts("No complaints to solve.");
  171. return;
  172. }
  173.  
  174. int id;
  175. printf("Enter complaint ID to mark solved: ");
  176. if (scanf("%d", &id) != 1)
  177. {
  178. puts("Invalid input.");
  179. return;
  180. }
  181. getchar();
  182.  
  183. if (id < 1 || id > count)
  184. {
  185. puts(" Invalid ID.");
  186. return;
  187. }
  188. if (complaints[id - 1].resolved)
  189. {
  190. puts("Already resolved.");
  191. return;
  192. }
  193.  
  194. printf("Enter solution description (optional): ");
  195. fgets(complaints[id - 1].solution,
  196. sizeof(complaints[id - 1].solution), stdin);
  197. trimNewline(complaints[id - 1].solution);
  198.  
  199. complaints[id - 1].resolved = 1;
  200. puts("Complaint marked as solved.");
  201. }
  202. //5) notice board er function
  203. void noticeBoard(void) {
  204. if (count == 0) {
  205. puts("No complaints yet.");
  206. return;
  207. }
  208.  
  209. puts("\n==== NOTICE BOARD ====");
  210.  
  211. const char *departments[] = {"CSE", "EEE", "CCE", "Other"};
  212. int numDept = 4;
  213.  
  214. for (int d = 0; d < numDept; d++) {
  215. const char *dept = departments[d];
  216. int pendingCount = 0, resolvedCount = 0;
  217.  
  218. // Check complaints count by status
  219. for (int i = 0; i < count; i++) {
  220. if (strcmp(complaints[i].department, dept) == 0) {
  221. if (!complaints[i].resolved)
  222. pendingCount++;
  223. else
  224. resolvedCount++;
  225. }
  226. }
  227.  
  228. if (pendingCount == 0 && resolvedCount == 0) {
  229. printf("\n-- %s Department --\nNo complaints found.\n", dept);
  230. continue;
  231. }
  232.  
  233. printf("\n-- %s Department --\n", dept);
  234.  
  235. if (pendingCount > 0) {
  236. puts("Pending Complaints:");
  237. for (int i = 0; i < count; i++) {
  238. if (strcmp(complaints[i].department, dept) == 0 && !complaints[i].resolved)
  239. {
  240. printf("#%d | %s\n", complaints[i].id, complaints[i].message);
  241.  
  242. }
  243. }
  244. } else
  245. {
  246. puts("No pending complaints.");
  247. }
  248.  
  249. if (resolvedCount > 0) {
  250. puts("Resolved Complaints:");
  251. for (int i = 0; i < count; i++)
  252. {
  253. if (strcmp(complaints[i].department, dept) == 0 && complaints[i].resolved)
  254. {
  255. printf("#%d | %s\n", complaints[i].id, complaints[i].message);
  256. }
  257. }
  258. } else {
  259. puts("No resolved complaints.");
  260. }
  261. }
  262. }
  263.  
  264. int main(void) {
  265. int choice;
  266. while (1) {
  267. puts("\n===== Complaint Routing System =====");
  268. puts("1. Submit Complaint");
  269. puts("2. View All Complaints");
  270. puts("3. View Complaints by Department");
  271. puts("4. Solve Complaint");
  272. puts("5. Notice Board");
  273. puts("6. Exit");
  274. printf("Enter choice: ");
  275. if (scanf("%d", &choice) != 1) break;
  276.  
  277. switch (choice) {
  278. case 1: addComplaint(); break;
  279. case 2: viewAll(); break;
  280. case 3: viewDepartmentComplaints(); break;
  281. case 4: solveComplaint(); break;
  282. case 5: noticeBoard(); break;
  283. case 6: puts("Goodbye!"); return 0;
  284. default: puts("Invalid choice!");
  285. }
  286. }
  287. return 0;
  288. }
  289.  
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
===== Complaint Routing System =====
1. Submit Complaint
2. View All Complaints
3. View Complaints by Department
4. Solve Complaint
5. Notice Board
6. Exit
Enter choice: