In: Computer Science
Make pesodocode of this code.
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);
}
int menu()
int ch;
do {
system("cls");
printf("Select one of the below option to continue\n");
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", & ch);
} while (ch > 5 || ch < 1);
return ch;
}
int main()
{
int ch;
loadData();
do {
ch = menu();
if (ch == 1)
subscribe();
else if (ch == 2)
claimProcess();
else if (ch == 3)
accountInfo();
else if (ch == 4)
searchingFunctionalities();
else
break;
} while (ch != 5);
system("pause");
return 0;
}
Pseudo code of the above code is as follows,
Function loadData(){
set delimiter as newline.
open file "patients.txt" in read mode and
if file has no data
then display "File not found"
return pointer
EndIf
Precondition : File has data
While file has data do the following
If file has only one data
Then exit from loop.
If file line has the end of the character
Then exit from loop .
Read the id of the patient from file.convert it into integer from string format.split from the line using delimiter.
Copy the name from the file into name using the delimiter to split the name from file.
Read the age of the patient from file.
Read the annual claim of the patient from file.
Read the plan from the file.
Copy the contact number of patient from file .
Copy the address of patient file.
Copy the end of string character.
Close the file "patient.txt".
Open the file "claim.txt" in read mode.
While file has data do the following
If file has one data
Then exit from loop.
If file has only new line,
Then break from loop.
Read id from the file .
Read claimed Year from file.
Read amount to claim from file.
Read the remaining amount from file.
End the file using the end of string character.
Close the file "Claim.txt"
Close the function loadData.
}
Function menu(){
Do the following until the user reads character greater than 5 or lesser than 1.
Display menu as follows
Display "select one of the below option to continue".
Display "1-Insurance plan Subscription" in next line.
Display "2-Claim Processing" in next line.
Display "3-Accounts information" in next line.
Display "4-Searching Functionalities" in next line.
Display "5-Exit" in next line.
Return character.
}
Function main(){
Read the character from user.
Call function loadData().
Do the following unti the character not equals 5.
If the character equals 1
Then call function subscribe ().
Else if character equals 2
Then call function ClaimProcess().
Else if character equals 3
Then call function AccountInfo().
Else if character equals 4
Then call function searchingFunctionalities().
Else
return from function.
Exit from main function.
}