Question

In: Computer Science

Hello sir below is my code can you plz explain it line by line in details...

Hello sir below is my code can you plz explain it line by line in details

#include<stdio.h>

#include<stdlib.h>

#include<stdbool.h>

#include<string.h>

#include<time.h>

struct patient {

int id;

int age;

bool annualClaim;

int plan;

char name[30];

char contactNum[15];

char address[50];

};

#define MAX_LENGTH 500

struct patient patients[100];

int patientCount = 0;

struct claim {

int id;

int claimedYear;

int amountClaimed;

int remaininigAmount;

};

struct claim claims[100];

void subscribe()

{

system("cls");

patients[patientCount].id = patientCount + 1;

printf("Enter age: ");

scanf("%d", & patients[patientCount].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("-----------------------------------------------------------------------------------------------\n");

printf("|%-30s|%-20d|%-20d|%-20d|\n", "Annual Claim Limit", 120000, 150000, 200000);

printf("-----------------------------------------------------------------------------------------------\n");

printf("|%-30s|%-20d|%-20d|%-20d|\n", "Lifetime Claim Limit", 600000, 750000, 1000000);

printf("-----------------------------------------------------------------------------------------------\n");

printf("\n\n%-25sAge Group and Health Insurence Plan\n\n", " ");

printf("-----------------------------------------------------------------------------------------------\n");

printf("|%-30s|%-25s%-30s\n", "Types of Claim", " ", "Eligibility Amount");

printf("-----------------------------------------------------------------------------------------------\n");

printf("|%-30s|%-20s|%-20s|%-20s|\n", " ", "Plan 120(RM)", "Plan 150(RM)", "Plan 200(RM)");

printf("-----------------------------------------------------------------------------------------------\n");

printf("|%-30s|%-20s|%-20s|%-20s|\n", "Room Charges", "120/day", "150/day", "200/day");

printf("-----------------------------------------------------------------------------------------------\n");

printf("|%-30s|%-20s|%-20s|%-20s|\n", "Intensive Care Unit", "250/day", "400/day", "700/day");

printf("-----------------------------------------------------------------------------------------------\n");

printf("|%-30s|%-20s|%-20s|%-20s|\n", "Hospital Supplies and Services", " ", " ", " ");

printf("-----------------------------------------------------------------------------------------------\n");

printf("|%-30s|%-60s|\n", "Surgical Fees", "As charged Sbject to approval by ZeeMediLife");

printf("-----------------------------------------------------------------------------------------------\n");

printf("|%-30s|%-20s|%-20s|%-20s|\n", "Other Fees", " ", " ", " ");

printf("-----------------------------------------------------------------------------------------------\n\n");

int ch;

do {

printf("Select a Claim Limit Type\n1-Annual Claim Limit 2-Lifetime Claim Limit: ");

scanf("%d", & ch);

} while (ch < 1 || ch > 2);

if (ch == 1)

patients[patientCount].annualClaim = true;

else

patients[patientCount].annualClaim = false;

do {

printf("Select a plan\n1-Plan120 2-Plan150 3-Plan200: ");

scanf("%d", & ch);

} while (ch < 1 || ch > 3);

patients[patientCount].plan = ch;

printf("Enter Name: ");

scanf("%s", & patients[patientCount].name);

printf("Contact Number: ");

scanf("%s", & patients[patientCount].contactNum);

printf("Enter Address: ");

scanf("%s", & patients[patientCount].address);

FILE * fp;

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

fprintf(fp, "%d,%s,%d,%d,%d,%s,%s\n", patients[patientCount].id, patients[patientCount].name, patients[patientCount].age, patients[patientCount].annualClaim, patients[patientCount].plan, patients[patientCount].contactNum, patients[patientCount].address);

fclose(fp);

time_t s;

struct tm * currentTime;

s = time(NULL);

currentTime = localtime( & s);

claims[patientCount].id = patients[patientCount].id;

claims[patientCount].amountClaimed = 0;

claims[patientCount].claimedYear = currentTime -> tm_hour + 1900;

if (patients[patientCount].annualClaim == true)

{

if (patients[patientCount].plan == 1)

claims[patientCount].remaininigAmount = 120000;

else if (patients[patientCount].plan == 2)

claims[patientCount].remaininigAmount = 150000;

else

claims[patientCount].remaininigAmount = 200000;

} else

{

if (patients[patientCount].plan == 1)

claims[patientCount].remaininigAmount = 600000;

else if (patients[patientCount].plan == 2)

claims[patientCount].remaininigAmount = 750000;

else

claims[patientCount].remaininigAmount = 1000000;

}

patientCount++;

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

if (fp == NULL)

printf("File Dont exist");

fprintf(fp, "%d,%d,%d,%d\n", claims[patientCount].id, claims[patientCount].claimedYear, claims[patientCount].amountClaimed, claims[patientCount].remaininigAmount);

fclose(fp);

system("pause");

}

Solutions

Expert Solution

I HAVE COMMENTED EACH LINE EXPLANATION AGIANTS EACH LINE YOU CAN EXECUTE IT

#include<stdio.h>// including stabdard input output

#include<stdlib.h> // including standard library

#include<stdbool.h>

#include<string.h>

#include<time.h>

struct patient { //defining a structure patient with following fields

int id; // an id of integer type

int age; // age of integertpye

bool annualClaim; //annualvlaim of boolean type

int plan; // plan of integer type

char name[30]; //an name array of char type with size =30

char contactNum[15]; //a contactnum array of char type with size =15

char address[50]; //an address array of char type with size =50

};

#define MAX_LENGTH 500 // defining max_lenght tp 500 global

struct patient patients[100]; // defining a object of structure patient type with name patients and size =100

int patientCount = 0; //intialising patient count to 0

struct claim { //defining a structure claim with following fields

int id; // an id of integer type

int claimedYear; // a claimedyear of integer type

int amountClaimed; // aa amountclaimed of integer type

int remaininigAmount; // a remainingAmount of integer type

};

struct claim claims[100]; // defining a object of structure claim type with name claims and size =100

void subscribe() // defining a function of subscribe name

{

system("cls"); // clearing tha system

patients[patientCount].id = patientCount + 1; // entering the value to id of structure patient's patients object

printf("Enter age: "); //taking input for age from user/keyboard

scanf("%d", & patients[patientCount].age); // entering the value to age of structure patient's patients object

printf("\n\n%-25sHealth Insurence Plan\n\n", " "); // dislaying message to screen Health Insurence Plan

printf("-----------------------------------------------------------------------------------------------\n");

printf("|%-30s|%-20s|%-20s|%-20s|\n", " ", "Plan 120(RM)", "Plan 150(RM)", "Plan 200(RM)"); //dislaying message to screen |Plan 120(RM) |Plan 150(RM) |Plan 200(RM) |

printf("-----------------------------------------------------------------------------------------------\n");// these all printf statements are used to display a table like structure as i have shown it below these are just a printf statements

printf("|%-30s|%-20d|%-20d|%-20d|\n", "Monthly Premium", 120, 150, 200);

printf("-----------------------------------------------------------------------------------------------\n");

printf("|%-30s|%-20d|%-20d|%-20d|\n", "Annual Claim Limit", 120000, 150000, 200000);

printf("-----------------------------------------------------------------------------------------------\n");

printf("|%-30s|%-20d|%-20d|%-20d|\n", "Lifetime Claim Limit", 600000, 750000, 1000000);

printf("-----------------------------------------------------------------------------------------------\n");

printf("\n\n%-25sAge Group and Health Insurence Plan\n\n", " ");

printf("-----------------------------------------------------------------------------------------------\n");

printf("|%-30s|%-25s%-30s\n", "Types of Claim", " ", "Eligibility Amount");

printf("-----------------------------------------------------------------------------------------------\n");

printf("|%-30s|%-20s|%-20s|%-20s|\n", " ", "Plan 120(RM)", "Plan 150(RM)", "Plan 200(RM)");

printf("-----------------------------------------------------------------------------------------------\n");

printf("|%-30s|%-20s|%-20s|%-20s|\n", "Room Charges", "120/day", "150/day", "200/day");

printf("-----------------------------------------------------------------------------------------------\n");

printf("|%-30s|%-20s|%-20s|%-20s|\n", "Intensive Care Unit", "250/day", "400/day", "700/day");

printf("-----------------------------------------------------------------------------------------------\n");

printf("|%-30s|%-20s|%-20s|%-20s|\n", "Hospital Supplies and Services", " ", " ", " ");

printf("-----------------------------------------------------------------------------------------------\n");

printf("|%-30s|%-60s|\n", "Surgical Fees", "As charged Sbject to approval by ZeeMediLife");

printf("-----------------------------------------------------------------------------------------------\n");

printf("|%-30s|%-20s|%-20s|%-20s|\n", "Other Fees", " ", " ", " ");

printf("-----------------------------------------------------------------------------------------------\n\n");
/*
-----------------------------------------------------------------------------------------------
| |Plan 120(RM) |Plan 150(RM) |Plan 200(RM) |
-----------------------------------------------------------------------------------------------
|Monthly Premium |120 |150 |200 |
-----------------------------------------------------------------------------------------------
|Annual Claim Limit |120000 |150000 |200000 |
-----------------------------------------------------------------------------------------------
|Lifetime Claim Limit |600000 |750000 |1000000 |
-----------------------------------------------------------------------------------------------


Age Group and Health Insurence Plan

-----------------------------------------------------------------------------------------------
|Types of Claim | Eligibility Amount
-----------------------------------------------------------------------------------------------
| |Plan 120(RM) |Plan 150(RM) |Plan 200(RM) |
-----------------------------------------------------------------------------------------------
|Room Charges |120/day |150/day |200/day |
-----------------------------------------------------------------------------------------------
|Intensive Care Unit |250/day |400/day |700/day |
-----------------------------------------------------------------------------------------------
|Hospital Supplies and Services| | | |
-----------------------------------------------------------------------------------------------
|Surgical Fees |As charged Sbject to approval by ZeeMediLife |
-----------------------------------------------------------------------------------------------
|Other Fees | | | |
----------------------------------------------------------------------------------------------- */

int ch; // defining a ch variable of integer type

do { // startin do loop

printf("Select a Claim Limit Type\n1-Annual Claim Limit 2-Lifetime Claim Limit: ");
/* display this message
Select a Claim Limit Type
1-Annual Claim Limit 2-Lifetime Claim Limit:
*/

scanf("%d", & ch); // storing to ch variable

} while (ch < 1 || ch > 2); // while conditioning statement checking only for 1 and 2 if user enter any value other than 1 and 2 loop will terminate

if (ch == 1) // if condition checking if value entered by user is 1 then annualclaims become true

patients[patientCount].annualClaim = true;

else

patients[patientCount].annualClaim = false; // otherwise annualcaims become false

do { // starting do loop

printf("Select a plan\n1-Plan120 2-Plan150 3-Plan200: "); //dipaying this message 1-Plan120 2-Plan150 3-Plan200:

scanf("%d", & ch); ///storing user input value to ch variable

} while (ch < 1 || ch > 3); // while conditioning statement checking only for 1 and 2 if user enter any value other less than 1 or greater than 3, loop will terminate

patients[patientCount].plan = ch; // assigneing ch value to plan field of patient structure

printf("Enter Name: "); // to enter name

scanf("%s", & patients[patientCount].name); // stores the entered name on name field of structure patient's patients object

printf("Contact Number: ");// to enter contact number

scanf("%s", & patients[patientCount].contactNum); //stores the entered contact number on contactnum field of structure patient's patients object

printf("Enter Address: "); // to enter address

scanf("%s", & patients[patientCount].address); //stores the entered address on address field of structure patient's patients object

FILE * fp; // declare a pointer of type file

fp = fopen("patients.txt", "a"); // opening a file in append mode i.e Data is added to the end of the file.If the file does not exist, it will be created.

fprintf(fp, "%d,%s,%d,%d,%d,%s,%s\n", patients[patientCount].id, patients[patientCount].name, patients[patientCount].age, patients[patientCount].annualClaim, patients[patientCount].plan, patients[patientCount].contactNum, patients[patientCount].address);
// data is getting append on file
fclose(fp); // closing the file

time_t s; // declaration of time object

struct tm * currentTime;

s = time(NULL); // Get the system time

currentTime = localtime( & s); // set the local time to current time

claims[patientCount].id = patients[patientCount].id; // assigning structure patient's id to structure claims's id

claims[patientCount].amountClaimed = 0; // initialising amountclaimed to 0

claims[patientCount].claimedYear = currentTime -> tm_hour + 1900; // assigning current time + 1900 hours to claimedyear

if (patients[patientCount].annualClaim == true) // ckecking condition foor annualclaim which we have already defined on line no 156 in if statement

{

if (patients[patientCount].plan == 1) // nested if i.e if annualclaim == true then this will execute and structure patients plan value == 1 then

claims[patientCount].remaininigAmount = 120000; //assigning 120000 to reamining amount

else if (patients[patientCount].plan == 2) // else contition i.e structure patients plan value == 2 then

claims[patientCount].remaininigAmount = 150000; //assigning 150000 to reamining amount

else

claims[patientCount].remaininigAmount = 200000; //assigning 200000 to reamining amount

}

else // outer else
// this will execute when annualclaim == false


{

if (patients[patientCount].plan == 1) // when structure patients plan value == 1 then

claims[patientCount].remaininigAmount = 600000; //assigning 600000 to reamining amount

else if (patients[patientCount].plan == 2) //else contition i.e structure patients plan value == 2 then

claims[patientCount].remaininigAmount = 750000; //assigning 750000 to reamining amount

else

claims[patientCount].remaininigAmount = 1000000; ////assigning 1000000 to reamining amount

}

patientCount++; // post increment in patientcount

fp = fopen("claims.txt", "a"); // opening a file in append mode i.e Data is added to the end of the file.

if (fp == NULL) //If the file does not exist

printf("File Dont exist");// file does not exist

fprintf(fp, "%d,%d,%d,%d\n", claims[patientCount].id, claims[patientCount].claimedYear, claims[patientCount].amountClaimed, claims[patientCount].remaininigAmount);
// data is getting append on file
fclose(fp); // closing the file

system("pause");//This is a Windows-specific command, which tells the OS to run the pause program.
//This program waits to be terminated, and halts the exceution of the parent C program.

//Only after the pause program is terminated, will the original program continue.

}


Related Solutions

Hello sir can you plz change my below code like change names , function name and...
Hello sir can you plz change my below code like change names , function name and add comments so it wont look same but run same. change as much as you can thank you. #include<stdio.h> #include<stdlib.h> #include<stdbool.h> #include<string.h> #include<time.h> struct patient { int id; int age; bool annualClaim; int plan; char name[30]; char contactNum[15]; char address[50]; }; #define MAX_LENGTH 500 struct patient patients[100]; int patientCount = 0; struct claim { int id; int claimedYear; int amountClaimed; int remaininigAmount; }; struct...
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: ");...
hello , could you please answer this question for me in details , my teacher want...
hello , could you please answer this question for me in details , my teacher want more than 400 word ?. it is an essay . 1) Discuss the application of Classical conditioning in reducing Anxiety.!!
plz answer two questions in details and explain. each part thanks. its my exam 1. Jin...
plz answer two questions in details and explain. each part thanks. its my exam 1. Jin is an accountant.  Nuankae is a sous chef at a successful Spanish restaurant on E. 68th Street, called “Que Lastima.”  Jin and Nuankae (who likes to be called “Kae”) both enjoy Louisiana cuisine and met at a cooking class.  They decide to open a small restaurant in northern Manhattan, called “Kae-Jin Cookin.’” Jin and Kae meet with you to seek advice on how to establish their business.  They...
In Python I have a code: here's my problem, and below it is my code. Below...
In Python I have a code: here's my problem, and below it is my code. Below that is the error I received. Please assist. Complete the swapCaps() function to change all lowercase letters in string to uppercase letters and all uppercase letters to lowercase letters. Anything else remains the same. Examples: swapCaps( 'Hope you are all enjoying October' ) returns 'hOPE YOU ARE ALL ENJOYING oCTOBER' swapCaps( 'i hope my caps lock does not get stuck on' ) returns 'I...
Below is my code in C#, When I run it, the output shows System.32[], Can you...
Below is my code in C#, When I run it, the output shows System.32[], Can you please check and let me know what is the problem in the code. class Program { static void Main(string[] args) { int number=12; Console.WriteLine(FizzArray(number)); } public static int[] FizzArray(int number) { int[] array = new int[number]; for (int i = 1; i < number; i++) array[i] = i; return array; }
The following 3 instances of code was provided by my embedded systems course. Can you explain...
The following 3 instances of code was provided by my embedded systems course. Can you explain what is happening in each code segment? === code 1 === void foo() { uint8_t a=2; uint8_t b[]={b0, b1, b2}; // They are the last three digits of your A# uint8_t* c=b; uint8_t* d=&a; } === code 2 === __extension__ typedef struct tagT1CONBITS { union { struct { unsigned :1; unsigned TCS:1; unsigned TSYNC:1; unsigned :1; unsigned TCKPS:2; unsigned TGATE:1; unsigned :6; unsigned TSIDL:1;...
Can you please explain in detail what each line of code stands for in the Main...
Can you please explain in detail what each line of code stands for in the Main method import java.util.Scanner; public class CashRegister { private static Scanner scanner = new Scanner(System.in); private static int dollarBills[] = {1, 2, 5, 10, 20, 50, 100}; private static int cents[] = {25, 10, 5, 1}; public static void main(String[] args) { double totalAmount = 0; int count = 0; for (int i = 0; i < dollarBills.length; i++) { count = getBillCount("How many $"...
Can you please see what I have done wrong with my program code and explain, This...
Can you please see what I have done wrong with my program code and explain, This python program is a guess my number program. I can not figure out what I have done wrong. When you enter a letter into the program, its supposed to say "Numbers Only" as a response. I can not seem to figure it out.. instead of an error message. import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if...
My code is supposed to display a stacked bar chart of my average week. Can you...
My code is supposed to display a stacked bar chart of my average week. Can you help me locate my errors and fix them? I'm just so confused <!DOCTYPE html> <html lang = "en"> <head> <meta charset="UTF-8" /> <title>Assignment 3: My Weekly Schedule</title> <script src="https://d3js.org/d3.v3.min.js" charset="utf-8"></script> <style type="text/css"> svg { font: 10px sans-serif; shape-rendering: crispEdges; } .axis path, .axis line{ fill: none; stroke: #000; } path.domain { stroke: none; } .y .tick line{ stroke: #ddd; } </style> </head> <body> <script...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT