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

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 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...
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]...
CODE A #include<stdio.h> #include<math.h> #include<stdlib.h> #define PI 3.14159265358979323846 int main(){ int diameter; printf("Enter value of diameter...
CODE A #include<stdio.h> #include<math.h> #include<stdlib.h> #define PI 3.14159265358979323846 int main(){ int diameter; printf("Enter value of diameter between 8 to 60 inches: "); scanf("%d",&diameter); // if(diameter>60 || diameter<=8){ // printf("Error! invalid input"); // exit(0); // } // else{ // float radius = diameter/2; // float volume = (4/3)*PI*radius*radius*radius; // printf("%.2f",volume); // } //check through the while loop if it is valid or in valid while(diameter>60 || diameter<=8){ printf("Invalid input Enter again: "); scanf("%d",&diameter); }    //caluclate the volume of sphere float...
(JAVA) InvertArrangement +invert(int[] a) : int [] +print(int[] a) : void Example 1: the invert method...
(JAVA) InvertArrangement +invert(int[] a) : int [] +print(int[] a) : void Example 1: the invert method receives the following arrangement: [1,2,3,4,5] The invert method returns the array [5,4,3,2,1] Example 2: the print method receives the following array: [5,4,3,2,1] The print method prints: 5,4,3,2,1 (data separated by commas). TIP: for the print method use System.out.print () without the "ln".
Hi, I'm trying to rewrite the code below (code #1) by changing delay() to millis(). void...
Hi, I'm trying to rewrite the code below (code #1) by changing delay() to millis(). void loop() { // Print the value inside of myBPM. Serial.begin(9600); int myBPM = pulseSensor.getBeatsPerMinute(); // Calls function on our pulseSensor object that returns BPM as an "int". // "myBPM" hold this BPM value now. if (pulseSensor.sawStartOfBeat()) { // Constantly test to see if "a beat happened". Serial.println("♥ A HeartBeat Happened ! "); // If test is "true", print a message "a heartbeat happened". Serial.print("BPM:...
) Write a recurrence relation of the following code and find the time complexity. void towerOfHanoi(int...
) Write a recurrence relation of the following code and find the time complexity. void towerOfHanoi(int n, char from_rod,                     char to_rod, char aux_rod) {     if (n == 1)     {         cout << "Move disk 1 from " << from_rod << " to " << to_rod<<endl;         return;     }     towerOfHanoi(n - 1, from_rod, aux_rod, to_rod);     cout << "Move disk " << n << " from " << from_rod << " to " << to_rod << endl;     towerOfHanoi(n - 1, aux_rod, to_rod, from_rod); }
1. Consider the following code: public class Widget implements Serializable { private int x; public void...
1. Consider the following code: public class Widget implements Serializable { private int x; public void setX( int d ) { x = d; } public int getX() { return x; } writeObject( Object o ) { o.writeInt(x); } } Which of the following statements is true? I. The Widget class is not serializable because no constructor is defined. II. The Widget class is not serializable because the implementation of writeObject() is not needed. III. The code will not compile...
What is the Θ( ) for each code segment below? (a) for( int i = 1,...
What is the Θ( ) for each code segment below? (a) for( int i = 1, i<= n, i = i*2){       some constant operation } (b) for( int i = 1, i<= n, i++){      for( int j = 2*i, j<=n, j++){           some constant operation      } } (c) for( int i = 1, i<= n, i = i*2){      for( int j = 1, j<=n, j = j*2){           some constant operation      } }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT