Tải bản đầy đủ (.doc) (31 trang)

Bài Tập lớn môn Matlab pdf

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (605.38 KB, 31 trang )

Bài tập lớn môn
matlab
GVHD: Đỗ Thị Mơ
NỘI DUNG BÁO CÁO
• Đề bài
• Mục Tiêu
• Chương trình demo
• Nhận xét và cho điểm
I.Đề 11
Câu 1 :
Nhập vào danh sách thuế xe ô tô, mỗi người bao gồm các thông tin sau : mã ,đơn
vị, loại xe, số ngày thuê, số xe . Trong đó đơn vị dạng kí tự. Hãy lập trình thực hiện
các mục sau :
1. Tính tiền thuê cho từng người :
Tiền thuê được tính như sau: 1 ngày đầu mỗi ngày là 500000 cho 1 xe, 3
ngày tiếp theo mỗi ngày là 400000 cho 1 xe, 4 tiếp theo mỗi ngày là 300000
cho 1 xe, các ngày tiếp theo mỗi ngày là 200000 cho 1 xe.
2. Sắp xếp theo số xe giảm dần.
3. Tìm thông tin của người khi nhập vào mã.
4. Tính tổng tiền thuê của từng đơn vị, tổng tiền thuê của cả danh sách.
5. Xóa đi một người khi nhập vào mã
6. Thêm vào một người ở vị trí i bất kì.
7. Sửa chữa thông tin của một người khi nhập vào mã.
8. Vẽ đồ thị biểu diễn tương quan giữa tiền thuê và số ngày thuê.
9. Vẽ đồ thị dạng cột để so sánh tiền thuê và số xe.
10.Vẽ đồ thị dạng Pie cho cột tổng tiền thuê của từng đơn vị.
Câu 2 :
Vẽ trên một đồ thị cho hàm số y=3x
4
+ 2x
3


-2x+1, x trong [-4,i] các điểm cách nhau
là 0.2, với i từ 7 đến 17 khoảng cách là 1.7
Câu 3 :
Vẽ trên một đồ thị các dạng mesh,waterfall,surfc cho hàm số y= 4cos
2
x+ 2cosx, với
x:[-2.5, 8.5] với đáy hình chữ nhật và đáy hình tròn.
Câu 4:
Cho hàm số f(x) = 2tg
3
x + 2sin
2
x + 3tg x cos x+1
Tính f’(x), f”’(x), f
(5)
(x) và hiển thị ở dạng quen thuộc
Tính tích phân bất định của f
Tính giới hạn khi x → 0.6
II.MỤC TIÊU

- Làm quen với lập trình Matlab cơ bản
- Nắm rõ,hiểu rõ các hàm toán học trong Matlab
- Biết cách lập trình giao diện bằngMatlab
- Làm quen với phần mềm Matlab và sử dụng.
III. CHƯƠNG TRÌNH DEMO
1, Giao diện chính
Giao diện chính là phần giới thiệu về các thành viên group 11 và các menu bài
tập.
Code



% Giao dien chuong trinh
h=figure('name','KIEM TRA MATLAB',
'color',[0.1 0.7 0.8],
'numbertitle','on',
'units','normalized',
'position',[0.1 0.1 0.85 0.85]);
% Tao tieu de
t=uicontrol(h,
'style','text',
'units','normalized',
'foregroundcolor','b',
'backgroundcolor',[0.1 0.7 0.8],
'string','DAI HOC CHU VAN AN',
'FontSize',21,
'position',[0.05 0.91 0.9 0.07]);
% Tao tieu de
t1=uicontrol(h,
'style','text',
'units','normalized',
'foregroundcolor','b',
'backgroundcolor',[0.1 0.7 0.8],
'string','KHOA CONG NGHE THONG TIN',
'FontSize',20,
'position',[0.05 0.87 0.9 0.07]);
% Tao tieu de
tieude=uicontrol(h,
'style','text',
'units','normalized',
'foregroundcolor','b',

'backgroundcolor',[0.1 0.7 0.8],
'string','BAI TAP LON MATLAB ',
'FontSize',30,
'position',[0.05 0.7 0.9 0.07]);

