ITP 168: Introduction to MATLAB
Part 1: Get Parent Contributions
You will ask the user for the parent contributions. You will ask for each trait separately.
Unlike previous assignments, you must now make sure that the user enters in the right information. For
the A trait, the user must enter in two characters which are both “A”s (either upper or lower case). For
the B trait, the user must enter in two characters which are both “B”s (either upper or lower case).
Your code should not continue to the next part unless the user gives valid information. See the sample
output for what this part should look like.
Part 2: Figure Out Contributions
Now that we know the parent’s traits, we must figure out what are the different combinations each
parent can give. We must come up with the 4 distinct combinations.
For example, if Parent 1’s genes are AaBB then the contributions are AB, AB, aB, and aB. Even though
two of these are duplicates, we must present all 4 of them.
Determine both parent’s contributions.
Part 3: Print Punnett Square
Now that we know the parent’s contributions, you will display the Punnett Square to the command
window. You will print Parent 1’s contributions on the top row, and Parents 2’s contributions in the first
column so that the results are formatted like this:
In this example the cells in GREEN are Parent 1’s contribution, the cells in ORANGE are Parent 2’s
contributions. The cells in WHITE are the offspring combinations.
When you print the Punnett Square, order the offspring combinations such that the A traits appear first
and the B traits appear second. Also, if there is a dominant trait (given by an uppercase letter) then
place it before the recessive trait (given by a lowercase letter). This means that it should be written as
Aa and not aA. Use the sort() function to accomplish this.
Print your Punnett Square so that everything lines up nicely. Consider using field width parameters to
control the alignment of the first row.