In: Computer Science
Hello sir can you explain me this code in details.
void claimProcess()
{
int id;
bool found = false;
system("cls");
printf("Enter patient ID for which you want to claim insurrence: ");
scanf("%d", & id);
int i;
for (i = 0; i < patientCount; i++)
{
if (patients[i].id == id)
{
found = true;
break;
}
}
if (found == false)
{
printf("subscriber not found\n");
return;
}
int numOfDaysHospitalized, suppliesCost, surgicalFee, otherCharges;
bool ICU;
printf("How many days were you haspitalized: ");
scanf("%d", & numOfDaysHospitalized);
int ICUFlag;
do {
printf("Select A Ward Type\n1-Normal Ward 2-ICU: ");
scanf("%d", & ICUFlag);
} while (ICUFlag < 1 || ICUFlag > 2);
if (ICUFlag == 2)
ICU = true;
else
ICU = false;
printf("Enter Cost of Supplies and Services: ");
scanf("%d", & suppliesCost);
printf("Enter Surgical Fees: ");
scanf("%d", & surgicalFee);
printf("Enter Other Charges: ");
scanf("%d", & otherCharges);
int ICUCharges = 0;
if (ICU == true)
{
if (patients[i].plan == 1)
ICUCharges = numOfDaysHospitalized * 120;
else if (patients[i].plan == 2)
ICUCharges = numOfDaysHospitalized * 150;
else
ICUCharges = numOfDaysHospitalized * 200;
} else
{
if (patients[i].plan == 1)
ICUCharges = numOfDaysHospitalized * 250;
else if (patients[i].plan == 2)
ICUCharges = numOfDaysHospitalized * 400;
else
ICUCharges = numOfDaysHospitalized * 700;
}
int totalClaimAmount = numOfDaysHospitalized + suppliesCost + surgicalFee + otherCharges + ICUCharges;
if (patients[i].annualClaim == true)
{
if (patients[i].age > 60)
{
printf("The subscriber age has exceeded the limit(60 Year), Not Eligible");
return;
}
}
int j;
for (j = 0; j < patientCount; j++)
{
if (claims[j].id == patients[i].id)
break;
}
int amountToBeBorne = 0;
if (totalClaimAmount <= claims[j].remaininigAmount)
{
claims[j].amountClaimed += totalClaimAmount;
claims[j].remaininigAmount -= totalClaimAmount;
} else
{
amountToBeBorne = totalClaimAmount - claims[j].remaininigAmount;
claims[j].amountClaimed += (totalClaimAmount - amountToBeBorne);
claims[j].remaininigAmount = 0;
printf("\n\nThe amount that can be claimed is less then the claim by subscriber. %d RM should be given by subscriber themselves\n", amountToBeBorne);
}
FILE * fp;
fp = fopen("claims.txt", "w");
for (int i = 0; i < patientCount; i++)
fprintf(fp, "%d,%d,%d,%d\n", claims[i].id, claims[i].claimedYear, claims[i].amountClaimed, claims[i].remaininigAmount);
fclose(fp);
printf("Subscriber ID: %d\nSubscriber Name: %s\nSubscriber Claimed Year: %d\nSubscriber amount Claimed: %d\nSubscriber Remaining Claimed: %d\n", claims[j].id, patients[i].name, claims[j].claimedYear, claims[j].amountClaimed, claims[j].remaininigAmount);
system("pause");
}
Function
void claimProcess(){ //function claimProcess(no return
type)
int id;
bool found = false;
system("cls"); //clearing the screen
printf("Enter patient ID for which you want to claim insurrence:
");
scanf("%d", & id); //Input id
int i;
for (i = 0; i < patientCount; i++){ //Loop upto Total
patient
if (patients[i].id == id){ //if input id matches the patient id
that means patient founded
found = true;
break;
}
}
if (found == false){ //if patient not found then exit the
program
printf("subscriber not found\n");
return;
}
int numOfDaysHospitalized, suppliesCost, surgicalFee,
otherCharges;
bool ICU;
printf("How many days were you haspitalized: ");
scanf("%d", & numOfDaysHospitalized); //Input from how many
days you are in hospital
int ICUFlag;
do { //do while loop
printf("Select A Ward Type\n1-Normal Ward 2-ICU: ");
scanf("%d", & ICUFlag); //Input Ward Type(1 or 2)
} while (ICUFlag < 1 || ICUFlag > 2); //if Ward Type other
than 1 or 2 the exit from the loop
if (ICUFlag == 2) //if Ward Type is 2 means patient is in
ICU
ICU = true;
else //if Ward Type is 1 means patient not in ICU
ICU = false;
printf("Enter Cost of Supplies and Services: ");
scanf("%d", & suppliesCost); //Input supplies Cost
printf("Enter Surgical Fees: ");
scanf("%d", & surgicalFee); //Input surgicalFee
printf("Enter Other Charges: ");
scanf("%d", & otherCharges); //Input otherCharges
int ICUCharges = 0;
if (ICU == true){ //if patient in ICU
if (patients[i].plan == 1)
ICUCharges = numOfDaysHospitalized * 120; //if plan=1 then charges
120/day
else if (patients[i].plan == 2)
ICUCharges = numOfDaysHospitalized * 150; //if plan=2 then charges
150/day
else
ICUCharges = numOfDaysHospitalized * 200; //if plan other than 1 or
2 then charges 200/day
}
else{ //If patient is not in ICU
if (patients[i].plan == 1)
ICUCharges = numOfDaysHospitalized * 250; //if plan=1 then charges
250/day
else if (patients[i].plan == 2)
ICUCharges = numOfDaysHospitalized * 400;//if plan=2 then charges
400/day
else
ICUCharges = numOfDaysHospitalized * 700; //if plan other than 1 or
2 then charges 700/day
}
//totalClaimAmount
int totalClaimAmount = numOfDaysHospitalized + suppliesCost +
surgicalFee + otherCharges + ICUCharges;
if (patients[i].annualClaim == true){ //if patient have annualClaim
and age greater than 60 they are not eligible to claim
if (patients[i].age > 60){
printf("The subscriber age has exceeded the limit(60 Year), Not
Eligible");
return;
}
}
int j;
for (j = 0; j < patientCount; j++){//loop total patient
if (claims[j].id == patients[i].id) //if clame id matches with
patient id then exit from the loop
break;
}
int amountToBeBorne = 0;
if (totalClaimAmount <= claims[j].remaininigAmount){//if
totalClaimAmount less than claim(remaininigAmount)
claims[j].amountClaimed += totalClaimAmount; //then add
totalClaimAmount to claim(amountClaimed)
claims[j].remaininigAmount -= totalClaimAmount;//and subtract
totalClaimAmount to claim(remaininigAmount)
}
else{ //if totalClaimAmount greater than
claim(remaininigAmount)
amountToBeBorne = totalClaimAmount -
claims[j].remaininigAmount;//then subtract claim(remaininigAmount)
to totalClaimAmount and pay amountToBeBorne
claims[j].amountClaimed += (totalClaimAmount -
amountToBeBorne);//and add claim(amountClaimed) to
(totalClaimAmount subtract to amountToBeBorne)
claims[j].remaininigAmount = 0; //and claims(remaininigAmount ) is
left zero
printf("\n\nThe amount that can be claimed is less then the claim
by subscriber. %d RM should be given by subscriber themselves\n",
amountToBeBorne);
}
FILE * fp;
fp = fopen("claims.txt", "w");//open file claims.txt to write
data
for (int i = 0; i < patientCount; i++)//loop upto total
patient
fprintf(fp, "%d,%d,%d,%d\n", claims[i].id, claims[i].claimedYear,
claims[i].amountClaimed, claims[i].remaininigAmount);//write into
file claims(id,claimedYear,amountClaimed,remaininigAmount)
fclose(fp); //close file
//print on console
claims(id,claimedYear,amountClaimed,remaininigAmount)
patients(name)
printf("Subscriber ID: %d\nSubscriber Name: %s\nSubscriber Claimed
Year: %d\nSubscriber amount Claimed: %d\nSubscriber Remaining
Claimed: %d\n", claims[j].id, patients[i].name,
claims[j].claimedYear, claims[j].amountClaimed,
claims[j].remaininigAmount);
system("pause");//program waits to be terminated
}
Explanation
function claimProcess(no return type)
Input id
Loop upto Total patient
if input id matches the patient id that means patient founded
if patient not found then exit the program
Input from how many days you are in hospital
do while loop
Input Ward Type(1 or 2)
if Ward Type other than 1 or 2 the exit from the loop
if Ward Type is 2 means patient is in ICU
else Ward Type is 1 means patient not in ICU
Input supplies Cost ,surgicalFee,otherCharges
if patient in ICU
if plan=1 then charges 120/day
if plan=2 then charges 150/day
else plan other than 1 0r 2 then charges 200/day
else patient is not in ICU
if plan=1 then charges 250/day
if plan=2 then charges 400/day
else plan other than 1 or 2 then charges 700/day
totalClaimAmount = numOfDaysHospitalized + suppliesCost + surgicalFee + otherCharges + ICUCharges;
if patient have annualClaim and age greater than 60 they are not eligible to claim
loop total patient
if clame id matches with patient id then exit from the loop
if totalClaimAmount less than claim(remaininigAmount)
then add totalClaimAmount to claim(amountClaimed) and subtract totalClaimAmount to claim(remaininigAmount)
else totalClaimAmount greater than claim(remaininigAmount)
then subtract claim(remaininigAmount) to totalClaimAmount and pay amountToBeBorne
and add claim(amountClaimed) to (totalClaimAmount subtract to amountToBeBorne)
and claims(remaininigAmount ) is left zero
open file claims.txt to write data
loop upto total patient
write into file claims(id,claimedYear,amountClaimed,remaininigAmount)
close file
print on console claims(id,claimedYear,amountClaimed,remaininigAmount) patients(name)
program waits to be terminated