% Tao tieu de
N=uicontrol(h,
'style','text',
'units','normalized',
'foregroundcolor','b',
'backgroundcolor',[0.1 0.7 0.8],
'string','<De 11> ',
'FontSize',24,
'position',[0.05 0.64 0.9 0.07]);

% Tao tieu de
N1=uicontrol(h,
'style','text',
'units','normalized',
'foregroundcolor','b',
'backgroundcolor',[0.1 0.7 0.8],
'string','Nhom 11: Nguyen Van Thanh<Team Leader> ',
'FontSize',20,
'position',[0.0002 0.5 0.54 0.07]);
% Tao tieu de
q1=uicontrol(h,
'style','text',
'units','normalized',
'foregroundcolor','b',
'backgroundcolor',[0.1 0.7 0.8],

'string',' Nguyen Xuan Truong ',
'FontSize',20,
'position',[0.0002 0.46 0.67 0.07]);
% Tao tieu de
N2=uicontrol(h,
'style','text',
'units','normalized',
'foregroundcolor','b',
'backgroundcolor',[0.1 0.7 0.8],
'string',' Nguyen Chi Nhien ',
'FontSize',20,
'position',[0.0002 0.42 0.64 0.07]);
% Tao tieu de
N3=uicontrol(h,
'style','text',
'units','normalized',
'foregroundcolor','b',
'backgroundcolor',[0.1 0.7 0.8],
'string',' Nguyen Van Viet ',
'FontSize',20,
'position',[0.0002 0.38 0.62 0.07]);
% Tao tieu de
N4=uicontrol(h,
'style','text',
'units','normalized',
'BackgroundColor',[0.2 0.2 0.9],
'foregroundcolor',[0.2 1 0.8],
'string',' MENU ',
'FontSize',27,
'position',[0.009 0.28 0.98 0.07]);







uicontrol('style','push','Units','Normalized',
'BackgroundColor',[0.5 0.2 0.9],
'foregroundcolor',[0.1 1 0.8],
'position',[0.05 0.15 0.1 0.1],'string','Bai1','callback','bai1MatlabDe11new');
uicontrol('style','push','Units','Normalized',
'BackgroundColor',[0.5 0.2 0.9],
'foregroundcolor',[0.1 1 0.8],
'position',[0.3 0.15 0.1 0.1],'string','Bai2','callback','cau2');
uicontrol('style','push','Units','Normalized',
'BackgroundColor',[0.5 0.2 0.9],
'foregroundcolor',[0.1 1 0.8],
'position',[0.55 0.15 0.1 0.1],'string','Bai3','callback','cau3');

uicontrol('style','push','Units','Normalized',
'BackgroundColor',[0.5 0.2 0.9],
'foregroundcolor',[0.1 1 0.8],
'position',[0.80 0.15 0.1 0.1],'string','Bai4','callback','cau4');

% Tao nut dong CT
Dong=uicontrol(h,
'style','pushbutton',
'units','normalized',
'BackgroundColor',[0.5 0.2 0.9],
'foregroundcolor',[0.1 1 0.8],

'string','Thoat',
'foregroundcolor','b',
'callback','close');

Hình 1 : Giao diện chính
2,Câu 1
Yêu cầu:
Nhập vào danh sách thuế xe ô tô, mỗi người bao gồm các thông tin sau : mã ,đơn
vị, loại xe, số ngày thuê, số xe . Trong đó đơn vị dạng kí tự. Hãy lập trình thực hiện
các mục sau :
11.Tính tiền thuê cho từng người :
Tiền thuê được tính như sau: 1 ngày đầu mỗi ngày là 500000 cho 1 xe, 3
ngày tiếp theo mỗi ngày là 400000 cho 1 xe, 4 tiếp theo mỗi ngày là 300000
cho 1 xe, các ngày tiếp theo mỗi ngày là 200000 cho 1 xe.
12.Sắp xếp theo số xe giảm dần.
13.Tìm thông tin của người khi nhập vào mã.
14.Tính tổng tiền thuê của từng đơn vị, tổng tiền thuê của cả danh sách.
15.Xóa đi một người khi nhập vào mã
16.Thêm vào một người ở vị trí i bất kì.
17.Sửa chữa thông tin của một người khi nhập vào mã.
18.Vẽ đồ thị biểu diễn tương quan giữa tiền thuê và số ngày thuê.
19.Vẽ đồ thị dạng cột để so sánh tiền thuê và số xe.
20.Vẽ đồ thị dạng Pie cho cột tổng tiền thuê của từng đơn vị.
Code:
function bai1()
global arrdonvi;
fprintf('===============DE SO 11=================\n')
fprintf('==============Hay chon cac chuc nang============\n')
%LABEL nhan1


