Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This question is done on the language C. starter code: /* CSC A48 - Winter 2020 * * Exercise 6 - The Resistant Strain *

This question is done on the language C.

image text in transcribed

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

starter code:

/* CSC A48 - Winter 2020 * * Exercise 6 - The Resistant Strain * * Please read the comments below carefully, they * describe your task in detail. Any clarifications * and corrections will be posted to Piazza so please * keep an eye on the forum! * * Starter code: Joe Armitage & William Song, 2020 */

#include

#define TISSUE_SIZE (10)

typedef enum tissueType { _ = '_', // Uninfected cell I = 'I', // Infected cell S = 'S', // Good bacterium: Sakinacoccus C = 'C', // Good bacterium: Charlestridium tetani } TissueType;

typedef struct cell { TissueType type; // Indicates if good bacterium, infected cell or uninfected cell int health; // For good bacteria: the multiple the range is extended by, for infected cells, // number of lives } Cell;

typedef Cell Tissue[TISSUE_SIZE][TISSUE_SIZE]; // A nice name for a 2D Cell array -> Tissue

/** * CRUNCHY: Use this helper helper function to implement Charles AND Sakina * HINT: I would implement numberOfCharlesInRange like this: * Pattern charles_patterns[4] = {{2, 0}, {0, 2}, {-2, 0}, {0, -2}}; * return numberOfBacteriaInRange(tissue_sample, x, y, charles_patterns, 4, C); */ typedef int Pattern[2]; int numberOfBacteriaInRange(Tissue tissue, int x, int y, Pattern pattern[], int num_patterns, TissueType type) { /** CRUNCHIER: do this without looping over all the cells (again) (attacks are symmetric!) */ int counter = 0;

return counter; }

/** * Return the number of Charlestridium tetani within tissue_sample that can attack position x, y. * * Legal attacks are limited to the pattern (where X is a legal attack and C is the bacterium): * _ _ X _ _ * _ _ _ _ _ * X _ C _ X * _ _ _ _ _ * _ _ X _ _ * where each Charlestridium tetani can attack in any one direction in this pattern for a certain * number of attacks. For example, if one had 2 health, its pattern would be limited to: * _ _ _ _ X _ _ _ _ * _ _ _ _ _ _ _ _ _ * _ _ _ _ X _ _ _ _ * _ _ _ _ _ _ _ _ _ * X _ X _ C _ X _ X * _ _ _ _ _ _ _ _ _ * _ _ _ _ X _ _ _ _ * _ _ _ _ _ _ _ _ _ * _ _ _ _ X _ _ _ _ * * INPUT: * tissue_sample: * - an array of arrays of Cells with dimensions TISSUE_SIZE * TISSUE_SIZE * - gives positions of each bacterium and each infected cell * - each cell can only contain one of the following types: * - `I`: Infected Cell * - `L`: A Charlestridium tetani bacterium * - `S`: A Sakinacoccus bacterium * - `_`: An uninfected cell (bacteria will ignore these) * x: the row coordinate (starting at 0) of the cell (within tissue_sample) to be checked. * y: the column coordinate (starting at 0) of the cell (within tissue_sample) to be checked. * * RETURN: the number of Charlestridium tetani that can make a legal attack to position x, y */ int numberOfCharlesInRange(Tissue tissue_sample, int x, int y) { /** TODO: implement this function, satisfying the description above. */

return 0; // replace this with your implementation }

/** * Return the number of Sakinacoccus within tissue_sample that can attack position x, y. * * Legal attacks are limited to the pattern (where X is a legal attack and S is the bacterium): * _ _ _ _ _ * _ X _ X _ * _ _ S _ _ * _ X _ X _ * _ _ _ _ _ * where each Sakinacoccus can attack in any one direction in this pattern for a certain * number of attacks. For example, if one had 2 health, its pattern would be limited to: * X _ _ _ X * _ X _ X _ * _ _ S _ _ * _ X _ X _ * X _ _ _ X * * INPUT: * tissue_sample: * - an array of arrays of Cells with dimensions TISSUE_SIZE * TISSUE_SIZE * - gives positions of each bacterium and each infected cell * - each cell can only contain one of the following types: * - `I`: Infected Cell * - `L`: A Charlestridium tetani bacterium * - `S`: A Sakinacoccus bacterium * - `_`: An uninfected cell (bacteria will ignore these) * x: the row coordinate (starting at 0) of the cell (within tissue_sample) to be checked. * y: the column coordinate (starting at 0) of the cell (within tissue_sample) to be checked. * * RETURN: the number of Sakinacoccus that can make a legal attack to position x, y */ int numberOfSakinaInRange(Tissue tissue_sample, int x, int y) { /** TODO: implement this function, satisfying the description above. */

return 0; // replace this with your implementation }

/** * Computes the percentage of infected cells in the given tissue sample which can be killed * by Sakinacoccus or Charlestridium tetani bacteria in the sample and updates the tissue sample to * the state after the attacks. * * INPUT: * tissue_sample: * - an array of arrays of Cells with dimensions TISSUE_SIZE * TISSUE_SIZE * - gives positions of each bacterium and each infected cell * - each cell can only contain one of the following types: * - `I`: Infected Cell * - `L`: A Charlestridium tetani bacterium * - `S`: A Sakinacoccus bacterium * - `_`: An uninfected cell (bacteria will ignore these) * - REQ: there is at least one infected cell * * OUTPUT: * tissue_sample: - mutated such that: * - All `I` cells have their health reduced by the number of good bacteria that can attack. * - Any `I` cell whose health drops to Think about how this 2D array is stored in memory... */

return 0; }

/** * Prints the tissue sample in a human readable format. * * INPUT: * tissue_sample: * - an array of arrays of Cells with dimensions TISSUE_SIZE * TISSUE_SIZE * - gives positions of each bacterium and each infected cell * - each cell can only contain one of the following types: * - `I`: Infected Cell * - `L`: A Charlestridium tetani bacterium * - `S`: A Sakinacoccus bacterium * - `_`: An uninfected cell (bacteria will ignore these) * * NOTE: The displayed indices do not match the implementation. * That is, they start at 1 (when we know array indices start at 0). * This is more obvious for the column indices, which are A - J. */ void printTissueSample(Tissue tissue_sample) { printf(" A B C D E F G H I J "); for (int x = 0; x

// We NEED this compiler directive to test your code with our own main(). Don't break it. #ifndef __TESTING // this compiler directive int main() { // Please note that these are JUST EXAMPLES! You will be tested on a wide range of data.

printf("====Jackson's Sample==== "); Tissue jackson_sample = { {{_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}}, {{_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}}, {{_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}}, {{_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}}, {{_, 0}, {_, 0}, {_, 0}, {_, 0}, {C, 1}, {_, 0}, {I, 1}, {_, 0}, {_, 0}, {_, 0}}, {{_, 0}, {_, 0}, {_, 0}, {_, 0}, {I, 3}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}}, {{_, 0}, {_, 0}, {_, 0}, {_, 0}, {I, 2}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}}, {{_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}}, {{_, 0}, {_, 0}, {S, 2}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}}, {{_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}}}; printTissueSample(jackson_sample); printf("Calculated: Killed %06.2f%% of bacteria ", testBacteria(jackson_sample)); printf(" Expected: Killed 066.67%% of bacteria "); printTissueSample(jackson_sample);

// Feel free to add your own examples/tests here printf("====Silviu's Sample==== "); Tissue silviu_sample = { {{_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}}, {{_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}}, {{_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {I, 1}, {_, 0}}, {{_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {I, 1}, {_, 0}, {_, 0}, {I, 1}, {_, 0}}, {{_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {I, 1}}, {{_, 0}, {_, 0}, {_, 0}, {I, 1}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {I, 1}, {S, 2}}, {{_, 0}, {_, 0}, {_, 0}, {I, 1}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}}, {{_, 0}, {_, 0}, {_, 0}, {C, 3}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {C, 2}, {_, 0}}, {{_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {I, 1}, {I, 1}, {I, 1}}, {{_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {_, 0}, {I, 1}, {_, 0}}}; printTissueSample(silviu_sample); printf("Calculated: Killed %06.2f%% of bacteria ", testBacteria(silviu_sample)); printf(" Expected: Killed 036.36%% of bacteria "); printTissueSample(silviu_sample); } #endif // and this compiler directive

Hi student, We need your help again. The virus has mutated and now not only is more virulent, but also has gained some resistance to our bacterial treatment regime! It now takes many bacteria attacking some viral host cells to kill them. Well, that's the bad news; but once again this comes with good news: our biology professor/magician has engineered some new virophage bacterial strains that are more effective, too. Although the virus is just as resistant to these new bacteria, these strains are more motile; that is, they can move more! At least, we hope they are effective. We need you to help us find out. This time, we want you to create a testBacteria function that, given a 2D array, will return a percentage of how many of the infected cells were destroyed as well as modify the tissue. Attached is some starter code. We are going to be busy culturing more of these bacteria to save us from extinction, so we're relying on you to implement this function! The Bacteria Here are how the two bacteria strains we have developed can attack infected cells ( xs represent cells we could kill, s and represent our bacteria, s represent uninfected cells). Let k be a variable per cell, representing its health (for bacteria, number of moves they can make). Sakinacoccus can move k spaces diagonally at 45 degrees to consume an infected cell, like so: ok= 1 IX IX IX | | X | ok= 2 X 1 X IX 1 X | X XL | Charlestridium tetani: they can move exactly two steps at a time, k times in any cardinal direction (up, down, left, or right), like so: ok= 1 TIX ok= 2 X | L | 1 X | L | | X 0 TIL IX IIII III IX . . 1 X | | X | | Each bacterium can only move from its starting position. They cannot move somewhere, then move again. They can attack as many infected cells as they can reach, only from their starting position. Tissue Samples We have two new patients (Jackson and Silviu) and samples of their tissue that we can test our bacteria on. Each tissue sample is square, perfect for representing as a 2D array (how convenient, right?). We will supply you with these tissue samples as 2D arrays of structs whose values have the following meanings: type : What kind of cell this is (bacterium, infected, uninfected) o 1: Infected Cell os: A Sakinacoccus bacterium o C: A Charlestridium tetani bacterium o : An uninfected cell (bacteria will ignore these) health : the "strength" of this cell o for 1 : the number of good bacteria needed to kill it (always > 0) o for s and c: the number steps they can take in one direction (always > 0) o for : this will always be (always = 0) No other value will appear in these arrays. Your Task Download the starter: the resistant strain.c Implement the functions: int numberofsakinaInRange(Tissue tissue_sample, int x, int y) int numberofcharlesInRange(Tissue tissue_sample, int x, int y) double testBacteria(Tissue tissue_sample) Again, the former 2 functions are designed as helpers for the latter. Use them wisely. We may also test them individually. Note: Now, you will be mutating the tissue_sample in testBacteria. Implementation Details A Tissue is a compound data type that is just a 2D cell array that has been renamed: typedef Cell Tissue[TISSUE_SIZE] [TISSUE_SIZE]; Each tissue sample is exactly TISSUE SIZE * TISSUE SIZE in dimensions Each row is TISSUE_SIZE long. o There are TISSUE_SIZE columns in every tissue sample array. o The indices are, in order, [ROW][COLUMN]. Function arguments should be mutated by only by testBacteria and only as documented. The characters representing each type of bacterium, infection, etc. are enumerated in the Tissue Type enum. You should not use the characters directly now, but rather these variables. Some Notes Once a cell has been killed, it cannot be killed again. . W can change tissue size. We will never change the defined variable names in this case TISSUE_SIZE), but we may change the associated value. For clarity, we may use #define TISSUE_SIZE (11) instead of #define TISSUE_SIZE (10) and your code must still work. TISSUE SIZE is guaranteed to be greater than 0 (for everyone's sake). CRUNCHY parts are totally optional; doing them will just impress us and help you learn. Unless you're already confident in your solution, don't attempt them. If you're extremely confident in your crunchy solution, you can submit that. It's up to you. You can create more helper functions if you wish. A Sakinacoccus with k= 2 will have an attach pattern like below: IX IX IX IX Examples Example 1 Cells will only extend their attack pattern, not move and change their direction Input: _0 _0 X1 _0 X1 _0_0_0 x10 _0 x1 52 _0_0 _0_0_0_0 x1 Output of testBacteria 0.600000 Example 2 Cells can be killed after they are attacked by multiple bacteria. The bacteria don't have to be of the same strain. Input: _0_0 (1 _053 _O_0 X2_0_0 _O X2 _0 _O X2 _0 _o si _0x2 Output of testBacteria 0.500000 Submission Do not modify anything other than the functions which you're supposed to implement. Remove any printf() statements you may have added while testing/debugging your solution. o Your functions (other than main ) should print nothing! Do not post any partial solutions or descriptions of your solution algorithm to the Piazza forum. If you have questions, please bring these to office hours! Hi student, We need your help again. The virus has mutated and now not only is more virulent, but also has gained some resistance to our bacterial treatment regime! It now takes many bacteria attacking some viral host cells to kill them. Well, that's the bad news; but once again this comes with good news: our biology professor/magician has engineered some new virophage bacterial strains that are more effective, too. Although the virus is just as resistant to these new bacteria, these strains are more motile; that is, they can move more! At least, we hope they are effective. We need you to help us find out. This time, we want you to create a testBacteria function that, given a 2D array, will return a percentage of how many of the infected cells were destroyed as well as modify the tissue. Attached is some starter code. We are going to be busy culturing more of these bacteria to save us from extinction, so we're relying on you to implement this function! The Bacteria Here are how the two bacteria strains we have developed can attack infected cells ( xs represent cells we could kill, s and represent our bacteria, s represent uninfected cells). Let k be a variable per cell, representing its health (for bacteria, number of moves they can make). Sakinacoccus can move k spaces diagonally at 45 degrees to consume an infected cell, like so: ok= 1 IX IX IX | | X | ok= 2 X 1 X IX 1 X | X XL | Charlestridium tetani: they can move exactly two steps at a time, k times in any cardinal direction (up, down, left, or right), like so: ok= 1 TIX ok= 2 X | L | 1 X | L | | X 0 TIL IX IIII III IX . . 1 X | | X | | Each bacterium can only move from its starting position. They cannot move somewhere, then move again. They can attack as many infected cells as they can reach, only from their starting position. Tissue Samples We have two new patients (Jackson and Silviu) and samples of their tissue that we can test our bacteria on. Each tissue sample is square, perfect for representing as a 2D array (how convenient, right?). We will supply you with these tissue samples as 2D arrays of structs whose values have the following meanings: type : What kind of cell this is (bacterium, infected, uninfected) o 1: Infected Cell os: A Sakinacoccus bacterium o C: A Charlestridium tetani bacterium o : An uninfected cell (bacteria will ignore these) health : the "strength" of this cell o for 1 : the number of good bacteria needed to kill it (always > 0) o for s and c: the number steps they can take in one direction (always > 0) o for : this will always be (always = 0) No other value will appear in these arrays. Your Task Download the starter: the resistant strain.c Implement the functions: int numberofsakinaInRange(Tissue tissue_sample, int x, int y) int numberofcharlesInRange(Tissue tissue_sample, int x, int y) double testBacteria(Tissue tissue_sample) Again, the former 2 functions are designed as helpers for the latter. Use them wisely. We may also test them individually. Note: Now, you will be mutating the tissue_sample in testBacteria. Implementation Details A Tissue is a compound data type that is just a 2D cell array that has been renamed: typedef Cell Tissue[TISSUE_SIZE] [TISSUE_SIZE]; Each tissue sample is exactly TISSUE SIZE * TISSUE SIZE in dimensions Each row is TISSUE_SIZE long. o There are TISSUE_SIZE columns in every tissue sample array. o The indices are, in order, [ROW][COLUMN]. Function arguments should be mutated by only by testBacteria and only as documented. The characters representing each type of bacterium, infection, etc. are enumerated in the Tissue Type enum. You should not use the characters directly now, but rather these variables. Some Notes Once a cell has been killed, it cannot be killed again. . W can change tissue size. We will never change the defined variable names in this case TISSUE_SIZE), but we may change the associated value. For clarity, we may use #define TISSUE_SIZE (11) instead of #define TISSUE_SIZE (10) and your code must still work. TISSUE SIZE is guaranteed to be greater than 0 (for everyone's sake). CRUNCHY parts are totally optional; doing them will just impress us and help you learn. Unless you're already confident in your solution, don't attempt them. If you're extremely confident in your crunchy solution, you can submit that. It's up to you. You can create more helper functions if you wish. A Sakinacoccus with k= 2 will have an attach pattern like below: IX IX IX IX Examples Example 1 Cells will only extend their attack pattern, not move and change their direction Input: _0 _0 X1 _0 X1 _0_0_0 x10 _0 x1 52 _0_0 _0_0_0_0 x1 Output of testBacteria 0.600000 Example 2 Cells can be killed after they are attacked by multiple bacteria. The bacteria don't have to be of the same strain. Input: _0_0 (1 _053 _O_0 X2_0_0 _O X2 _0 _O X2 _0 _o si _0x2 Output of testBacteria 0.500000 Submission Do not modify anything other than the functions which you're supposed to implement. Remove any printf() statements you may have added while testing/debugging your solution. o Your functions (other than main ) should print nothing! Do not post any partial solutions or descriptions of your solution algorithm to the Piazza forum. If you have questions, please bring these to office hours

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Are there any questions that you want to ask?

Answered: 1 week ago