Hospital Management System_arrays
Hospital Management System_arrays
Code
#include <stdio.h>
#include <string.h>
char patientNames[MAX_PATIENTS][100];
int patientAges[MAX_PATIENTS];
char patientDiseases[MAX_PATIENTS][100];
char appointmentDates[MAX_APPOINTMENTS][20];
char appointmentTimes[MAX_APPOINTMENTS][10];
char appointmentPatientNames[MAX_APPOINTMENTS][100];
int main() {
int patientCount = 0;
int appointmentCount = 0;
int choice;
while (1) {
printf("5. Exit\n");
scanf("%d", &choice);
switch (choice) {
case 1:
// Add Patient
} else {
scanf("%d", &patientAges[patientCount]);
break;
case 2:
if (patientCount == 0) {
} else {
printf("\nList of Patients:\n");
printf("----------------------------\n");
break;
case 3:
// Add Appointment
} else if (patientCount == 0) {
appointmentDates[appointmentCount][strcspn(appointmentDates[appointmentCount],
"\n")] = '\0'; // Remove trailing newline
appointmentTimes[appointmentCount][strcspn(appointmentTimes[appointmentCount],
"\n")] = '\0'; // Remove trailing newline
appointmentPatientNames[appointmentCount]
[strcspn(appointmentPatientNames[appointmentCount], "\n")] = '\0'; // Remove trailing
newline
appointmentCount++;
break;
case 4:
if (appointmentCount == 0) {
} else {
printf("\nList of Appointments:\n");
printf("----------------------------\n");
break;
case 5:
return 0;
default:
return 0;
}
OUTPUT
Hospital Management System
1. Add Patient
3. Add Appointment
5. Exit
1. Add Patient
3. Add Appointment
5. Exit
1. Add Patient
3. Add Appointment
5. Exit
List of Patients:
Patient 1:
Name: arun
Age: 24
Disease: coma
----------------------------
Patient 2:
Name: aadi
Age: 24
Disease: ulcer
----------------------------
1. Add Patient
3. Add Appointment
5. Exit
1. Add Patient
3. Add Appointment
5. Exit
List of Appointments:
Appointment 1:
Date: 2024-11-24
Time: 21:23
----------------------------
1. Add Patient
3. Add Appointment
5. Exit
Enter your choice: 5
Algorithm:
Step 1: Initialization
Initialize:
Display options:
1. Add Patient
3. Add Appointment
5. Exit
o If patientCount > 0:
If patientCount > 0:
Increment appointmentCount.
o If appointmentCount > 0:
If choice == 5 (Exit):
If choice is invalid:
Step 5: Repeat
Go back to Step 2 to display the menu again, unless the user chooses to exit.
Pseudocode:
Initialize patientCount = 0, appointmentCount = 0
Repeat:
Display the menu with options (Add Patient, View All Patients, Add Appointment, View All
Appointments, Exit)
If choice == 1:
Increment patientCount
Else:
Else if choice == 2:
If patientCount > 0:
Else:
Else if choice == 3:
If patientCount > 0:
Increment appointmentCount
Else:
Else if choice == 4:
If appointmentCount > 0:
Else:
Else if choice == 5:
Exit program
Else:
End Repeat