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