C PROGRAM The text files are within a folder called Term. Each text file is name
ID: 3828625 • Letter: C
Question
C PROGRAM
The text files are within a folder called Term. Each text file is named drugID.txt (ex. 0001.txt, 0002.txt, 0003.txt).
Contents of 0001.txt:
D V C F A E t
50 25 0.86 0.8 0.8 0.231 3
0002.txt:
D V C F A E t
20 15 0.72 0.3 0.68 0.3 -5
0003.txt:
D V C F A E t
45 20 0.78 0.9 0.68 0.342 2
D = drug dose given
V = volume distributed in the body
C = concentration of the drug at time t
F = fraction of dose which has been absorbed (also called bioavailability) A = absorption rate constant
E = elimination rate constant
t = time
absorption part = A ×F ×D ×e^-At
elimination part = E ×V ×C
Using this information write a C program to do the Following:
Use Case A: "[Enter the Data File Location]"
The user selects option a) from the menu
The user is asked to enter the file location (full path)
The program displays the main menu
Use Case B: "[Enter a Drug ID]"
The user selects option b) from the menu
The user is asked to enter a particular Drug ID
The program displays the main menu
Use Case C: "[Display Drug Info]"
The user selects option c) from the menu
The program goes to the file location (entered from option A) and locate the drug info file (txt)
based on the drug ID (entered from option B)
The program displays the main menu
Use Case D: "[Get Time]”
The user selects option d) from the menu
The user is asked to enter the time at which to compute pharmacokinetic info
The program displays the main menu
Use Case E: "[Get Pharmacokinetics Info]”
The user selects option e) from the menu
The program displays:
o a table with the values for A, F, D, E, V, C, and t. o the absorption part at time t, and
o the elimination part at time t
3. The program displays the main menu
Explanation / Answer
#include<stdio.h>
#include<string.h>
#include<math.h>
char menu() {
printf("A. Enter file location B. Enter Drug ID C. Display drug info D. Get time E. Get Pharmacokinetics Info Enter your choice: ");
return getchar();
}
void readInfo(char *file, int *d, int *v, double *c, double *f, double *a, double *e, int *t){
FILE *fp = fopen(file, "r");
char line[20];
fgets(line, 50, fp); //to ignore line 1
fscanf(fp, "%d %d %lf %lf %lf %lf %d", d, v, c, f, a, e, t);
}
void showInfo(int d, int v, double c, double f, double a, double e, int t, double ap, double ep, int flag) {
printf("Drug dose given: %d ",d);
printf("volume distributed in the body: %d ",v);
printf("concentration of the drug at time t: %lf ",c);
printf("fraction of dose which has been absorbed (also called bioavailability): %lf ",f);
printf("absorption rate constant: %lf ",a);
printf("elimination rate constant: %lf ",e);
printf("time (t): %d ",t);
if (flag == 1) {
printf("absorption part: %lf ",ap);
printf("elimination part: %lf ",ep);
}
}
void main() {
char option;
char loc[80] = "", did[20] = "", fLoc[100];
int D,V,t,p_t;
double C,F,A,E,absob_p,elim_p ;
while(1) {
option = menu();
switch(option) {
case 'A':
case 'a':
printf("Please enter location: ");
scanf("%s", loc);
break;
case 'B':
case 'b':
printf("Please enter Drug ID: ");
scanf("%s", did);
break;
case 'C':
case 'c':
strcpy(fLoc,loc);
strcat(fLoc,"/Term/");
strcat(fLoc,did);
strcat(fLoc,".txt");
readInfo(fLoc, &D, &V, &C, &F, &A, &E, &t);
showInfo(D,V,C,F,A,E,t,absob_p,elim_p,0);
break;
case 'D':
case 'd':
printf("Enter the time at which to compute pharmacokinetic info: ");
scanf("%d", &p_t);
break;
case 'E':
case 'e':
absob_p = A*F*D*exp(-A*p_t); //calculate value as gven
elim_p = E*V*C; //calculate as given
showInfo(D,V,C,F,A,E,t,absob_p,elim_p,1);
break;
default:
break;
}
}
}
The code is very straingt forward, so havnt commented much line of the code. If you think you need comments nd more clarification, please do comment below. I shall be glad to help you.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.