fprintf('\t1.Nhap Du Lieu va tinh tien thue cho tung nguoi.\n')
fprintf('\t2.Sap xep theo so xe giam dan.\n')
fprintf('\t3.Tim thong tin tung nguoi khi nhap vao ma.\n')
fprintf('\t4.Tinh tong tien thue cua tung don vi va ca danh sach.\n')
fprintf('\t5.Xoa nguoi khi nhap va ma.\n')
fprintf('\t6.Them nguoi o vi tri bat ky.\n')
fprintf('\t7.Sua thong tin nguoi khi nhap ma.\n')
fprintf('\t8.Do thi tuong quan tien thue so ngay thue.\n')
fprintf('\t9.Do thi danh cot so sanh tien thue so ngay thue.\n')
fprintf('\t10.Do thi dang pie cho cot tong tien thue.\n')
fprintf('\t11.Ve Menu\n')
fprintf('\t12.Thoat.\n\n')
fprintf('\tBan chon: ')
chon=input('');
while(chon~=12)
switch(chon)
case 0
fprintf('\tBan chon(12:thoat): ')
chon=input('');
case 1
n=input('Nhap vao so nguoi: ');
while(n<=0)
n=input('So nguoi ban nhap khong dung, yeu cau nhap lai: ');
end

Nguoi = struct('Ma',{},'Donvi',{},'Loaixe',{},'Songaythue',{},'Soxe',
{},'Tienthue',{});
%Nguoitam = struct('Ma',{},'Donvi',{},'Loaixe',{},'Songaythue',{},'Soxe',
{},'Tienthue',{});
disp('====NHAP THONG TIN CHO TUNG NGUOI====')

for i=1:n
%Nguoi = struct('Ma',{},'Donvi',{},'Loaixe',{},'Songaythue',{},'Soxe',
{},'Tienthue',{});
fprintf('Nhap thong tin cho nguoi thu %d',i)

fprintf('\n\tNhap ma: ')
Nguoi(i).Ma = input('');

while(isempty(Nguoi(i).Ma)==1)
fprintf('\n\tNhap lai ma: ')
Nguoi(i).Ma = input('');
end
if(i>=2)
for a=1:i-1
if(Nguoi(i-a).Ma==Nguoi(i).Ma)
fprintf('\n\t Ma vua nhap bi trung')
fprintf('\n\t Nhap lai ma: ')
Nguoi(i).Ma = input('');

end
% if(Nguoi(i-a).Ma==Nguoi(i).Ma)
% fprintf('\n\t Ma vua nhap bi trung')
% fprintf('\n\t Nhap lai ma: ')
% Nguoi(i).Ma = input('');

% end
end
end
% end cua while



fprintf('\tNhap vao don vi: ')
Nguoi(i).Donvi=input('','s');
% soat loi
while(isempty(Nguoi(i).Donvi)==1)
fprintf('\tNhap lai don vi: ')
Nguoi(i).Donvi=input('','s');
end
%
arrdonvi(i)=Nguoi(i).Donvi;
fprintf('\tNhap Loai xe: ')
Nguoi(i).Loaixe=input('');
%Soat loi
while((isempty(Nguoi(i).Loaixe)==1))
fprintf('\tNhap lai Loai xe: ')
Nguoi(i).Loaixe=input('');
end
%++++++++++++++++++++++++++++++++
fprintf('\tNhap so ngay thue: ')
Nguoi(i).Songaythue=input('');
%+++++++++++++++++++++++++
while(isempty(Nguoi(i).Songaythue)==1)
fprintf('\tNhap lai so ngay thue: ')
Nguoi(i).Songaythue=input('');
end
%+++++++++++++++++++++++++++++++
fprintf('\tNhap so xe: ')
Nguoi(i).Soxe=input('');
%+++++++++++++++++++++++++++++++++++
while(isempty(Nguoi(i).Soxe)==1)

