Question

In: Computer Science

Explain the code below in details. void accountInfo() { system("cls"); int ch; printf("1-Total Amount Claimed by...

Explain the code below in details.

void accountInfo()

{

system("cls");

int ch;

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", & ch);

if (ch == 1)

{

int totalAmountClaimedByLifeTimeSubs = 0;

for (int i = 0; i < patientCount; i++)

{

if (patients[i].annualClaim == false)

{

for (int j = 0; j < patientCount; j++)

{

if (claims[j].id == patients[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 < patientCount; i++)

{

if (claims[i].remaininigAmount <= 0 && patients[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 ch;

printf("1-Search by ID\n2-Search by age\n");

scanf("%d", & ch);

if (ch == 1)

{

int id;

printf("Enter patient ID for which you want Search: ");

scanf("%d", & id);

int i;

for (i = 0; i < patientCount; i++)

{

if (patients[i].id == id)

{

printf("\nSubscriber Name: %s\nSubscriber Age: %d\nSubscriber Contact: %s\nSubscriber Address: %s\n", patients[i].name, patients[i].age, patients[i].contactNum, patients[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 < patientCount; i++)

{

if (patients[i].age == age)

{

printf("\nSubscriber Name: %s\nSubscriber ID: %d\nSubscriber Contact: %s\nSubscriber Address: %s\n", patients[i].name, patients[i].id, patients[i].contactNum, patients[i].address);

}

}

}

system("pause");

}

void loadData()

{

char line[MAX_LENGTH];

const char * delimiter = ",\n";

FILE * fp;

fp = fopen("patients.txt", "r");

char c;

if (fp == NULL)

{

printf("file not found");

return;

}

while (fp != NULL)

{

if (fgets(line, MAX_LENGTH - 1, fp) == NULL)

break;

if (line[1] == '\0')

break;

patients[patientCount].id = atoi(strtok(line, delimiter));

strcpy(patients[patientCount].name, strtok(NULL, delimiter));

patients[patientCount].age = atoi(strtok(NULL, delimiter));

patients[patientCount].annualClaim = strtok(NULL, delimiter);

patients[patientCount].plan = atoi(strtok(NULL, delimiter));

strcpy(patients[patientCount].contactNum, strtok(NULL, delimiter));

strcpy(patients[patientCount].address, strtok(NULL, delimiter));

strcpy(line, "\0");

patientCount++;

}

fclose(fp);

fp = fopen("claims.txt", "r");

int claimCount = 0;

while (fp != NULL)

{

if (fgets(line, MAX_LENGTH - 1, fp) == NULL)

break;

if (line == "\n")

break;

claims[claimCount].id = atoi(strtok(line, delimiter));

claims[claimCount].claimedYear = atoi(strtok(NULL, delimiter));

claims[claimCount].amountClaimed = atoi(strtok(NULL, delimiter));

claims[claimCount].remaininigAmount = atoi(strtok(NULL, delimiter));

strcpy(line, "\0");

claimCount++;

}

fclose(fp);

}

Solutions

Expert Solution

CODE:

Explanation is given in the comment wise.

// prints the account information of the subscribers

void accountInfo() {
system("cls"); // clears the output screen
int ch; // represents the 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", & ch); // can give input choice
if (ch == 1) // if choice is 1 then below statements executes
{
int totalAmountClaimedByLifeTimeSubs = 0;
for (int i = 0; i < patientCount; i++) // iterates till reaches all the patient Counts
{
if (patients[i].annualClaim == false) // if patient fails to claim then below code
// executes for claims array to check the patient claim done on one-on-one basis.
{
for (int j = 0; j < patientCount; j++) {
if (claims[j].id == patients[i].id) // if the patient has a certain then that will be added to
// total amount claimed by life time
{
totalAmountClaimedByLifeTimeSubs += claims[j].amountClaimed;
}
}
}
}
// total amount claimed is printed here.
printf("\nTotal amount Claimed By LifeTime Subscribers is: %d\n", totalAmountClaimedByLifeTimeSubs);
  
} else // if the choice is other than the 1 then below code executes
{
int count = 0;
for (int i = 0; i < patientCount; i++) {
if (claims[i].remaininigAmount <= 0 && patients[i].annualClaim == true)
count++;
}
printf("Total number of Annual Claim Limit Subcriber who have exhausted all their amount are: %d\n", count);
}
system("pause");
// Whenever pause is used then the program waits to be terminated, and halts the exceution of the parent program.
// Only after the pause program is terminated, will the original program continue.
}


// function describing the searchingFunctionalities in the program
// there are two functionalities given here.
// one by age and other by ID.

void searchingFunctionalities() {
system("cls"); // clears the output screen
int ch; // choice variable can choose either ID by choosing 1 or Age by choosing 2
  
printf("1-Search by ID\n2-Search by age\n");
scanf("%d", & ch); // enters choice
  
// if choice is 1 then the search by ID is exceuted
if (ch == 1) {
int id;
printf("Enter patient ID for which you want Search: ");
scanf("%d", & id); // allows you to enter the patient ID.
int i;
for (i = 0; i < patientCount; i++) { // iterates till the number of patients
// iterates for the patients array to check the ID with the ID given.
// if matches prints the contents and then breaks the loop
if (patients[i].id == id) {
printf("\nSubscriber Name: %s\nSubscriber Age: %d\nSubscriber Contact: %s\nSubscriber Address: %s\n", patients[i].name, patients[i].age, patients[i].contactNum, patients[i].address);
break;
}
}
printf("Subscriber Not Found");
}
else { // seach by age is executed.
int age;
printf("Enter age for which you want Search: ");
scanf("%d", & age); // can enter the age
for (int i = 0; i < patientCount; i++) { // iterates till the number of patients
// iterates for the patients array to check the ID with the ID given.
// if matches prints the contents and then breaks the loop
if (patients[i].age == age) {
printf("\nSubscriber Name: %s\nSubscriber ID: %d\nSubscriber Contact: %s\nSubscriber Address: %s\n", patients[i].name, patients[i].id, patients[i].contactNum, patients[i].address);
}
}
}
system("pause");
// Whenever pause is used then the program waits to be terminated, and halts the exceution of the parent program.
// Only after the pause program is terminated, will the original program continue.
}

// function describing the loading the data
// here loads two files one is patients.txt and other is claims.txt
// the contents from the patients.txt is stored in patients of structure type.
// the contents from the claims.txt is stored in claims of structure type.

void loadData() {
char line[MAX_LENGTH]; // line of character array type of MAX_LENGTH is created.
const char * delimiter = ",\n"; // delimiter is choosen an \n
FILE * fp; // file pointer created
// patients.txt is opened.
fp = fopen("patients.txt", "r");
char c;
// if the patients.txt doesnt exist then return NULL
// prints file not found.
if (fp == NULL) {
printf("file not found");
return;
}
// if the file is not NULL then contents are read line by line
// using strtok the contents are broken by the delimiter
// atoi is the function converts alpha values to the integer numeric type.
  
while (fp != NULL) {
if (fgets(line, MAX_LENGTH - 1, fp) == NULL)
break; // till the file reaches the end-pointer this loop is executed.
if (line[1] == '\0')
break;
// the line is broken down using the delimiter and is stored in the
// respective structure members.
  
patients[patientCount].id = atoi(strtok(line, delimiter));
strcpy(patients[patientCount].name, strtok(NULL, delimiter));
patients[patientCount].age = atoi(strtok(NULL, delimiter));
patients[patientCount].annualClaim = strtok(NULL, delimiter);
patients[patientCount].plan = atoi(strtok(NULL, delimiter));
strcpy(patients[patientCount].contactNum, strtok(NULL, delimiter));
strcpy(patients[patientCount].address, strtok(NULL, delimiter));
strcpy(line, "\0");
patientCount++; // patientCount is maintained.
}
fclose(fp); // file pointer is closed.
// claims.txt file is opened.
fp = fopen("claims.txt", "r");
int claimCount = 0; // claimCount is initialised to 0.
  
// if the file is not NULL then contents are read line by line
// using strtok the contents are broken by the delimiter
// atoi is the function converts alpha values to the integer numeric type.
  
while (fp != NULL) {
if (fgets(line, MAX_LENGTH - 1, fp) == NULL)
break;
if (line == "\n")
break;
claims[claimCount].id = atoi(strtok(line, delimiter));
claims[claimCount].claimedYear = atoi(strtok(NULL, delimiter));
claims[claimCount].amountClaimed = atoi(strtok(NULL, delimiter));
claims[claimCount].remaininigAmount = atoi(strtok(NULL, delimiter));
strcpy(line, "\0");
claimCount++; // claimCount is incremented by 1.
}
fclose(fp); // file pointer is closed
}


Related Solutions

Hello sir can you explain me this code in details. void claimProcess() { int id; bool...
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: ");...
Please explain this code line by line void printperm(int *A,int n,int rem,int j) {    if(n==1)...
Please explain this code line by line void printperm(int *A,int n,int rem,int j) {    if(n==1)       {        for(int k=0;k<j;k++)        cout<<A[k]<<" + ";        cout<<rem<<"\n";        return;       }     for(int i=0;i<=rem;i++)    {          if(i<=rem)          A[j]=i;          printperm(A,n-1,rem-i,j+1);    } }
What’s the output of following code fragment: #include<stdio.h> #include<signal.h> void response (int sig_no) { printf("25"); }...
What’s the output of following code fragment: #include<stdio.h> #include<signal.h> void response (int sig_no) { printf("25"); } void response2 (int sig_no) { printf("43"); }     int main() {      int id = getpid();      signal(SIGUSR1, response); signal(SIGKILL, response2); for(int i=0; i<4; i++) { sleep(1); if (i % 3 == 0) { kill(id, SIGUSR1); } else { kill(id, SIGKILL); } } return 0; }
What is the ouput of the following code? void loop(int num) { for(int i = 1;...
What is the ouput of the following code? void loop(int num) { for(int i = 1; i < num; ++i) { for(int j = 0; j < 5; ++j) { cout << j; } } } int main() { loop(3); return 0; }
Question 31 Given the code snippet below, what prints? void fun(int *p) { int q =...
Question 31 Given the code snippet below, what prints? void fun(int *p) { int q = 10; p = &q; } int main() { int r = 20; int *p = &r; fun(p); cout << *p; return 0; } Question 31 options: 10 20 compiler error Runtime error Question 32 A union’s members are exactly like the members of a Structure. Question 32 options: True False Question 33 Given the code below, what are the errors. #include <iostream> using namespace...
Given the root C++ code: void sort() {    const int N = 10;    int...
Given the root C++ code: void sort() {    const int N = 10;    int x[N];    for(int i = 0; i < N; i++)    {        x[i] = 1 + gRandom-> Rndm() * 10;        cout<<x[i]<<" "; }    cout<<endl;    int t;       for(int i = 0; i < N; i++)    {    for(int j = i+1; j < N; j++)    {        if(x[j] < x[i])        {   ...
Consider the following code: void swap(int arr[], int i, int j) {        int temp = arr[i];...
Consider the following code: void swap(int arr[], int i, int j) {        int temp = arr[i];        arr[i] = arr[j];        arr[j] = temp; } void function(int arr[], int length) {        for (int i = 0; i<length / 2; i++)               swap(arr, i, (length / 2 + i) % length); } If the input to the function was int arr[] = { 6, 1, 8, 2, 5, 4, 3, 7 }; function(arr,8); What values would be stored in the array after calling the...
why my code for mergesort always wrong ? void Merge(vector<int>& data, int p, int q, int...
why my code for mergesort always wrong ? void Merge(vector<int>& data, int p, int q, int r) { int n1 = q - p + 1; int n2 = r - q; vector<int>left(n1); vector<int>right(n2); for(int i = 0; i < n1; i++) { left[i] = data[p + i]; } for(int j = 0; j < n2; j++) { right[j] = data[q+j+1]; } int i = 0; int j = 0; for(int k = p; k <= r; k++) { if(left[i]...
Given a program as shown below: #include <stdio.h> void function1(void); void function2 (int, double x); void...
Given a program as shown below: #include <stdio.h> void function1(void); void function2 (int, double x); void main (void) { int m; double y; m=15; y=308.24; printf ("The value of m in main is m=%d\n\n",m); function1(); function2(m,y); printf ("The value of m is main still m = %d\n",m); } void function1(void) { printf("function1 is a void function that does not receive\n\\r values from main.\n\n"); } void function2(int n, double x) { int k,m; double z; k=2*n+2; m=5*n+37; z=4.0*x-58.4; printf ("function2 is...
Given a program as shown below: #include <stdio.h> void function1(void); void function2 (int, double x); void...
Given a program as shown below: #include <stdio.h> void function1(void); void function2 (int, double x); void main (void) { int m; double y; m=15; y=308.24; printf ("The value of m in main is m=%d\n\n",m); function1(); function2(m,y); printf ("The value of m is main still m = %d\n",m); } void function1(void) { printf("function1 is a void function that does not receive\n\\r values from main.\n\n"); } void function2(int n, double x) { int k,m; double z; k=2*n+2; m=5*n+37; z=4.0*x-58.4; printf ("function2 is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT