fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #define MAX_PATIENTS 10
  6.  
  7. // Structure to store patient details
  8. typedef struct {
  9. char name[50];
  10. int age;
  11. char symptoms[100];
  12. int severity; // Higher value means more severe
  13. int priority;
  14. } Patient;
  15.  
  16. // Function to assign priority based on severity
  17. void assignPriority(Patient patients[], int n) {
  18. for (int i = 0; i < n; i++) {
  19. patients[i].priority = patients[i].severity; // Priority is based on severity
  20. }
  21. }
  22.  
  23. // Function to sort patients based on priority (Descending order)
  24. void sortPatientsByPriority(Patient patients[], int n) {
  25. for (int i = 0; i < n - 1; i++) {
  26. for (int j = 0; j < n - i - 1; j++) {
  27. if (patients[j].priority < patients[j + 1].priority) {
  28. Patient temp = patients[j];
  29. patients[j] = patients[j + 1];
  30. patients[j + 1] = temp;
  31. }
  32. }
  33. }
  34. }
  35.  
  36. // Function to predict health condition based on symptoms
  37. void predictDisease(Patient *p) {
  38. printf("\nPredicted Condition for %s:\n", p->name);
  39.  
  40. if (strstr(p->symptoms, "fever") && strstr(p->symptoms, "cough")) {
  41. printf("Possible Disease: Flu or COVID-19\n");
  42. } else if (strstr(p->symptoms, "chest pain") || strstr(p->symptoms, "shortness of breath")) {
  43. printf("Possible Disease: Heart Issue\n");
  44. } else if (strstr(p->symptoms, "headache") && strstr(p->symptoms, "dizziness")) {
  45. printf("Possible Disease: Migraine or High BP\n");
  46. } else {
  47. printf("General Check-up Recommended.\n");
  48. }
  49. }
  50.  
  51. // Function to display patient details after scheduling
  52. void displayPatients(Patient patients[], int n) {
  53. printf("\nScheduled Patients List (Based on Priority):\n");
  54. printf("------------------------------------------------\n");
  55. printf("Priority | Name | Age | Symptoms | Severity\n");
  56. printf("------------------------------------------------\n");
  57.  
  58. for (int i = 0; i < n; i++) {
  59. printf("%8d | %-10s | %3d | %-20s | %8d\n",
  60. patients[i].priority, patients[i].name, patients[i].age, patients[i].symptoms, patients[i].severity);
  61. predictDisease(&patients[i]);
  62. }
  63. }
  64.  
  65. int main() {
  66. int n;
  67. printf("Enter the number of patients (max %d): ", MAX_PATIENTS);
  68. scanf("%d", &n);
  69. if (n > MAX_PATIENTS) {
  70. printf("Maximum number of patients is %d. Exiting...\n", MAX_PATIENTS);
  71. return 1;
  72. }
  73.  
  74. Patient patients[MAX_PATIENTS];
  75.  
  76. // Input patient details
  77. for (int i = 0; i < n; i++) {
  78. printf("\nEnter details for patient %d:\n", i + 1);
  79. printf("Name: ");
  80. scanf(" %[^\n]s", patients[i].name);
  81. printf("Age: ");
  82. scanf("%d", &patients[i].age);
  83. printf("Symptoms (comma-separated): ");
  84. scanf(" %[^\n]s", patients[i].symptoms);
  85. printf("Severity (1-10, 10 = Critical): ");
  86. scanf("%d", &patients[i].severity);
  87. }
  88.  
  89. // Assign priority based on severity
  90. assignPriority(patients, n);
  91.  
  92. // Sort patients based on priority
  93. sortPatientsByPriority(patients, n);
  94.  
  95. // Display scheduled patients
  96. displayPatients(patients, n);
  97.  
  98. return 0;
  99. }
  100.  
Success #stdin #stdout 0s 5300KB
stdin
Standard input is empty
stdout
Enter the number of patients (max 10): 
Scheduled Patients List (Based on Priority):
------------------------------------------------
Priority | Name       | Age | Symptoms            | Severity
------------------------------------------------