要求包含如下功能:
1、可创建不少于100名学生成员;
2、每名成员的记录包括:学号、姓名、专业和5门课程的成绩;
3、能够实现添加、删除、修改学生成员;(增加非法字符警告)
4、能够实现添加、删除、修改学生成员的课程成绩;(增加非法字符警告)
5、分别计算每一门课程的平均成绩;
6、每一门课程单独排序,输出由高到低的课程、姓名、成绩信息。
7、提供图形界面实现上述功能,界面包含
(1)系统登录界面
(2)添加、删除、修改界面
(3)被选中学生信息显示界面(基本信息,课程成绩,平均成绩)
(4)被选中课程信息显示界面(排序后的课程成绩,学生基本信息)
第一次弄gui,借鉴别人的代码(手动狗头)
参考博客MATLAB GUI图形界面设计一个学生管理系统
他已经讲的很好了,所以我就不献丑了(卑微的渣渣就是我)
登录界面我就不附源码啦,毕竟一样一样的
源代码如下(功能界面)
我运行出来是没有问题的,如果出现问题就百度吧,写得有点low,别骂,骂就是you can you up
function varargout = untitled3(varargin)
% UNTITLED3 MATLAB code for untitled3.fig
% UNTITLED3, by itself, creates a new UNTITLED3 or raises the existing
% singleton*.
%
% H = UNTITLED3 returns the handle to a new UNTITLED3 or the handle to
% the existing singleton*.
%
% UNTITLED3('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in UNTITLED3.M with the given input arguments.
%
% UNTITLED3('Property','Value',...) creates a new UNTITLED3 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before untitled3_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to untitled3_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help untitled3
% Last Modified by GUIDE v2.5 19-Jun-2021 20:28:48
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @untitled3_OpeningFcn, ...
'gui_OutputFcn', @untitled3_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
% End initialization code - DO NOT EDIT
% --- Executes just before untitled3 is made visible.
function untitled3_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to untitled3 (see VARARGIN)
% Choose default command line output for untitled3
handles.output = hObject;
% Update handles structure
global Read_num Read_txt Read_all Hang Lie olddata newdata
%读取学生信息
[Read_num,Read_txt,Read_all]=xlsread('学生信息.xlsx');
set(handles.uitable1,'Data',Read_all);
olddata=get(handles.uitable1,'Data');
guidata(hObject, handles);
% --- Outputs from this function are returned to the command line.
function varargout = untitled3_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
%***********查找学生*************
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to chaz (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global olddata newdata
prompt={'请输入学号:'};
answer = inputdlg(prompt,'查找',[1 50]);
a=str2double(answer);
data=get(handles.uitable1,'data');
[j]=find(a==cell2mat(data(:,1)));
%查找行数
if j
%输出信息
[IconData,IconCMap]=imread('yes.jpg');
newdata=[olddata(j,4),olddata(j,5),olddata(j,6),olddata(j,7),olddata(j,8)];
mk=mean(cell2mat(newdata( : ,4)));
h=msgbox(['学号 :',num2str(cell2mat(data(j,1))),' 姓名: ',cell2mat(data(j,2)),' 班级: ',num2str(cell2mat(data(j,3))),' 高等数学: ',num2str(cell2mat(data(j,4))),' 大学英语: ',num2str(cell2mat(data(j,5))),' 线性代数: ',num2str(cell2mat(data(j,6))),' 概率论: ',num2str(cell2mat(data(j,7))),' 大学物理: ',num2str(cell2mat(data(j,8))),' 平均成绩: ',num2str(mk)]);
waitfor(h);
else
[IconData,IconCMap]=imread('出错.jpg');
h=msgbox('输入学号没有查找到!请检查输入是否错误!','错误','warn',IconData,IconCMap);
waitfor(h);
end
% --- Executes on button press in pushbutton2.
%***********添加学生*************
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to tianjia (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global olddata newdata
prompt={ '输入学号' , '输入姓名' ,'输入专业' , '高等数学' , '大学英语' '线性代数' , '概率论', '大学物理' };
answer=inputdlg(prompt,'增添新的学生信息',[1 50;1 50;1 50;1 50;1 50;1 50;1 50;1 50]);
data={str2double(answer{1,1}) answer{2,1} answer{3,1} str2double(answer{4,1}) str2double(answer{5,1}) str2double(answer{6,1}) str2double(answer{7,1}) str2double(answer{8,1})};
olddata=get(handles.uitable1,'data');
newdata = [ olddata ; data];
set(handles.uitable1,'data',newdata);
guidata(hObject,handles);
%***********删除学生*************
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to shanchu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global olddata newdata
prompt={'请输入学号:'};
answer = inputdlg(prompt,'删除',[1 50]);
a=str2double(answer);
olddata=get(handles.uitable1,'data');
newdata=olddata;
[j]=find(a==cell2mat(newdata(:,1)));
%查找行数
if j
newdata(j,:)=[];
set(handles.uitable1,'data',newdata);
else
[IconData,IconCMap]=imread('出错.jpg');
h=msgbox('输入学号没有查找到!请检查输入是否错误!','错误','warn',IconData,IconCMap);
waitfor(h);
end
%***********修改学生*************
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global olddata newdata
prompt={ '输入修改学生学号' , '输入姓名' ,'输入专业' , '高等数学' , '大学英语' '线性代数' , '概率论', '大学物理' };
answer=inputdlg(prompt,'修改学生信息',[1 50;1 50;1 50;1 50;1 50;1 50;1 50;1 50]);
a=str2double(answer{1,1});
b=answer{2,1};
c=answer{3,1};
d=str2double(answer{4,1});
e=str2double(answer{5,1});
f=str2double(answer{6,1});
h=str2double(answer{7,1});
m=str2double(answer{8,1});
olddata=get(handles.uitable1,'data');
newdata=olddata;
[j]=find(a==cell2mat(newdata(:,1)));
if j
newdata(j,2)={b};
newdata(j,3)={c};
newdata(j,4)={d};
newdata(j,5)={e};
newdata(j,6)={f};
newdata(j,7)={h};
newdata(j,8)={m};
set(handles.uitable1,'data',newdata);
else
[IconData,IconCMap]=imread('出错.jpg');
h=msgbox('输入学号没有查找到!请检查输入是否错误!','错误','warn',IconData,IconCMap);
waitfor(h);
end
%**************返回上一步************
% --- Executes on button press in daoruchengji.
function daoruchengji_Callback(hObject, eventdata, handles)
% hObject handle to daoruchengji (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global olddata newdata
guidata(hObject,handles) ;
set(handles.uitable1,'Data',olddata);
%*************平均成绩***********************
% --- Executes on button press in pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles)
% hObject handle to pj (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global olddata newdata
olddata=get(handles.uitable1,'data');
mk1=mean(cell2mat(olddata( : ,4)));
mk2=mean(cell2mat(olddata( : ,5)));
mk3=mean(cell2mat(olddata( : ,6)));
mk4=mean(cell2mat(olddata( : ,7)));
mk5=mean(cell2mat(olddata( : ,8)));
h=msgbox([' 高等数学: ',num2str(mk1),' 大学英语: ',num2str(mk2),' 线性代数: ',num2str(mk3),' 概率论: ',num2str(mk4),' 大学物理: ',num2str(mk5)]);
waitfor(h);
%*****************************排序**************************
% --- Executes on button press in pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton10 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global olddata newdata
prompt={ '输入依据排序的课程序号:高数(1) 英语(2) 线性代数(3) 概率论(4) 大学物理(5)' };
answer=inputdlg(prompt,'删除成绩',[1 50]);
n=str2double(answer{1,1});
olddata=get(handles.uitable1,'data');
newdata=[olddata(:,1),olddata(:,2),olddata(:,3),olddata(:,4),olddata(:,5),olddata(:,6),olddata(:,7),olddata(:,8)];
newdata=sortrows(newdata,n+3,'descend');
%newdata=[cell2mat(olddata(:,1)),cell2mat(olddata(:,4)),cell2mat(olddata(:,5)),cell2mat(olddata(:,6)),cell2mat(olddata(:,7)),cell2mat(olddata(:,8))];
set(handles.uitable1,'Data',newdata);
%*********************背景*******************
% --- Executes during object creation, after setting all properties.
function figure1_CreateFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
ha=axes('units','normalized','pos',[0 0 1 1]);
uistack(ha,'down');
ii=imread('back2.jpg');
image(ii);
colormap gray
set(ha,'handlevisibility','off','visible','on');
%***************************删除学生成绩**************
% --- Executes on button press in pushbutton11.
function pushbutton11_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton11 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
prompt={ '输入学号' , '输入要删除的课程序号:高数(1) 英语(2) 线性代数(3) 概率论(4) 大学物理(5)' };
answer=inputdlg(prompt,'删除成绩',[1 50;1 50]);
a=str2double(answer{1,1});
b=str2double(answer{2,1})+3;
newdata=get(handles.uitable1,'data');
[j]=find(a==cell2mat(newdata(:,1)));
if j
newdata(j,b)={[]};
set(handles.uitable1,'data',newdata);
else
[IconData,IconCMap]=imread('出错.jpg');
h=msgbox('输入学号没有查找到!','错误','warn',IconData,IconCMap);
waitfor(h);
end
% --- Executes on button press in pushbutton13.
function pushbutton13_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton13 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
prompt={ '输入学号' , '输入要删除的课程序号:高数(1) 英语(2) 线性代数(3) 概率论(4) 大学物理(5)','该科目分数' };
answer=inputdlg(prompt,'修改成绩',[1 50;1 50;1 50]);
a=str2double(answer{1,1});
b=str2double(answer{2,1})+3;
c=str2double(answer{3,1});
newdata=get(handles.uitable1,'data');
[j]=find(a==cell2mat(newdata(:,1)));
if j
newdata(j,b)={c};
set(handles.uitable1,'data',newdata);
else
[IconData,IconCMap]=imread('出错.jpg');
h=msgbox('输入学号没有查找到!','错误','warn',IconData,IconCMap);
waitfor(h);
end
% --- Executes on button press in pushbutton14.
function pushbutton14_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton14 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton15.
function pushbutton15_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton15 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
版权声明:本文为magical_pencil原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。