Trying to create a GPA calculator?
15 views (last 30 days)
Show older comments
I want to create a Cumulative GPA calculator using two scripts. The first script will ask for Class Name, Number, Credits, and Grade.
%Problem Statement: Gather information of a certain class
Transcript.CourseName = input('What is the Course Name?', 's' );
Transcript.CourseNumber =input('What ss the Course Number?', 's');
Transcript.CouseCredits = input('What is the Course Credits?');
Transcript.CourseGrade = input('What is your grade in that class?');
The second script will gather those informations from all the classes the user is taking, and calculate the Cumulative GPA
%Problem Statement: Calculate the cumilative GPA from the grade of the
%three courses.
%Input: i-number of classes
%Output:GPA- Culmilative GPA
Ask = input('How many classes are you taking?')
numClass = Ask
for i =1:numClass
TRANSCRIPT(i).CourseName = input('What is the Course Name?', 's' );
TRANSCRIPT(i).CourseNumber =input('What ss the Course Number?', 's');
TRANSCRIPT(i).CourseCredits = input('What is the Course Credits?');
TRANSCRIPT(i).CourseGrade = input('What is your grade in that class?');
function(GPA_Cumli) =
end
As you can see, I haven't written the function yet because I do not know how'll this look. I know I am supposed to add the CourseGrade from all my classes then divide them by i, but I am struggling with the addition part. Any help would be appreciated.
0 Comments
Accepted Answer
Rahul Goel
on 10 May 2017
Hi Seong,
You can change your function to something like this:
function GPA = calculateGPA()
%Output:GPA- Culmilative GPA
Ask = input('How many classes are you taking?')
numClass = Ask;
totalEarned = 0;
totalCredits = 0;
for i =1:numClass
TRANSCRIPT(i).CourseName = input('What is the Course Name?', 's' );
TRANSCRIPT(i).CourseNumber =input('What ss the Course Number?', 's');
TRANSCRIPT(i).CourseCredits = input('What is the Course Credits?');
TRANSCRIPT(i).CourseGrade = input('What is your grade in that class?');
totalEarned = totalEarned + (TRANSCRIPT(i).CourseCredits * TRANSCRIPT(i).CourseGrade);
totalCredits = totalCredits + TRANSCRIPT(i).CourseCredits;
end
GPA = totalEarned/totalCredits;
end
Hope this helps!
0 Comments
More Answers (1)
TARIK YAMAN
on 12 Jan 2019
Hi, Seong. You can improve and use the script.
clc;
clear;
clear all;
fid = fopen('my_transcript.txt','wt');
a = input('enter the number of course : ');
k = 0;
for i = 1:a;
k = k + 1;
fprintf('\nfor %3d. course\n',k);
b(k) = input('\nenter the credits of this course : ');
c = input('\nenter the your grade : ','s');
switch c
case 'AA'
d(k) = 4;
case 'BA'
d(k) = 3.5;
case 'BB'
d(k) = 3;
case 'CB'
d(k) = 2.5;
case 'CC'
d(k) = 2.0;
case 'DC'
d(k) = 1.5;
case 'DD'
d(k) = 1.0;
case 'FD'
d(k) = 0.5;
case 'FF'
d(k) = 0;
case 'FG'
d(k) = 0;
otherwise disp('your input is invalid, so it must be like AA , BB , DD , FG , FF');
fprintf('\nfor %3d. course\n',k);
e = input('\nenter the your grade again : ','s');
switch e
case 'AA'
d(k) = 4;
case 'BA'
d(k) = 3.5;
case 'BB'
d(k) = 3;
case 'CB'
d(k) = 2.5;
case 'CC'
d(k) = 2.0;
case 'DC'
d(k) = 1.5;
case 'DD'
d(k) = 1.0;
case 'FD'
d(k) = 0.5;
case 'FF'
d(k) = 0;
case 'FG'
d(k) = 0;
end
end
p(k) = d(k)*b(k);
gano0 = sum(p)/sum(b);
percent0(k) = 100*(b(k));
end
percent = percent0/sum(b);
table = [1:a;b;d;percent];
fprintf(fid,'course number credit grade margin of effect on general grade\n');
fprintf(fid,' %3d %10.1d %3.1f %10.4f\n',table);
fprintf(fid,'\nsum of credits : %3d general grade : %10.3f',sum(b),gano0);
fclose(fid);
clc;
open('my_transcript.txt');
1 Comment
See Also
Categories
Find more on Entering Commands in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!