fprintf('\tNhap lai so xe: ')
Nguoi(i).Soxe=input('');
end
%+++++++++++++++++++++++++++++++++

if(Nguoi(i).Songaythue==1)
Nguoi(i).Tienthue=500000;
else if(Nguoi(i).Songaythue<=4)
Nguoi(i).Tienthue=500000+(Nguoi(i).Songaythue-1)*400000;
else if(Nguoi(i).Songaythue<=8)
Nguoi(i).Tienthue=500000 + 3*400000 +(Nguoi(i).Songaythue-
4)*300000;
else
Nguoi(i).Tienthue= 500000 + 3*400000 +4*300000+
(Nguoi(i).Songaythue-8)*200000;
end
end
end
end
%Cau 2
fprintf('CAU A IN RA DANH SACH ROI TINH LUON TIEN THUE\n')
fprintf('Ma DonVi LoaiXe SoNgayThue SoXe TienThue\n')
n=length(Nguoi);
for i=1:n
fprintf('%d %s %d %d %d %d\n', Nguoi(i).Ma,
Nguoi(i).Donvi, Nguoi(i).Loaixe, Nguoi(i).Songaythue,
Nguoi(i).Soxe,Nguoi(i).Tienthue)
end

fprintf('\tBan chon tiep(12:thoat): ')

chon=input('');

%Cau 3 - Sap xep danh sach theo so xe giam dan

case 2
mang1=size(arrdonvi);
if(mang1<1)
fprintf('\tBan hay chon 1 truoc! \n')
return
end
fprintf('SAP XEP THEO SO XE GIAM DAN\n')
max=0;
n1=length(Nguoi);%Lay ve kich thuoc de tranh sai sot
for i=1:n1
max=i;
for j=i+1:n1
if(Nguoi(j).Soxe>Nguoi(max).Soxe)
max=j;
end
tam = Nguoi(i).Soxe;
Nguoi(i).Soxe=Nguoi(max).Soxe;
Nguoi(max).Soxe=tam;
%Sap xep lai don vi
tam3 = Nguoi(i).Donvi;
Nguoi(i).Donvi=Nguoi(max).Donvi;
Nguoi(max).Donvi=tam3;
%Sap xep lai loai xe
tam4 = Nguoi(i).Loaixe;
Nguoi(i).Loaixe=Nguoi(max).Loaixe;
Nguoi(max).Loaixe=tam4;

%Sap xep lai ma
tam2 = Nguoi(i).Ma;
Nguoi(i).Ma=Nguoi(max).Ma;
Nguoi(max).Ma=tam2;
%Sap xep lai so ngay thue
tam5 = Nguoi(i).Songaythue;
Nguoi(i).Songaythue=Nguoi(max).Songaythue;
Nguoi(max).Songaythue=tam5;
%Sap xep lai tien thue
tam6 = Nguoi(i).Tienthue;
Nguoi(i).Tienthue=Nguoi(max).Tienthue;
Nguoi(max).Tienthue=tam6;

end
end
n=length(Nguoi);
fprintf('Ma DonVi LoaiXe SoNgayThue SoXe TienThue\n')
for i=1:n
fprintf('%d %s %d %d %d %d\n', Nguoi(i).Ma,
Nguoi(i).Donvi, Nguoi(i).Loaixe, Nguoi(i).Songaythue,
Nguoi(i).Soxe,Nguoi(i).Tienthue)
end

fprintf('\tBan chon tiep(12:thoat): ')
chon=input('');
case 3
mang1=size(arrdonvi);
if(mang1<1)
fprintf('\tBan hay chon 1 truoc! \n')
return

