Norman works as a pharmacist at the District Health Clinic.

Berikut ini adalah pertanyaan dari snrainnz pada mata pelajaran TI untuk jenjang Sekolah Menengah Atas

Norman works as a pharmacist at the District Health Clinic. Every day he had to prepare a report of the list of diabetic patients receiving insulin medication. He developed a program that could record his patient ID and treatment type. The system can calculate and display the total number and average percentage of diabetic patients receiving insulin treatment. Finally, the program can perform a linear search and display a list of patients based on the treatment type code. Otherwise, display "You entered an invalid treatment code". The program output is shown in the sample output.Sample output 1:

********* DISTRICT HEALTH CLINIC ********* ****Diabetes Treatment Report ****

Please enter the number of patients:5

**** TREATMENT TYPE ****

Insulin 1

Metaformin M

Enter patient ID: 2233 Treatment Type: M

Enter patient ID: 3344 Treatment Type: M

Enter patient ID: 4455

Treatment Type: M

Enter patient ID: 5566

Treatment Type: I

Enter patient ID: 6677 Treatment Type: H

The total number of insulin patients: 1 The percentage of insulin patients 20.0%

Enter option to print a list-> I for Insulin, M for Metaformin: I

Patient ID

Treatment Type I

5566​

Jawaban dan Penjelasan

Berikut ini adalah pilihan jawaban terbaik dari pertanyaan diatas.

To generate the report, Norman can use the following program:

```

#include <stdio.h>

int main() {

int n, i, insulin = 0;

char treatment;

float percentage;

printf("********* DISTRICT HEALTH CLINIC ********* ****Diabetes Treatment Report ****\n");

printf("Please enter the number of patients:");

scanf("%d", &n);

printf("\n**** TREATMENT TYPE ****\n");

printf("Insulin 1\nMetaformin M\n");

int patient_id[n];

char treatment_type[n];

for (i = 0; i < n; i++) {

printf("\nEnter patient ID: ");

scanf("%d", &patient_id[i]);

printf("Treatment Type: ");

scanf(" %c", &treatment_type[i]);

if (treatment_type[i] == '1') {

insulin++;

} else if (treatment_type[i] != 'M') {

printf("You entered an invalid treatment code\n");

i--;

}

}

percentage = ((float)insulin / n) * 100;

printf("\nThe total number of insulin patients: %d The percentage of insulin patients %.1f%%\n", insulin, percentage);

printf("\nEnter option to print a list-> I for Insulin, M for Metaformin: ");

scanf(" %c", &treatment);

printf("Patient ID\n");

for (i = 0; i < n; i++) {

if (treatment_type[i] == treatment) {

printf("%d\n", patient_id[i]);

} else if (treatment == 'I' && treatment_type[i] == '1') {

printf("%d\n", patient_id[i]);

} else if (treatment != 'M' && treatment != 'I') {

printf("You entered an invalid treatment code\n");

break;

}

}

return 0;

}

```

The program starts by displaying a header and prompting the user to enter the number of patients. Then, it displays the treatment options and asks the user to enter the patient ID and treatment type for each patient. While doing so, it keeps track of the number of patients receiving insulin treatment.

After all patients have been entered, the program calculates the total number and percentage of patients receiving insulin treatment and displays them.

Finally, the program prompts the user to enter a treatment code to display a list of patients receiving that treatment. It uses a linear search algorithm to find the patients with the specified treatment type and displays their IDs. If the user enters an invalid treatment code, the program displays an error message.

I hope this helps :)

Semoga dengan pertanyaan yang sudah terjawab oleh saalfatih dapat membantu memudahkan mengerjakan soal, tugas dan PR sekolah kalian.

Apabila terdapat kesalahan dalam mengerjakan soal, silahkan koreksi jawaban dengan mengirimkan email ke yomemimo.com melalui halaman Contact

Last Update: Wed, 14 Jun 23