Tải bản đầy đủ (.docx) (14 trang)

Lập trình Pascal (ôn thi HSG) chương trình nhập và xuất hóa đơn bán lẻ, ghi kết quả dưới định dạng số tiền và đọc số tiền thành chữ

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 (70.28 KB, 14 trang )

{Dùng app Pascal N – IDE để chạy chương trình, vì trong chương trình có sử dụng tiếng Việt có
dấu. }

{LẬP TRÌNH PASCAL: (ƠN THI HSG) CHƯƠNG TRÌNH NHẬP
VÀ XUẤT HÓA ĐƠN BÁN LẺ, GHI KẾT QUẢ DƯỚI ĐỊNH
DẠNG SỐ TIỀN VÀ ĐỌC SỐ TIỀN THÀNH CHỮ.}
uses crt;
procedure docso(x:integer);
var tr,ch,dvi:integer;
begin
tr:= x div 100;


ch:= (x-100*tr) div 10;
dvi:= x mod 100 - 10*ch;
IF (wherex<15) then begin
Case tr of
0: begin
if (wherex>19) and (ch<>0) then write('không trăm ');
if (wherex>19) and (ch=0) and (dvi<>0) then
write('không trăm linh ') end;
1: write('Một');
2: write('Hai');
3: write('Ba');
4: write('Bốn');
5: write('Năm');
6: write('Sáu');
7: write('Bảy');
8: write('Tám');
9: write('Chín');
end;




if (tr<>0) then if (ch<>0) then write(' trăm ') else write('
trăm');
if (tr=0) then
case ch of
0:if (tr<>0) and (dvi<>0) then write(' linh ');
1:if (dvi<>0) then write('Mười ') else write('Mười');
2: write('Hai');
3: write('Ba');
4: write('Bốn');
5: write('Năm');
6: write('Sáu');
7: write('Bảy');
8: write('Tám');
9: write('Chín');
end
else
case ch of
0:if (tr<>0) and (dvi<>0) then write(' linh ');


1:if (dvi<>0) then write('mười ') else write('mười');
2: write('hai');
3: write('ba');
4: write('bốn');
5: write('năm');
6: write('sáu');
7: write('bảy');
8: write('tám');

9: write('chín');
end;
if (ch<>1) and (ch<>0) then if (dvi<>0) then write(' mươi
') else write(' mươi');
if (tr+ch=0) then
case dvi of
0: if (ch=0) and (tr=0) then write('không');
1: if (ch<2) then write('Một') else write('mốt');
2: write('Hai');
3: write('Ba');
4: if (ch<2) then write('Bốn') else write('tư');


5: if (ch<1) then write('Năm') else write('lăm');
6: write('Sáu');
7: write('Bảy');
8: write('Tám');
9: write('Chín');
end
else
case dvi of
0: if (ch=0) and (tr=0) then write('khơng');
1: if (ch<2) then write('một') else write('mốt');
2: write('hai');
3: write('ba');
4: if (ch<2) then write('bốn') else write('tư');
5: if (ch<1) then write('năm') else write('lăm');
6: write('sáu');
7: write('bảy');
8: write('tám');

9: write('chín');


end;
end
else
begin
Case tr of
0: begin
if (wherex>18) and (ch<>0) then write('không trăm ');
if (wherex>18) and (ch=0) and (dvi<>0) then
write('không trăm linh ') end;
1: write('một');
2: write('hai');
3: write('ba');
4: write('bốn');
5: write('năm');
6: write('sáu');
7: write('bảy');
8: write('tám');
9: write('chín');
end;


if (tr<>0) then if (ch<>0) then write(' trăm ') else write('
trăm');
case ch of
0:if (tr<>0) and (dvi<>0) then write(' linh ');
1:if (dvi<>0) then write('mười ') else write('mười');
2: write('hai');

3: write('ba');
4: write('bốn');
5: write('năm');
6: write('sáu');
7: write('bảy');
8: write('tám');
9: write('chín');
end;
if (ch<>1) and (ch<>0) then if (dvi<>0) then write(' mươi
') else write(' mươi');
case dvi of
0: if (ch=0) and (tr=0) then write('không');
1: if (ch<2) then write('một') else write('mốt');


2: write('hai');
3: write('ba');
4: if (ch<2) then write('bốn') else write('tư');
5: if (ch<1) then write('năm') else write('lăm');
6: write('sáu');
7: write('bảy');
8: write('tám');
9: write('chín');
end;
end;
end;
var vat,s,i,j,n,m,h,p,t,o,v,n1,n3,n2,k:int64;
L,G: array [1..1000] of int64;
begin
clrscr;

s:=0;
write('Số mặt hàng: '); readln(n);clrscr; writeln;
for i:=1 to n do


begin
j:=i;
writeln('-) Mặt hàng (',i,'): ');
write('+) Số lượng: '); readln(l[i]);
write('+) Đơn giá: '); read(g[j]); p:=g[j]; gotoxy(13,wherey1);
if (p<1000) then write(p);
if (p>999) and (p<1000000) then begin
v:= p div 1000;
k:= p mod 1000;
write(v,',');
if (k<10) then write('00',k);
if (k>9) and (k<99) then write('0',k);
if (k>99) then write(k);
end;
if (p>999999) then begin
o:=p div 1000000; v:=(p mod 1000000) div 1000; k:= (p(p div 1000000)*1000000) mod 1000;
write(o,',');


if (v<10) then write('00',v,',');
if (v>9) and (v<99) then write('0',v,',');
if (v>99) then write(v,',');
if (k<10) then write('00',k);
if (k>9) and (k<99) then write('0',k);
if (k>99) then write(k);

end;
write(' ₫');
s:= s+l[i]*p;
writeln; writeln;
end;
writeln('----------------------------'); writeln;
write('Thuế VAT: '); readln(vat); gotoxy(1,wherey-1);
writeln('Thuế VAT: ',vat,'%'); s:= round(s+s*vat/100);
writeln;
write('TỔNG CỘNG: ');
if (s<1000) then write(s);
if (s>999) and (s<1000000) then begin


t:= s div 1000;
h:= s mod 1000;
write(t,',');
if (h<10) then write('00',h);
if (h>9) and (h<99) then write('0',h);
if (h>99) then write(h);
write(' ₫')
end;
if (s>999999) then begin
m:=s div 1000000; t:=(s mod 1000000) div 1000; h:= (s- (s
div 1000000)*1000000) mod 1000;
write(m,',');
if (t<10) then write('00',t,',');
if (t>9) and (t<99) then write('0',t,',');
if (t>99) then write(t,',');
if (h<10) then write('00',h);

if (h>9) and (h<99) then write('0',h);
if (h>99) then write(h);
write(' ₫')


end;
writeln;
writeln;
write('THÀNH TIỀN: ');
if (s<1000) then docso(s);
if (s>999) and (s<1000000) then
begin
n1:= s div 1000;
n2:= s mod 1000;
docso(n1); if (n2<>0) then write(' nghìn ') else write('
nghìn'); if (n2>0) then docso(n2);
end;
if (s>999999) then
begin
n1:= s div 1000000;
n2:= (s mod 1000000) div 1000;
n3:= (s-(s div 1000000)*1000000) mod 1000;
docso(n1); if (n2+n3<>0) then write(' triệu ') else write('
triệu');


if (n2>0) then begin
docso(n2);if (n3<>0) then write(' nghìn ') else write('
nghìn'); end;
if (n3>0) then

docso(n3);
end;
write(' đồng.');
readln
end.




×