end
%cau 3
fprintf('===TIM THONG TIN CUA 1 NGUOI KHI NHAP VAO MA===\n')
fprintf('Xin moi nhap vao ma can tim kiem: ')
nhap=input('');
fprintf('\nBan da nhap: %d\n',nhap)
fprintf('Ket qua tim kiem: \n')
demnguoi=0;
vitringuoi=0;
n1 = length(Nguoi);%Lay ve kich thuoc se linh hoat hon neu nhu mang duoc
xoa hay them
for i=1:n1
if(nhap==Nguoi(i).Ma)
demnguoi=demnguoi+1;
vitringuoi=i;
end
end
if(demnguoi~=0)
fprintf('Da tim thay nguoi co ma %d tai vi tri thu %d\n
',Nguoi(vitringuoi).Ma,vitringuoi);
fprintf('Thong tin nguoi do nhu sau:\n')
fprintf('Ma DonVi LoaiXe SoNgayThue SoXe TienThue\n')
fprintf('%d %s %d %d %d %d\n',
Nguoi(vitringuoi).Ma, Nguoi(vitringuoi).Donvi, Nguoi(vitringuoi).Loaixe,
Nguoi(vitringuoi).Songaythue, Nguoi(vitringuoi).Soxe,Nguoi(vitringuoi).Tienthue)
else
fprintf('Khong tim thay ai co ma vua nhap!')
end

fprintf('\tBan chon tiep(12:thoat): ')

chon=input('');
case 4
mang1=size(arrdonvi);
if(mang1<1)
fprintf('\tBan hay chon 1 truoc! \n')
return
end
%cau 4
%tinh tong tien thue cua tung don vi,tong tien thue cua ca danh sach
dem=0;
tientungdvsonhieu=0;
tientungdv=0;
arrremoveddum=unique(arrdonvi,'first');%loai bo thanh phan trung lap trong
mang arrdonvi
n1=size(arrremoveddum);%lay ve kich thuoc mang arrremoveddum
tam=0;
%that la rac roi khi phai lay ra so nguoi trung nhau roi lai so
%sanh voi chinh no
for j=1:n1
for i=1:n
if(Nguoi(i).Donvi==arrremoveddum(j))
dem=dem+1;
end
end
end
%neu co nhieu nguoi trung nhau thi chi in ra lan cuoi, tuc la gia
%tri cuoi tinh duoc cua tien thue don vi do
for j=1:n1
for i=1:n
if(Nguoi(i).Donvi==arrremoveddum(j))

tientungdvsonhieu=tientungdvsonhieu+Nguoi(i).Tienthue;
tam=tam+1;
if(tam==dem)
fprintf('Tong tien thue cua don vi %s la:
%g\n',arrremoveddum(j),tientungdvsonhieu)
end
else
tientungdv=Nguoi(i).Tienthue;
fprintf('Tong tien thue cua don vi %s la:
%g\n',Nguoi(i).Donvi,tientungdv)
end

end
end
%tinh tong tien thue cho tat ca danh sach
tongthue=0;
for i=1:n
tongthue=tongthue+Nguoi(i).Tienthue;
end
fprintf('Tong tien cua ca danh sach: %g',tongthue)
fprintf('\tBan chon tiep(12:thoat): ')
chon=input('');
case 5
mang1=size(arrdonvi);
if(mang1<1)
fprintf('\tBan hay chon 1 truoc! \n')
return
end
%Cau 5
%Xoa di 1 nguoi khi nhap vao ma

fprintf('Hay nhap vao ma nguoi can xoa: ')
nhap1 = input('');
n2=length(Nguoi);
%quan ly nguoi ban linked_list
% listObj = linked_list([]);
% for i=1:n2
% listObj.add_element(Nguoi(i),i);
% end


tam2=0;
t=0;
for i=1:n2
if(nhap1==Nguoi(i).Ma)
Nguoi(i)=[];
% t=i;
% while(tam2~=(n-t))
% tam2=tam2+1;
% Nguoi(i+1).Ma=Nguoi(i).Ma;
% Nguoi(i+1).Donvi=Nguoi(i).Donvi;
% Nguoi(i+1).Loaixe=Nguoi(i).Loaixe;
% Nguoi(i+1).Songaythue=Nguoi(i).Songaythue;
% Nguoi(i+1).Soxe=Nguoi(i).Soxe;
% Nguoi(i+1).Tienthue=Nguoi(i).Tienthue;
% i=i+1;
%end
break;
end
end
fprintf('Sau khi xoa ta co danh sach\n')

fprintf('Ma DonVi LoaiXe SoNgayThue SoXe TienThue\n')
n3=length(Nguoi);
for i=1:n3
fprintf('%d %s %d %d %d %d\n', Nguoi(i).Ma,
Nguoi(i).Donvi, Nguoi(i).Loaixe, Nguoi(i).Songaythue,
Nguoi(i).Soxe,Nguoi(i).Tienthue)
end
%fprintf('gia tri n1 %d\n',n1)
fprintf('\tBan chon tiep(12:thoat): ')
chon=input('');
case 6
mang1=size(arrdonvi);
if(mang1<1)
fprintf('\tBan hay chon 1 truoc! \n')
return
end
%Cau 6
%Them vao 1 nguoi o vi tri bat ky
n2=length(Nguoi);
fprintf('Ban muon them nguoi vao vi tri nao: ')
nhap2 = input('');
while(nhap2>n2)
fprintf('Vi tri ban them ngoai khoang cho phep, Yeu cau nhap lai: ')
nhap2 = input('');
end
%Chuan bi truoc khi them nguoi moi
tam1=0;
tam2='A';
tam3=0;
tam4=0;

tam5=0;
tam6=0;
% n=length(Nguoi);
% fprintf('kich thuoc truoc %d',n);
% Nguoi=Nguoi([2:end 1]);
n2=length(Nguoi);
%fprintf('kich thuoc sau %d',n2);
% for i =1:n+1
% if(nhap2==i)
% for j=nhap2:n
% %doi cho Ma
% tam1=Nguoi(j).Ma;
% Nguoi(j).Ma=Nguoi(j+1).Ma;
% Nguoi(j+1).Ma=tam1;
% %Doi cho don vi
% tam2=Nguoi(j).Donvi;
% Nguoi(j).Donvi=Nguoi(j+1).Donvi;
% Nguoi(j+1).Donvi=tam2;
% %doi cho loai xe
% tam3=Nguoi(j).Loaixe;
% Nguoi(j).Loaixe=Nguoi(j+1).Loaixe;
% Nguoi(j+1).Loaixe=tam3;
% %doi cho so ngay thue
% tam4=Nguoi(j).Songaythue;
% Nguoi(j).Songaythue=Nguoi(j+1).Songaythue;
% Nguoi(j+1).Songaythue=tam4;
% %doi cho so xe
% tam5=Nguoi(j).Soxe;
% Nguoi(j).Soxe=Nguoi(j+1).Soxe;
% Nguoi(j+1).Soxe=tam5;

% %doi cho tien thue
% tam6=Nguoi(j).Tienthue;
% Nguoi(j).Tienthue=Nguoi(j+1).Tienthue;
% Nguoi(j+1).Tienthue=tam6;
%
% end
% end
% end
%Ket thuc chua bi truoc khi them nguoi moi

%Them thong tin cho nguoi moi
fprintf('Nhap thong tin cho nguoi moi\n')
fprintf('\tNhap ma: ')
Nguoi(n2+1).Ma = input('');
fprintf('\tNhap vao don vi: ')
Nguoi(n2+1).Donvi=input('','s');
fprintf('\tNhap Loai xe: ')
Nguoi(n2+1).Loaixe=input('');
fprintf('\tNhap so ngay thue: ')
Nguoi(n2+1).Songaythue=input('');
fprintf('\tNhap so xe: ')
Nguoi(n2+1).Soxe=input('');
if(Nguoi(n2+1).Songaythue==1)
Nguoi(n2+1).Tienthue=500000;
else if(Nguoi(n2+1).Songaythue<=4)
Nguoi(n2+1).Tienthue=500000+(Nguoi(n2+1).Songaythue-
1)*400000;
else if(Nguoi(n2+1).Songaythue<=8)
Nguoi(n2+1).Tienthue=500000 + 3*400000 +
(Nguoi(n2+1).Songaythue-4)*300000;

else
Nguoi(n2+1).Tienthue= 500000 + 3*400000 +4*300000+
(Nguoi(n2+1).Songaythue-8)*200000;
end
end
end
%Ket thuc them thong tin cho nguoi moi
%Sau do se doi cho nguoi moi them va nguoi thu nhap vao
%doi cho Ma
for i=n2+1:-1:nhap2+1
tam1=Nguoi(i).Ma;
Nguoi(i).Ma=Nguoi(i-1).Ma;
Nguoi(i-1).Ma=tam1;
%Doi cho don vi
tam2=Nguoi(i).Donvi;
Nguoi(i).Donvi=Nguoi(i-1).Donvi;
Nguoi(i-1).Donvi=tam2;
%doi cho loai xe
tam3=Nguoi(i).Loaixe;
Nguoi(i).Loaixe=Nguoi(i-1).Loaixe;
Nguoi(i-1).Loaixe=tam3;
%doi cho so ngay thue
tam4=Nguoi(i).Songaythue;
Nguoi(i).Songaythue=Nguoi(i-1).Songaythue;
Nguoi(i-1).Songaythue=tam4;
%doi cho so xe
tam5=Nguoi(i).Soxe;
Nguoi(i).Soxe=Nguoi(i-1).Soxe;
Nguoi(i-1).Soxe=tam5;
%doi cho tien thue

tam6=Nguoi(i).Tienthue;
Nguoi(i).Tienthue=Nguoi(i-1).Tienthue;
Nguoi(i-1).Tienthue=tam6;
end

n2=length(Nguoi);
fprintf('Sau khi them nguoi ta co \n')
fprintf('Ma DonVi LoaiXe SoNgayThue SoXe TienThue\n')
for i=1:n2
fprintf('%d %s %d %d %d %d\n', Nguoi(i).Ma,
Nguoi(i).Donvi, Nguoi(i).Loaixe, Nguoi(i).Songaythue,
Nguoi(i).Soxe,Nguoi(i).Tienthue)
end

fprintf('\tBan chon tiep(12:thoat): ')
chon=input('');
case 7
mang1=size(arrdonvi);
if(mang1<1)
fprintf('\tBan hay chon 1 truoc! \n')
return
end
%Cau 7
%Sua thong tin cua 1 nguoi khi nhap vao ma
fprintf('Ban muon sua thong tin nguoi co ma la gi? ')
nhap3 = input('');
n3= length(Nguoi);
vitri=0;
dvtam='A';
lxtam=0;

snttam=0;
sxtam=0;
tttam=0;
for i=1:n3
if(nhap3==Nguoi(i).Ma)
vitri=i;
dvtam=Nguoi(i).Donvi;
lxtam=Nguoi(i).Loaixe;
snttam=Nguoi(i).Songaythue;
sxtam=Nguoi(i).Soxe;
tttam=Nguoi(i).Tienthue;
fprintf('\n\tNhap vao don vi: ')
Nguoi(i).Donvi=input('','s');
fprintf('\tNhap Loai xe: ')
Nguoi(i).Loaixe=input('');
fprintf('\tNhap so ngay thue: ')
Nguoi(i).Songaythue=input('');
fprintf('\tNhap so xe: ')
Nguoi(i).Soxe=input('');
if(Nguoi(i).Songaythue==1)
Nguoi(i).Tienthue=500000;
else if(Nguoi(i).Songaythue<=4)
Nguoi(i).Tienthue=500000+(Nguoi(i).Songaythue-1)*400000;
else if(Nguoi(i).Songaythue<=8)
Nguoi(i).Tienthue=500000 + 3*400000 +(Nguoi(i).Songaythue-
4)*300000;
else
Nguoi(i).Tienthue= 500000 + 3*400000 +4*300000+
(Nguoi(i).Songaythue-8)*200000;
end

end
end
end
end

n3=length(Nguoi);
fprintf('TRUOC KHI SUA THONG TIN NGUOI CO MA %d TAI VI TRI
%d NHU SAU \n',nhap3,vitri);
fprintf('Ma DonVi LoaiXe SoNgayThue SoXe TienThue\n')
fprintf('%d %s %d %d %d %d\n',
Nguoi(vitri).Ma,dvtam,lxtam, snttam, sxtam, tttam)
fprintf('Sau khi sua thong nguoi ta co ma %d tai vi tri %d tro
thanh\n',nhap3,vitri)
fprintf('Ma DonVi LoaiXe SoNgayThue SoXe TienThue\n')
fprintf('%d %s %d %d %d %d\n', Nguoi(vitri).Ma,
Nguoi(vitri).Donvi, Nguoi(vitri).Loaixe, Nguoi(vitri).Songaythue,
Nguoi(vitri).Soxe,Nguoi(vitri).Tienthue)
fprintf('CA DANH SACH SAU KHI SUA THONG TIN NHU SAU\n')
fprintf('Ma DonVi LoaiXe SoNgayThue SoXe TienThue\n')
for i=1:n3
fprintf('%d %s %d %d %d %d\n', Nguoi(i).Ma,
Nguoi(i).Donvi, Nguoi(i).Loaixe, Nguoi(i).Songaythue,
Nguoi(i).Soxe,Nguoi(i).Tienthue)
end
fprintf('\tBan chon tiep(12:thoat): ')
chon=input('');
case 8
mang1=size(arrdonvi);
if(mang1<1)
fprintf('\tBan hay chon 1 truoc: ')

return
end
%Cau 8
%Ve do thi bieu dien tuong quan giua tien thue va so ngay thue
n=length(Nguoi);
for i=1:n
ngaythue(i)=Nguoi(i).Songaythue;
tienthue(i)=Nguoi(i).Tienthue;
end
figure

plot(ngaythue,tienthue,'r*-')
xlabel('Ngay thue')
ylabel('Tien thue')
title('Tuong quan giua ngay thue va tien thue')

fprintf('\tBan chon tiep(12:thoat): ')
chon=input('');
case 9
%cau 9
%Ve do thi dang cot de so sanh tien thue va so xe
n=length(Nguoi);
for i=1:n
soxe(i)=Nguoi(i).Soxe;
tienthue1(i)=Nguoi(i).Tienthue;
end
figure
bar(soxe,tienthue1)
xlabel('So Xe')
ylabel('Tien Thue')

title('Tuong quan giua ngay thue va so xe')

fprintf('\tBan chon tiep(12:thoat): ')
chon=input('');
case 10
%cau 10
%Ve do thi dang pie Cho cot tien thue cua tung don vi
n=length(Nguoi);
for i=1:n
tienthue2(i)=Nguoi(i).Tienthue;
end
figure
pie(tienthue2)

fprintf('\tBan chon tiep(12:thoat): ')
chon=input('');
case 11

fprintf('====================================================\n'
)
fprintf('\t1.Nhap Du Lieu va tinh tien thue cho tung nguoi.\n')
fprintf('\t2.Sap xep theo so xe giam dan.\n')
fprintf('\t3.Tim thong tin tung nguoi khi nhap vao ma.\n')
fprintf('\t4.Tinh tong tien thue cua tung don vi va ca danh sach.\n')
fprintf('\t5.Xoa nguoi khi nhap va ma.\n')
fprintf('\t6.Them nguoi o vi tri bat ky.\n')
fprintf('\t7.Sua thong tin nguoi khi nhap ma.\n')
fprintf('\t8.Do thi tuong quan tien thue so ngay thue.\n')
fprintf('\t9.Do thi danh cot so sanh tien thue so ngay thue.\n')
fprintf('\t10.Do thi dang pie cho cot tong tien thue.\n')

fprintf('\t11.Ve Menu\n')
fprintf('\t12.Thoat.\n\n')

fprintf('====================================================\n'
)
fprintf('\tBan chon: ')
chon=input('');
end
end
end%ket thuc function
3,Câu 2
Code:
function Bai2()

dem=1;
for i=7:1.7:17
x=[-4:0.2:i];
y=3*x.^4 + 2*x.^3-2*x+1;
Xlabel('truc x')
Ylabel('truc y')
title('y=3*x^4 + 2*x^3-2*x+1')
subplot(3,2,dem)
plot(x,y,'r ')
dem=dem+1;
Xlabel('truc x')
Ylabel('truc y')
title('y=3*x^4 + 2*x^3-2*x+1')
grid on
end
end

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×