Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

4. Write a Matlab script file that calculates the student\'s grade point average

ID: 3282098 • Letter: 4

Question

4. Write a Matlab script file that calculates the student's grade point average, where A-4, B-3, C-2, D-1, and F 0. Your code must be written in such a way that the user is able to enter any number of courses. Test your function using the grades and credit hours shown in the tables below. The code must be written so that the user can enter their grades and associated credit hours. (Note: When using the "input" command to input a string variable, the syntax is: letter-grade input('Instructions', 's'). The 's' tells Matlab that the input will be a string variable. Also, the "if" conditional statement used with a string variable will use the following syntax: if letter-grade ='C'. Student A Grade B Credit Hours 4 4 Student B: Grade A Credit Hours

Explanation / Answer

for student A

define

a=['BBADABDB'] and h=[2 4 3 4 3 4 3 4]

function av = GPA(a,h)

for k=1:length(a)

if a(k) == 'A'

a(k) = 4;

elseif a(k) == 'B'

a(k) = 3;

elseif a(k) == 'C'

a(k) = 2;

elseif a(k) == 'D'

a(k) = 1;

elseif a(k) == 'F'

a(k) = 0;

end

end

av = sum((a.*h))/sum(h)

Now for student B

define

b=['AACBACBA'] and t=[2 3 3 1 3 1 3 3]

function av = GPA(b,t)

for k=1:length(b)

if b(k) == 'A'

b(k) = 4;

elseif b(k) == 'B'

b(k) = 3;

elseif b(k) == 'C'

b(k) = 2;

elseif b(k) == 'D'

b(k) = 1;

elseif b(k) == 'F'

b(k) = 0;

end

end

av = sum((b.*t))/sum(t)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote