Question
Checker guidelines: for compatibility with the checker, the struct array must be called students, and the names of the fields must be Name, Credits, and
The trickiest part is getting the letter grades into a column vector field. Try something like this:
students(sheet).Grades = [txtData{2:end, 2}]
Here's the function for reference:
function gpas = GPA(Student) %Declare the variables totalGrades=0; totCredits=0; totMajorGrades=0; totMajorCredits=0; %Use a for loop, to calculate the total credits, total grades, %total major grades, and total major credits for i=1:length(Student.Grades) %Check the student grade is equal to A if (Student.Grades(i)=='A') % calculate the total grades and credits totalGrades=totalGrades+4*Student.Credits(i); totCredits=totCredits+Student.Credits(i); if(Student.Major(i)) % calculate the total major grades and major credits totMajorGrades=totMajorGrades+4*Student.Credits(i); totMajorCredits=totMajorCredits+Student.Credits(i); end %Check the student grade is equal to B elseif (Student.Grades(i)=='B') % calculate the total grades and credits totalGrades=totalGrades+3*Student.Credits(i); totCredits=totCredits+Student.Credits(i); if(Student.Major(i)) % calculate the total major grades and major credits totMajorGrades=totMajorGrades+3*Student.Credits(i); totMajorCredits=totMajorCredits+Student.Credits(i); end %Check the student grade is equal to C elseif (Student.Grades(i)=='C') % calculate the total grades and credits totalGrades=totalGrades+2*Student.Credits(i); totCredits=totCredits+Student.Credits(i); if(Student.Major(i)) % calculate the total major grades and major credits totMajorGrades=totMajorGrades+2*Student.Credits(i); totMajorCredits=totMajorCredits+Student.Credits(i); end %Check the student grade is equal to D elseif (Student.Grades(i)=='D') % calculate the total grades and credits totalGrades=totalGrades+Student.Credits(i); totCredits=totCredits+Student.Credits(i); if(Student.Major(i)) % calculate the total major grades and major credits totMajorGrades=totMajorGrades+Student.Credits(i); totMajorCredits=totMajorCredits+Student.Credits(i); end %Check the student grade is equal to F elseif (Student.Grades(i)=='F') % calculate the total credits totCredits=totCredits+Student.Credits(i); if(Student.Major(i)) % calculate the total major credits totMajorCredits=totMajorCredits+Student.Credits(i); end end end
%calculate the gpas gpas=[totalGrades/totCredits totMajorGrades/totMajorCredits]; end
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started