In: Computer Science
Write a Matlab code to
Gpa=sum(mark in subject i * subiect credit i) /total
number of credit,
i=1:12
MATLAB:
clc;close all;clear all;
A = randi([10,100],250,12);
B = randi([2,6],1,12);
i=input('Enter student id:?');
j=input('Enter course number:?');
%TO define grades
if A(i,j)>= 91 && A(i,j)>=100
grade='A';
elseif A(i,j) >= 81 && A(i,j)>=90
grade='B';
elseif A(i,j) >= 71 && A(i,j)>=80
grade='C';
elseif A(i,j) >= 61 && A(i,j)>=70
grade='D';
elseif A(i,j) <61
grade='F';
end
fprintf('The grade of the student in the subject is
%c\n',grade);
%To calculate GPA of the semester
for j=1:1:12
Gpa=Gpa+(A(i,j) * B(j) );
endfor
Gpa=Gpa/(10*sum(B));
fprintf('The GPA of the student in this semester is
%3.2f\n',Gpa);
Command window:
Enter student id:?100
Enter course number:?10
The grade of the student in the subject is F
The GPA of the student in this semester is 5.14
Enter student id:?200
Enter course number:?12
The grade of the student in the subject is F
The GPA of the student in this semester is 6.84
Enter student id:?150
Enter course number:?11
The grade of the student in the subject is F
The GPA of the student in this semester is 4.97