|
這是我之前課程設(shè)計(jì)寫的一段代碼,老師讓自主設(shè)計(jì)我就寫了一個(gè)有關(guān)于匯率轉(zhuǎn)換的,包括很多國家的貨幣之間的匯率轉(zhuǎn)換,還可以用于計(jì)算銀行的存儲(chǔ)的日利息,月利息和年利息。
0.png (6.8 KB, 下載次數(shù): 39)
下載附件
2018-1-14 16:32 上傳
MATLAB源程序如下:
- function varargout = Interest_rate1(varargin)
- % INTEREST_RATE1 MATLAB code for Interest_rate1.fig
- % INTEREST_RATE1, by itself, creates a new INTEREST_RATE1 or raises the existing
- % singleton*.
- %
- % H = INTEREST_RATE1 returns the handle to a new INTEREST_RATE1 or the handle to
- % the existing singleton*.
- %
- % INTEREST_RATE1('CALLBACK',hObject,eventData,handles,...) calls the local
- % function named CALLBACK in INTEREST_RATE1.M with the given input arguments.
- %
- % INTEREST_RATE1('Property','Value',...) creates a new INTEREST_RATE1 or raises the
- % existing singleton*. Starting from the left, property value pairs are
- % applied to the GUI before Interest_rate1_OpeningFcn gets called. An
- % unrecognized property name or invalid value makes property application
- % stop. All inputs are passed to Interest_rate1_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 Interest_rate1
- % Last Modified by GUIDE v2.5 28-Aug-2016 18:27:40
- % Begin initialization code - DO NOT EDIT
- gui_Singleton = 1;
- gui_State = struct('gui_Name', mfilename, ...
- 'gui_Singleton', gui_Singleton, ...
- 'gui_OpeningFcn', @Interest_rate1_OpeningFcn, ...
- 'gui_OutputFcn', @Interest_rate1_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 Interest_rate1 is made visible.
- function Interest_rate1_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 Interest_rate1 (see VARARGIN)
- % Choose default command line output for Interest_rate1
- handles.output = hObject;
- % Update handles structure
- guidata(hObject, handles);
- % UIWAIT makes Interest_rate1 wait for user response (see UIRESUME)
- % uiwait(handles.figure1);
- % --- Outputs from this function are returned to the command line.
- function varargout = Interest_rate1_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;
- % --- Executes on button press in radiobutton1.
- function radiobutton1_Callback(hObject, eventdata, handles)
- % hObject handle to radiobutton1 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- % Hint: get(hObject,'Value') returns toggle state of radiobutton1
- global type
- type=1;
- % --- Executes on button press in radiobutton2.
- function radiobutton2_Callback(hObject, eventdata, handles)
- % hObject handle to radiobutton2 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- % Hint: get(hObject,'Value') returns toggle state of radiobutton2
- global type
- type=2;
- % --- Executes on button press in pushbutton1.
- function pushbutton1_Callback(hObject, eventdata, handles)
- % 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 money t
- t=1;
- f1=fopen('money.txt'); %By reading the text file to input the principal
- money=fscanf(f1,'%d');
- fclose(f1); %close the file
- set(handles.text3,'string',num2str(money)); %Display the value in the static text box
- axes(handles.axes1);
- title('存款本金');
- stem(t,money);
- % --- Executes on button press in pushbutton2.
- function pushbutton2_Callback(hObject, eventdata, handles)
- % hObject handle to pushbutton2 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- global Time Amount Type Name
- fid=fopen('Bill.txt'); %By reading the text file to input the bill
- fscanf(fid, '%s %s',2);
- Name=fscanf(fid, '%s',1); %obtain the user's name
- fgetl(fid);
- fgetl(fid);
- Time=[];
- Amount=[];
- Type=[];
- while ~feof(fid);
- Time=[Time,fscanf(fid, '%d ',1)]; %obtain the time of deposit or withdrawals
- Amount=[Amount,fscanf(fid, '%f ',1)]; %obtain the amount of deposit or withdrawals
- Type=[Type,fscanf(fid, '%c ',1)]; %obtain the type of deposit or withdrawals
- end
- Name
- Time
- Amount
- Type
- % --- Executes on selection change in popupmenu1.
- function popupmenu1_Callback(hObject, eventdata, handles)
- % hObject handle to popupmenu1 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- global e
- n=get(handles.popupmenu1,'Value');
- e=n;
- % Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array
- % contents{get(hObject,'Value')} returns selected item from popupmenu1
- % --- Executes during object creation, after setting all properties.
- function popupmenu1_CreateFcn(hObject, eventdata, handles)
- % hObject handle to popupmenu1 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles empty - handles not created until after all CreateFcns called
- % Hint: popupmenu 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 pushbutton3.
- function pushbutton3_Callback(hObject, eventdata, handles)
- % hObject handle to pushbutton3 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- global e money Rate Loan_rate
- fid=fopen('Data.txt'); %By reading the text file to obtain the rate of deposit and loan ,exchange rate
- fgetl(fid); % returns the next line of the specified file, removing the newline characters.
- Exchange=[]; %exchange rate
- Rate=[]; %the rate of deposit
- Loan_rate=[]; %the rate of loan
- while ~feof(fid);
- Rate=[Rate,fscanf(fid, '%f ',1)];
- Exchange=[Exchange,fscanf(fid, '%f ',1)];
- Loan_rate=[Loan_rate,fscanf(fid, '%f ',1)];
- end
- Exchange_rate=Exchange(e);
- amount0=money*Exchange_rate;
- set(handles.text4,'string',num2str(amount0)); %Display the converted amount in the static text box
- set(handles.text6,'string',num2str(Exchange_rate)); %Display the exchange rate
- axes(handles.axes1);
- title('外匯匯率');
- x=1:1:6;
- stem(x,Exchange);
- % --- Executes on selection change in popupmenu2.
- function popupmenu2_Callback(hObject, eventdata, handles)
- % hObject handle to popupmenu2 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- % Hints: contents = cellstr(get(hObject,'String')) returns popupmenu2 contents as cell array
- % contents{get(hObject,'Value')} returns selected item from popupmenu2
- global t_deposit
- m=get(handles.popupmenu2,'Value'); %Choose the currency
- t_deposit=m;
- % --- Executes during object creation, after setting all properties.
- function popupmenu2_CreateFcn(hObject, eventdata, handles)
- % hObject handle to popupmenu2 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles empty - handles not created until after all CreateFcns called
- % Hint: popupmenu 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 pushbutton4.
- function pushbutton4_Callback(hObject, eventdata, handles)
- % hObject handle to pushbutton4 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- global Rate type t_deposit money amount1 t_loan Loan_rate
- switch type
- case 1
- switch t_loan
- case 1 %loan for one year
- amount1=(Loan_rate(1)+1)*money;
- set(handles.text11,'string',num2str(Loan_rate(t_loan)));
- set(handles.text9,'string',num2str(amount1));
- case {2,3,4,5} %loan for 2~5 years
- amount1=(Loan_rate(t_loan)+1)^t_loan*money;
- set(handles.text11,'string',num2str(Loan_rate(t_loan)));
- set(handles.text9,'string',num2str(amount1));
- case {6,7,8,9,10} %loan 6~10 years
- amount1=(Loan_rate(6)+1)^t_loan*money;
- set(handles.text11,'string',num2str(Loan_rate(6)));
- set(handles.text9,'string',num2str(amount1));
- end
- case 2
- switch t_deposit
- case 1
- amount1=(Rate(t_deposit+1)/4.0+1)*money;%Time deposit for three months
- case 2
- amount1=(Rate(t_deposit+1)/2+1)*money; %Time deposit for six months
- case 3
- amount1=(Rate(t_deposit+1)+1)*money; %Time deposit for one year
- case 4
- amount1=(Rate(t_deposit+1)+1)*(Rate(4)+1)*money; %Time deposit for two years
- case 5
- amount1=(Rate(t_deposit+1)+1)*(Rate(5)+1)*(Rate(5)+1)*money; %Time deposit for three years
- end
- set(handles.text9,'string',num2str(amount1));%diaplay the principal and interest
- set(handles.text11,'string',num2str(Rate(t_deposit+1)));%display the rate
- end
- axes(handles.axes2); %draw the matchstick picture of the diffrent
- ……………………
- …………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
實(shí)驗(yàn)1(Interest Rate).zip
(43.95 KB, 下載次數(shù): 18)
2018-1-14 11:15 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
|