In: Computer Science
A Private Poly Clinic in City wish to develop software to automate their Patient Monitoring system for storing the details of the patients visited the clinic. Develop a system to meet the following requirements:
|
Patient Id |
Fees in (OMR) |
Gender |
|
P001 |
15 |
M |
|
P002 |
10 |
F |
|
P003 |
20 |
M |
|
P004 |
8 |
F |
|
P005 |
12 |
M |
Read the fees paid by ‘N’ patients into a one dimensional array in random order. Develop an algorithm, flow chart and write a C program to arrange the fees read in ascending order. Display the result with appropriate statements.
Screenshot of the code:


Code ( Text Format )
#include <stdio.h>
typedef struct Patient {
char id[10];
int fees;
char gender;
} Patient;
void swapPatients(Patient *xp, Patient *yp)
{
Patient temp = *xp;
*xp = *yp;
*yp = temp;
}
void SortPatients(Patient arr[], int n)
{
int i, j, min_idx;
for (i = 0; i < n-1; i++)
{
min_idx = i;
for (j = i+1; j < n; j++)
if (arr[j].fees < arr[min_idx].fees)
min_idx = j;
swapPatients(&arr[min_idx], &arr[i]);
}
}
int main()
{
Patient patients[100];
int n, i;
printf("Enter total number of patients");
scanf("%d", &n);
for(i = 0 ; i < n ; i++)
{
printf("Enter the details of patient %d:\n", i+1);
printf("Enter the ID of the Patient: ");
scanf("%s" , patients[i].id);
printf("Enter the Fees of the Patient: ");
scanf("%d" , &patients[i].fees);
printf("Enter the Gender of the Patient: ");
scanf("%s" , &patients[i].gender);
}
SortPatients(patients, n);
printf("Details with fees in ascending order are: \n");
printf("Pateint Id Fees Gender");
for (i = 0; i < n; i++){
printf("\n %s %d %c", patients[i].id, patients[i].fees, patients[i].gender);
}
}
Sample Output :
Input :

Output :

Flow Chart:

Algorithm :
Step 1 : Start
Step 2 : Enter the number of patients
Step 3 : Enter the Details of Patients ( Read Patient ID , Fees and Gender )
Step 4 : Do sorting in ascending order according to fees
Step 5 : Print the final sorted details of the Patients
Step 6 : End