C programming help Creat a C program A group of scientists

C programming help

Creat a C program : A group of scientists are testing a new drug to evaluate its effect on cancer cells. Their tests involved adding the drug to a variety of samples of cancerous cells, and observing the samples over a course of 7 days. On the 7th day, they note the percentage of the original cells that are still alive. Their results are stored in a text file. Manual analysis of the data is very tedious, so you have been hired to write a program to help them analyze their results. You program should read the percentages from the text file and store the number of samples that had each percentage of cells left.

Your program MUST also include the following 4 functions, to analyze the results stored in the array:

1. displayResults: This function takes the array and its length as parameters and prints out the number of samples with each percentage of cells left

2. getMaxLeft: This function takes the array and its size as parameters and returns the percentage of cells left with the maximum number of samples that had this percentage after the seven days.

3. getAverageLeft: This function takes the array and its length as parameters and returns the average percentage of cells left

4. getNumSamples: This function takes the array and its length and a percentage p (an integer) as parameters and returns the number of samples found with less than p% cells left.

When run your program should execute each of the functions from 1 to 4 in that order, and output the results as shown in the sample run below.

Restrictions:

· the input file called results.txt has 201 integers – 200 bits of data and the end of data marker 999

· the input file can contain any number of values on each line. But there is always a space between the numbers.

· all of the data in the file will be valid percentages from 0 – 100 inclusive · The end of the data is marked by 999

Sample Results.txt file

31 53 2 85 77 37 76 24 51 83 79 57 22 19 54 70 62 35 39 61

73 1 57 81 74 63 33 30 39 58 43 64 66 56 5 51 89 50 82 84

86 96 44 18 28 68 9 8 56 47 69 21 34 85 40 90 45 76 91 15

30 77 24 43 61 23 99 51 72 87 70 95 97 49 92 96 86 34 73 0

26 81 100 53 87 46 49 0 92 33 28 56 98 34 66 99 60 27 40 10

46 14 78 11 22 73 0 81 43 90 95 68 35 12 24 39 99 9 20 48

55 2 72 80 77 46 12 69 25 6 44 59 45 21 60 43 20 82 87 64

75 41 76 23 92 52 22 71 68 14 61 35 62 82 48 20 50 83 46 36 18 53 37 40 3 91 12 94 46 41

23 61 36 99 69 97 67 2 45 13

82 32 48 51 60 96 66 20 52 45 89 54 64 9 7 8 97 100 56 39

999

Sample Run Results

     %              Number of Cases

---------------------------------------

0                  3

1                  1

2                  3

3                  1

4                  0

5                  1

6                 1

.

.

      98                  4

      99                  4

      100                2

The maximum number of cases – 5 had 46% left

The average% of cells left is 52.20

For what % would you like to find the number of cases?

96 (user input)

There were 3 cases with 100% of the cells left

Solution

SOURCE CODE:

#include<stdio.h>

void displayResults(int length,int array[length])
{
   int i=0;
   printf(\"\ Percentage\\tNumber of Cases\ \");
   printf(\"\ -------------------------------\");
   for(i=0;i<=length;i++)
   printf(\"\ %d\\t\\t%d\",i,array[i]);
}

void getMaxLeft(int length,int array[length])
{
   int i=0,index=0;
   for(i=0;i<=length;i++)
   {
       if(array[index]<array[i])
           index=i;
   }
   printf(\"\ The maximum number of cases %d had %d percentage left\",array[index],index);
}

void getAverageLeft(int length,int array[length])
{
   int i=0,j=0;
   double avg=0.0;
   for(i=0;i<=length;i++)
       if(array[i]>0)
       {
           avg=avg+(double)i;
           j++;
       }
   avg=avg/(double)j;
   printf(\"\ The average of cells left is %g\",avg);
}

void getNumSamples(int length,int array[length],int p)
{
   if(p<=length)
       printf(\"\ The were %d cases with %d percentage cells left\",array[p],p);
  
}

int main()
{
   int i=0;
   int array[101];
   FILE *fp1;
fp1 = fopen(\"results.txt\", \"r\"); //Input File
int ch=getc(fp1);
for(i=0;i<101;i++)
   array[i]=0;
   for(; fscanf(fp1, \"%d\", &i) && !feof(fp1);)
   {
       if(i==999)
           break;
       array[i]++;
   }
   fclose(fp1);
   displayResults(100,array);
   getMaxLeft(100,array);
   getAverageLeft(100,array);
   printf(\"\ For what percent would you like to find the number of cases?\");
   scanf(\"%d\",&i);
   getNumSamples(100,array,i);
   return -1;
}

SAMPLE OUTPUT:


Percentage Number of Cases

-------------------------------
0 3
1 2
2 3
3 1
4 0
5 1
6 1
7 1
8 2
9 3
10 1
11 1
12 3
13 1
14 2
15 1
16 0
17 0
18 2
19 1
20 4
21 2
22 3
23 3
24 3
25 1
26 1
27 1
28 2
29 0
30 2
31 0
32 1
33 2
34 3
35 3
36 2
37 2
38 0
39 4
40 3
41 2
42 0
43 4
44 2
45 4
46 5
47 1
48 3
49 2
50 2
51 4
52 2
53 3
54 2
55 1
56 4
57 2
58 1
59 1
60 3
61 4
62 2
63 1
64 3
65 0
66 3
67 1
68 3
69 3
70 2
71 1
72 2
73 3
74 1
75 1
76 3
77 3
78 1
79 1
80 1
81 3
82 4
83 2
84 1
85 2
86 2
87 3
88 0
89 2
90 2
91 2
92 3
93 0
94 1
95 2
96 3
97 3
98 1
99 4
100 2

The maximum number of cases 5 had 46 percentage left

The average of cells left is 50.8462

For what percent would you like to find the number of cases?96

The were 3 cases with 96 percentage cells left
.

C programming help Creat a C program : A group of scientists are testing a new drug to evaluate its effect on cancer cells. Their tests involved adding the drug
C programming help Creat a C program : A group of scientists are testing a new drug to evaluate its effect on cancer cells. Their tests involved adding the drug
C programming help Creat a C program : A group of scientists are testing a new drug to evaluate its effect on cancer cells. Their tests involved adding the drug
C programming help Creat a C program : A group of scientists are testing a new drug to evaluate its effect on cancer cells. Their tests involved adding the drug
C programming help Creat a C program : A group of scientists are testing a new drug to evaluate its effect on cancer cells. Their tests involved adding the drug

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site