Day 18 WH


I couldn't figure out how to get the program to work initially, so I called Sam and he told me that he figured out to replace the underscore with a period for the f_fingertip. The program worked after and I took some time to figure out how to print the count and percentage of each category. Overall the modifications weren't too difficult once you figured out how to print the counts.
/* Finger print program*/
/* It then references a function to compute the overall category.*/
#include <stdio.h>
int k,l,j,i=0;
double pow,pol,poa,arch_2,whorls_2,loop_2;//whorls_2 is equal to i becuase it must be double to calc percentage
//pow is percentage of whorls
/* Define a structure for the fingerprint information. */
/* The order for fingertips is right hand, thumb to pinky, */
/* and left hand, thumb to pinky. The codes are L for loops, */
/* W for whorls, and A for arches. */
struct fingerprint
{
int ID_number;
double overall_category;
char fingertip[10];
};
int main(void)
{
/* Declare and initialize variables. */
struct fingerprint new_print;
double compute_category(struct fingerprint f);
/* Specify information for the new fingerprint. */
new_print.ID_number = 2491009;
new_print.overall_category = 0;
new_print.fingertip[0] = 'W';
new_print.fingertip[1] = 'L';
new_print.fingertip[2] = 'L';
new_print.fingertip[3] = 'W';
new_print.fingertip[4] = 'A';
new_print.fingertip[5] = 'L';
new_print.fingertip[6] = 'L';
new_print.fingertip[7] = 'W';
new_print.fingertip[8] = 'A';
new_print.fingertip[9] = 'L';
for(k=0;k<=9;k++)
{
if(new_print.fingertip[k]=='W')
{
i++; //i is incrementing whirl hence the "W"
}
if(new_print.fingertip[k]=='L')
{
l++;
}
if(new_print.fingertip[k]=='A')
{
j++;
}
}

/* Reference function to compute overall category. */
/*Setting the int to double */
whorls_2=i;
loop_2=l;
arch_2=j;
new_print.overall_category = compute_category(new_print);
/* equating percentage */
pow= (whorls_2/10)*100; /*percentage of loop*/
pol= (loop_2/10)*100;
poa= (arch_2/10)*100;
/* Print overall category computed by the function. */
printf("Fingerprint Analysis for ID: %i \n",
new_print.ID_number);
printf("Overall Category: %.2f \n",new_print.overall_category);
printf("Numbers of whorls:%i\n",i);
printf("Numbers of loops:%i\n",l);
printf("Numbers of Arch:%i\n",j);
printf("Percentage of whorls:%lf percent\n",pow);
printf("Percentage of loop:%lf percent\n",pol);
printf("Percentage of arch:%lf percent\n",poa);

/* Exit program. */
return 0;
}
/*--------------------------------------------------------------*/
/* This function computes the overall category */
/* for a fingerprint. */
double compute_category(struct fingerprint f)
{
/* Declare and initialize variables. */
double Rt=0, Ri=0, Rm=0, Rr=0, Rp=0, Lt=0, Li=0, Lm=0, Lr=0,
Lp=0, num, den;
/* Set values based on whorls. */
if (f.fingertip[0] == 'W')
Rt = 16;
if (f.fingertip[1] == 'W')
Ri = 16;
if (f.fingertip[2] == 'W')
Rm = 8;
if (f.fingertip[3] == 'W')
Rr = 8;
if (f.fingertip[4] == 'W')
Rp = 4;
if (f.fingertip[5] == 'W')
Lt = 4;
if (f.fingertip[6] == 'W')
Li = 2;
if (f.fingertip[7] == 'W')
Lm = 2;
/* Compute the numerator and denominator for overall category. */
num = Ri + Rr + Lt + Lm + Lp + 1;
den = Rt + Rm + Rp + Li + Lr + 1;
return num/den;
}




Comments

Popular posts from this blog

Day_13