📄 unit1.pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ComCtrls;
type
TForm1 = class(TForm)
GroupBox1: TGroupBox;
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
StatusBar1: TStatusBar;
ComboBox1: TComboBox;
Label6: TLabel;
Label7: TLabel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Label8: TLabel;
procedure Button4Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
n:integer;
a:array[0..3] of integer;
implementation
{$R *.dfm}
procedure TForm1.Button4Click(Sender: TObject);
begin
close;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i:integer;
begin
n:=0;
for i:=0to 3 do
a[i]:=0;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
k:integer;
begin
k:= combobox1.ItemIndex;
if k<>(-1) then
begin
a[k]:=a[k]+1;
n:=n+1;
label7.Caption:='已唱票数:'+inttostr(n);
if n=30 then button1.Enabled:=false; ////////////30
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
j,m,i:integer;
c:string;
s:array[0..3] of string;
begin
label1.Caption:='张三 '+inttostr(a[0]);
label2.Caption:='李四 '+inttostr(a[1]);
label3.Caption:='王五 '+inttostr(a[2]);
label4.Caption:='赵六 '+inttostr(a[3]);
c:='';
m:=0;
for j:=0 to 3 do
s[j]:=combobox1.Items[j];
//for k:=0 to 3 do
//if a[k]>(n/2)then label8.Caption:=label8.Caption+s[k];
//for j:=0 to 2 do
i:=0;
while i<>3 do
begin
j:=0;
while j<>3 do
begin
if a[j]<a[j+1]then
begin
m:=a[j];
a[j]:=a[j+1];
a[j+1]:=m;
c:=s[j];
s[j]:=s[j+1];
s[j+1]:=c;
end;
j:=j+1;
end;
i:=i+1;
end;
if a[0]>(n div 2) then label8.Caption:=label8.Caption+s[0]
else
if a[0]>a[1] then
label8.Caption:=label8.Caption+s[0]
else if a[1]>a[2]then
label8.Caption:=label8.Caption+s[0]+s[1]
else if a[2]>a[3]then
label8.Caption:=label8.Caption+s[0]+s[1]+s[2]
else
label8.Caption:=label8.Caption+s[0]+s[1]+s[2]+s[3];
button1.Enabled:=false;
button3.Enabled:=true;
button2.Enabled:=false;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
i:integer;
begin
n:=0;
for i:=0 to 3 do
a[i]:=0;
label1.Caption:='张三';
label2.Caption:='李四';
label3.Caption:='王五';
label4.Caption:='赵六';
label7.Caption:='共唱票数';
label8.Caption:='选举结果:';
combobox1.ItemIndex:=-1;
button1.Enabled:=true;
button2.Enabled:=true;
button3.Enabled:=false;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -