1 任务名称
彩票仿真系统的设计与实现
2 任务目标
设计一个购买机选彩票的仿真系统,该系统至少可以提供三种彩票种类,分别为双色球、3D和31选7(可自行设计,不限于这几个)。用户选择好彩票种类,输入要购买的彩票注数并确定后,系统显示购买这些彩票所需的钱款,再次确认后,显示相应注数的彩票号码。
要求系统的界面友好、操作方便、不会造成用户的误解,同时对彩票注数有有容错功能,用户只能输入1~5注,否则就提示出错。
3 设计要求
a)界面上应有系统的名称,如“机选彩票仿真系统”,同学们不必局限于例子,可自行为系统取名并将其放置在界面上的适当位置。
b)界面上应有设计者的姓名和学号,如“2021000001 小美”,同学们不必局限于例子,可自行安排和设计。
c)界面上就有背景图案。
d)界面上提供三种彩票种类的选择,用户每次只能选择其中一种进行购买。建议使用单选按钮+按钮组合框,回调函数在组合框的selectchangfunction中编写。提示:这里可能需要一个全局变量,如a,若用户选择第一项,则a=1,以此类推。在其它回调函数中,如果需要用到是哪一个彩票种类时,即可利用全局变量a来获得。If a2怎么怎么样。。。
e)用户可查看彩票的玩法。可以有多种方法来实现该功能,例如可设计一个“彩票玩法说明”按钮+文本框的组合,假设有用户不知道“双色球”的玩法,他可以选择“双色球”,按下“彩票玩法说明”按钮,系统即可在文本框中显示“双色球”的玩法说明。也可设计成,在用户选择彩票种类的时候,系统直接在文本框进行说明,而不需要再增加一个“说明”按钮。
f)用户可输入要购买的注数,只能是1~5注。要求有容错功能。
g)显示用户购买彩票所需的金额,每注彩票2元。下面三个选项应选一个,可获得相应分数,三项分数之间不累加。
i.当用户选择好彩票种类,输入注数,并按“确定”按钮后,系统显示要购买这些彩票所需的金额。
ii.如果能用questdlg进行提示“您要花费n元,请问确定吗?”(提供确定、取消选项,默认取消选项),用户选择“确定”后系统显示金额,用户选择“取消”,则彩票注数编辑框清零。完成此功能者可获得加分。
iii.如果能提示“您要购买的彩票注数是m注,将花费n元,请问确定吗?”其余同上,可获得 更多加分。本项与前项相比,在字符串组合显示功能上难度更大。建议用num2str把数字转为字符串,并利用[ ]来连接字符串。
h)显示彩票号码。提示:可用randperm产生随机组合,请设计显示方式。若使用的是text或edit控件,请注意max,min的差值。
i.以“双色球”为例,它的玩法是从红色球的133的数字中选择6个数字,从蓝色球的115的数字中选择一个数字,共同组成一注号码。如果直接利用一个编辑框来显示这注号码(下图中是2注号码),而不区分红球和蓝球,可获得20分。提示:编辑框默认显示单行,如果想要在编辑框中显示多行,需要修改编辑框的某个属性。
ii.如果能用两个编辑框,在第一个编辑框显示红色球的6个数字,在第二个编辑框中显示蓝色球的1个数字,并以颜色进行提示,则可获得25分(如下图所示)。
iii.以3D为例,它的玩法是在000~999的自然数中选择一个数字,作为一注号码。假设随机生成的数是68,系统显示的数也是68,则没有额外加分,但如果系统能显示为068,则可获得加分。提示: 可用floor(rand(1,1)*1000)产生0~999之间的随机数。另外,在C语言中有%03d可以控制至少输出3位数字,如果位数不够前面补0。而MATLAB中有一个函数叫sprintf,大家可以研究一下它的使用方法。
i)提供“自选”(不限注数)和“机选”(顶多5注)两种方案,机选如前所示,用户输入彩票类型和注数,系统出号码;自选是由用户自己选择彩票类型和号码,同学们请自行设计自选流程。例如:用户可以先输入注数,然后再输入相应的号码;也可以用户输入一次号码,你再询问是否需要再填写一注。总之,流程你们定,但应该具有友好性和方便性,不要让用户自己猜测。
j)提供“退出系统”功能和“打印”功能。在退出系统时要求有提示。“打印”功能只要能调出“打印机属性对话框”就算成功。退出时应给出提示信息,确认用户是否真的退出。
k)因为是人机交互练习题,所以希望同学们能够多使用不同类型的控件,并且对能控件的一些属性进行设置,如控件的颜色、字体的大小等。
l)界面友好、布局合理。以老师审美为标准哈。
登录后复制
function varargout = zhangyu_2191002006(varargin)% ZHANGYU_2191002006 MATLAB code for zhangyu_2191002006.fig% ZHANGYU_2191002006, by itself, creates a new ZHANGYU_2191002006 or raises the existing% singleton*.%% H = ZHANGYU_2191002006 returns the handle to a new ZHANGYU_2191002006 or the handle to% the existing singleton*.%% ZHANGYU_2191002006('CALLBACK',hObject,eventData,handles,...) calls the local% function named CALLBACK in ZHANGYU_2191002006.M with the given input arguments.%% ZHANGYU_2191002006('Property','Value',...) creates a new ZHANGYU_2191002006 or raises the% existing singleton*. Starting from the left, property value pairs are% applied to the GUI before zhangyu_2191002006_OpeningFcn gets called. An% unrecognized property name or invalid value makes property application% stop. All inputs are passed to zhangyu_2191002006_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 zhangyu_2191002006% Last Modified by GUIDE v2.5 28-Mar-2021 13:31:06% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @zhangyu_2191002006_OpeningFcn, ... 'gui_OutputFcn', @zhangyu_2191002006_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []);if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1});endif 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 zhangyu_2191002006 is made visible.function zhangyu_2191002006_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 zhangyu_2191002006 (see VARARGIN)% Choose default command line output for zhangyu_2191002006handles.output = hObject;ha=axes('units','normalized','pos',[0 0 1 1]);uistack(ha,'down');ii=imread('background.jfif');image(ii);colormap grayset(ha,'handlevisibility','off','visible','on');% Update handles structureguidata(hObject, handles);% UIWAIT makes zhangyu_2191002006 wait for user response (see UIRESUME)% uiwait(handles.figure1);% --- Outputs from this function are returned to the command line.function varargout = zhangyu_2191002006_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 structurevarargout{1} = handles.output;% --- Executes when selected object is changed in uibuttongroup1.function uibuttongroup1_SelectionChangedFcn(hObject, eventdata, handles)% hObject handle to the selected object in uibuttongroup1% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global a ;a=1;if hObject == handles.rb1 set(handles.tishi1,'String','从33个红色球号码中选出6个号码,再从16个蓝色球号码中选出1个号码,组成乐透式投注'); set(handles.tishi2,'String','3d'); set(handles.tishi3,'String','七乐彩'); a =1;elseif hObject == handles.rb2 set(handles.tishi2,'String','以一个3位自然数为投注号码的彩票,投注者从000-999的数字中选择一个3位数进行投注'); set(handles.tishi1,'String','双色球'); set(handles.tishi3,'String','七乐彩'); a=2;elseif hObject == handles.rb3 set(handles.tishi3,'String','从01—30共30个号码中选择7个号码组合为一注投注号码。'); set(handles.tishi2,'String','3d'); set(handles.tishi1,'String','双色球'); a=3;endfunction zs_edit_Callback(hObject, eventdata, handles)% hObject handle to zs_edit (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of zs_edit as text% str2double(get(hObject,'String')) returns contents of zs_edit as a double% --- Executes during object creation, after setting all properties.function zs_edit_CreateFcn(hObject, eventdata, handles)% hObject handle to zs_edit (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');end% --- Executes on button press in pbok.function pbok_Callback(hObject, ~, handles)% hObject handle to pbok (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global a;price = 0;n = get(handles.zs_edit,'String');n= str2num(n);if(n<1||n>5) f = errordlg('您输入的值超出范围,请重新输入','输入错误');else price = n*2; str1 = sprintf('您要花费 %d元,请问确定吗?',price); answer1 = questdlg(str1,'提示','确定','取消','取消'); switch answer1 case '确定' str2 = sprintf('您要购买的彩票注数是%d注,将花费%d元',n,price); answer2= questdlg(str2,'提示','确定','取消','取消'); switch answer2 case '确定' list = {'机选','自选'}; [indx,~] = listdlg('ListString',list,'SelectionMode','single','ListSize',[160,50]); switch indx case 1 %机选产生号码 if a==1 %机选玩法 双色球 matrix_r =ones(n,6); matrix_b =ones(n,1); for i =1:n%生成n注彩票 temp_r = round(rand(1,6)*33+1); matrix_r (i,1:6)=temp_r; temp_b = round(rand(1,1)*15+1); matrix_b(i,:) = temp_b; end set(handles.left_num,'String',num2str(matrix_r),'Visible','On'); set(handles.right_num,'String',num2str(matrix_b),'Visible','On'); elseif a==2 %机选玩法 3d A = cell(n,1); for i =1:n rand_3d = round(rand(1)*999); r=sprintf('%03d',rand_3d); r = cellstr(r); A(i,1) = r; end set(handles.left_num,'String',A,'Visible','On'); set(handles.right_num,'String','','Visible','off'); elseif a ==3 %机选玩法 七乐彩 B = cell(n,1); for i =1:n rand_ql = round(rand(1,7)*10+1); r=sprintf('%02d ',rand_ql); r = cellstr(r); B(i,1) =r; end set(handles.left_num,'String',B,'Visible','On'); set(handles.right_num,'String','','Visible','off'); end1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42.43.44.45.46.47.48.49.50.51.52.53.54.55.56.57.58.59.60.61.62.63.64.65.66.67.68.69.70.71.72.73.74.75.76.77.78.79.80.81.82.83.84.85.86.87.88.89.90.91.92.93.94.95.96.97.98.99.100.101.102.103.104.105.106.107.108.109.110.111.112.113.114.115.116.117.118.119.120.121.122.123.124.125.126.127.128.129.130.131.132.133.134.135.136.137.138.139.140.141.142.143.144.145.146.147.148.149.150.151.152.153.154.155.156.157.158.159.160.161.162.163.164.165.166.167.168.169.170.171.172.173.174.175.176.177.178.179.180.181.182.183.184.185.186.187.188.189.190.191.192.
1 matlab版本
2014a
免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删