Explain this code function by function in detail
int menu()
{
int choice;
do {
system("cls");
printf("1-Insurence Plan Subscription\n");
printf("2-Claim Processing\n");
printf("3-Accounts Information\n");
printf("4-Searching Functionalities\n");
printf("5-Exit\n");
scanf("%d", &choice);
} while (choice > 5 || choice < 1);
return choice;
void subscribe()
system("cls");
victims[userCount].id = userCount + 1;
printf("Enter age: ");
scanf("%d", &victims[userCount].age);
printf("\n\n%-25sHealth Insurence Plan\n\n", " ");
printf("-----------------------------------------------------------------------------------------------\n");
printf("|%-30s|%-20s|%-20s|%-20s|\n", " ", "Plan 120(RM)", "Plan 150(RM)", "Plan 200(RM)");
printf("-----------------------------------------------------------------------------------------------\n");
printf("|%-30s|%-20d|%-20d|%-20d|\n", "Monthly Premium", 120, 150, 200);
printf("|%-30s|%-20d|%-20d|%-20d|\n", "Annual Claim Limit", 120000,150000,200000);
printf("|%-30s|%-20d|%-20d|%-20d|\n", "Lifetime Claim Limit", 600000,750000,1000000);
printf("\n\n%-25sAge Group and Health Insurence Plan\n\n", " ");
printf("|%-30s|%-25s%-30s\n", "Types of Claim"," ","Eligibility Amount");
printf("|%-30s|%-20s|%-20s|%-20s|\n", " ", "Plan 120(RM)", "Plan 150(RM)", "Plan 200(RM)");
printf("|%-30s|%-20s|%-20s|%-20s|\n", "Room Charges", "120/day", "150/day", "200/day");
printf("|%-30s|%-20s|%-20s|%-20s|\n", "Intensive Care Unit", "250/day", "400/day", "700/day");
printf("|%-30s|%-20s|%-20s|%-20s|\n", "Hospital Supplies and Services", " "," "," ");
printf("|%-30s|%-60s|\n", "Surgical Fees", "As charged Sbject to approval by ZeeMediLife");
printf("|%-30s|%-20s|%-20s|%-20s|\n", "Other Fees", " ", " ", " ");
int choice;
do{
printf("Select a Claim Limit Type\n1-Annual Claim Limit 2-Lifetime Claim Limit: ");
scanf("%d", &choice);
} while (choice < 1 || choice>2);
if (choice == 1)
victims[userCount].annualClaim = true;
else
victims[userCount].annualClaim = false;
do {
printf("Select a plan\n1-Plan120 2-Plan150 3-Plan200: ");
scanf("%d", &choice);
} while (choice < 1 || choice>3);
victims[userCount].plan = choice;
printf("Enter Name: ");
scanf("%s", &victims[userCount].name);
printf("Contact Number: ");
scanf("%s", &victims[userCount].contactNum);
printf("Enter Address: ");
scanf("%s", &victims[userCount].address);
FILE *fp;
fp = fopen("users.txt", "a");
fprintf(fp, "%d,%s,%d,%d,%d,%s,%s\n", victims[userCount].id, victims[userCount].name, victims[userCount].age, victims[userCount].annualClaim, victims[userCount].plan, victims[userCount].contactNum, victims[userCount].address);
fclose(fp);
time_t s;
struct tm* currentTime;
s = time(NULL);
currentTime = localtime(&s);
claims[userCount].id = victims[userCount].id;
claims[userCount].amountClaimed = 0;
claims[userCount].claimedYear = currentTime->tm_hour + 1900;
if (victims[userCount].annualClaim == true)
if (victims[userCount].plan == 1)
claims[userCount].remaininigAmount = 120000;
else if (victims[userCount].plan == 2)
claims[userCount].remaininigAmount = 150000;
else
claims[userCount].remaininigAmount = 200000;
} else {
if (victims[userCount].plan == 1)
claims[userCount].remaininigAmount = 600000;
else if (victims[userCount].plan == 2)
claims[userCount].remaininigAmount = 750000;
else
claims[userCount].remaininigAmount = 1000000;
}userCount++;
fp = fopen("claims.txt", "a");
if (fp == NULL)
printf("File Dont exist");
fprintf(fp,"%d,%d,%d,%d\n", claims[userCount].id, claims[userCount].claimedYear, claims[userCount].amountClaimed, claims[userCount].remaininigAmount);
fclose(fp);
system("pause");
void claimProcess()
{ int id;
bool found = false;
system("cls");
printf("Enter user ID for which you want to claim insurrence: ");
scanf("%d", &id); int i;
for (i = 0; i < userCount; i++)
{
if (victims[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 (victims[i].plan == 1)
ICUCharges = numOfDaysHospitalized * 120;
else if (victims[i].plan == 2)
ICUCharges = numOfDaysHospitalized * 150;
else
ICUCharges = numOfDaysHospitalized * 200;
}
else
{
if (victims[i].plan == 1)
ICUCharges = numOfDaysHospitalized * 250;
else if (victims[i].plan == 2)
ICUCharges = numOfDaysHospitalized * 400;
else
ICUCharges = numOfDaysHospitalized * 700;
}
int totalClaimAmount = numOfDaysHospitalized + suppliesCost + surgicalFee + otherCharges + ICUCharges;
if (victims[i].annualClaim == true)
{
if (victims[i].age > 60)
{
printf("The subscriber age has exceeded the limit(60 Year), Not Eligible");
return;
}
}
int j;
for (j = 0; j < userCount; j++)
{
if (claims[j].id == victims[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<userCount;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, victims[i].name, claims[j].claimedYear, claims[j].amountClaimed, claims[j].remaininigAmount);
system("pause");
}
void accountInfo()
{
system("cls");
int choice;
printf("1-Total Amount Claimed by LifeTime Claim Limit subscriber\n");
printf("2-Total number of Annual Claim Limit who have exhausted all their eligible amount\n");
scanf("%d", &choice);
if (choice == 1)
{
int totalAmountClaimedByLifeTimeSubs = 0;
for (int i = 0; i < userCount; i++)
{
if (victims[i].annualClaim == false)
{
for (int j = 0; j < userCount; j++)
{
if (claims[j].id == victims[i].id)
{
totalAmountClaimedByLifeTimeSubs += claims[j].amountClaimed;
}
printf("\nTotal amount Claimed By LifeTime Subscribers is: %d\n", totalAmountClaimedByLifeTimeSubs);
}
else
{
int count = 0;
for (int i = 0; i < userCount; i++)
{
if (claims[i].remaininigAmount <= 0 && victims[i].annualClaim == true)
count++;
}
printf("Total number of Annual Claim Limit Subcriber who have exhausted all their amount are: %d\n", count);
}
system("pause");
}
void searchingFunctionalities()
{
system("cls");
int choice;
printf("1-Search by ID\n2-Search by age\n");
scanf("%d", &choice);
if (choice == 1)
{
int id;
printf("Enter user ID for which you want Search: ");
scanf("%d", &id);
int i;
for (i = 0; i < userCount; i++)
{
if (victims[i].id == id)
{
printf("\nSubscriber Name: %s\nSubscriber Age: %d\nSubscriber Contact: %s\nSubscriber Address: %s\n", victims[i].name, victims[i].age, victims[i].contactNum, victims[i].address);
break;
}
}
printf("Subscriber Not Found");
}
else
{
int age;
printf("Enter age for which you want Search: ");
scanf("%d", &age);
for (int i = 0; i < userCount; i++)
{
if (victims[i].age == age)
{
printf("\nSubscriber Name: %s\nSubscriber ID: %d\nSubscriber Contact: %s\nSubscriber Address: %s\n", victims[i].name, victims[i].id, victims[i].contactNum, victims[i].address);
}
system("pause");
}
int main()
{
int choice;
loadData();
do {
choice = menu();
if (choice == 1)
subscribe();
else if (choice == 2)
claimProcess();
else if (choice == 3)
accountInfo();
else if (choice == 4)
searchingFunctionalities();
else
break;
} while (choice != 5);
system("pause");
return 0;
}
Explanation:
Main Functon:
loadData():
Then in the main function
the menu() function is called. The menu() function prints the menu of the application through printf() then it reads and integer value as choice through scanf() and returns it to the choice variable of the main() function.
NOTE: The choice variable of the main() function and the menu() function are different variables and they have different addresses and scope.
if choice is equal to 1 the subscribe() function is called.
subscribe():
If choice is equal to 2 then claimProcess() function is called.
claimProcess():
If choice is equal to 3 in the main() function the accountInfo() is called:
if the choice is equal to 4 in the main() function searchingFunctionalities() is called:
**Fell free to ask any queries in the comment section. I am happy to help you. if you like our work, please give Thumbs up**
Get Answers For Free
Most questions answered within 1 hours.