Using MATLAB. Create an algorithm to allow the user to enter a list of courses t
ID: 3740369 • Letter: U
Question
Using MATLAB. Create an algorithm to allow the user to enter a list of courses they have taken along with the grades received and the credit hours for each course, and then calculate the user’s GPA. The program should first ask the user to type either Yes or No in response to the question, “Do you want to enter a grade?” If the answer is Yes, the user should be asked to enter the name of the course (text), the grade in the course (A, B, C, D, or F), and the number of credit hours for the course (a positive integer). If the user enters an invalid grade or an invalid number for the credit hours, he or she should be warned and asked to try again a maximum of three times, after which an appropriate error message should be generated and the program terminated. If they successfully enter the information for a course, the course name, the letter grade, and the credit hours should be displayed in a single row on the screen in an appropriate format, and then they should be asked again if they wish to enter a grade, and the entire process repeats if they answer Yes. If they answer No, the GPA should be calculated and displayed in an appropriate format, and then the program terminated unless no grades were entered (they typed No the first time) in which case an appropriate message should be generated and the program terminated.
Explanation / Answer
function varargout = mygpa(varargin) gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @mygpa_OpeningFcn, ... 'gui_OutputFcn', @mygpa_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end function mygpa_OpeningFcn(hObject, eventdata, handles, varargin) handles.output = hObject; guidata(hObject, handles); function varargout = mygpa_OutputFcn(hObject, eventdata, handles) varargout{1} = handles.output; function c1_Callback(hObject, eventdata, handles) function c1_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function g1_Callback(hObject, eventdata, handles) function g1_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function g2_Callback(hObject, eventdata, handles) function g2_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function c2_Callback(hObject, eventdata, handles) function c2_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function g3_Callback(hObject, eventdata, handles) function g3_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function c3_Callback(hObject, eventdata, handles) function c3_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function g4_Callback(hObject, eventdata, handles) function g4_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function c4_Callback(hObject, eventdata, handles) function c4_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function c6_Callback(hObject, eventdata, handles) function c6_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function g6_Callback(hObject, eventdata, handles) function g6_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function g5_Callback(hObject, eventdata, handles) function g5_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function c5_Callback(hObject, eventdata, handles) function c5_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function c7_Callback(hObject, eventdata, handles) function c7_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function g7_Callback(hObject, eventdata, handles) function g7_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function g8_Callback(hObject, eventdata, handles) function g8_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function c8_Callback(hObject, eventdata, handles) function c8_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function pushbutton1_Callback(hObject, eventdata, handles) C=[0 4 3 2 1]; G=[0 4.00 3.75 3.50 3.00 2.50 2.00 1.50 1.00 0.00]; cc(1)=C(get(handles.c1,'Value')); gg(1)=G(get(handles.g1,'Value')); cc(2)=C(get(handles.c2,'Value')); gg(2)=G(get(handles.g2,'Value')); cc(3)=C(get(handles.c3,'Value')); gg(3)=G(get(handles.g3,'Value')); cc(4)=C(get(handles.c4,'Value')); gg(4)=G(get(handles.g4,'Value')); cc(5)=C(get(handles.c5,'Value')); gg(5)=G(get(handles.g5,'Value')); cc(6)=C(get(handles.c6,'Value')); gg(6)=G(get(handles.g6,'Value')); cc(7)=C(get(handles.c7,'Value')); gg(7)=G(get(handles.g7,'Value')); cc(8)=C(get(handles.c8,'Value')); gg(8)=G(get(handles.g8,'Value')); GPA=sum(cc.*gg)/sum(cc); set(handles.GPA,'String',GPA) global ABCXYZ ; ABCXYZ=(sum(cc)); XX(GPA); function cgpa0_Callback(hObject, eventdata, handles) function cgpa0_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function ch0_Callback(hObject, eventdata, handles) function ch0_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function pushbutton2_Callback(hObject, eventdata, handles) cgpa_previous=(get(handles.cgpa0 ,'String')); ch_previous=(get(handles.ch0 ,'String')); gpa_current=(get(handles.GPA ,'String')); cgpa_previous=str2num(cgpa_previous); ch_previous=str2num(ch_previous); gpa_current=str2num(gpa_current); global ABCXYZ; ccgpa=(gpa_current.*ABCXYZ+cgpa_previous.*ch_previous)./(ABCXYZ+ch_previous); set(handles.CCGPA,'String',ccgpa); XX(ccgpa); function XX(t) if t==4 msgbox('Parable Performance!','CGPA','replace');return; end if t>=3.5 msgbox('Excellent Performance!','CGPA','replace');return; end if t>=3 msgbox('Fair!','CGPA','replace');return; end if t>=2 msgbox('You Need To work evenmore!','CGPA','replace');return; end if tRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.