|
发表于 2021-8-25 16:48:20
|
显示全部楼层
我是菜虫.才学习 黛尔妃 几天. 老侯的版权.
program Project股民;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils;
type
//定义一个股民信息,是不同变量的集合.
Holder = record
//股民ID
ID ,Name: string;
end;
//动态数组来存储信息,因你无法知道总数.
HolderList = array of Holder;
var
GuMinList :HolderList; //真正的信息存储地.
{*------------------------------------------------------------------------------
-------------------------------------------------------------------------------}
procedure addGuMin(); //添加一个过程.
var
GuMin:Holder;
ArrayLength :Integer;
//生成唯一标识语句如下
UUID :TGUID;
begin
//获取股民信息库中的信息个数.
ArrayLength := Length(GuMinList);
Writeln('你选择了添加功能,请输入姓名.');
CreateGUID(UUID);
GuMin.ID :=GUIDToString(UUID);
{将用户输入的股民姓名赋值给记录类型的NAME变量.}
Readln(GuMin.Name); // 这里如果咩有,就不显示所有的姓名,只有ID号
//将股民信息保存在数组中.
Insert(GuMin,GuMinList,ArrayLength - 1); //insert用法还要看一看.
//如果添加之后的数组元素个数大于添加前,则添加成功.
if Length(GuMinList) > ArrayLength then
begin
Writeln('添加成功!!');
end
else
begin
Writeln('添加失败..');
end;
end;
//\查询信息
procedure LisHolder();
var
GuMin:Holder;
begin
Writeln('你选择了查询功能,请输入要查询的韭菜名:');
for GuMin in GuMinList do
begin
//with语句
with GuMin do
begin
Writeln('编号是',ID,#$09,'姓名是:', Name);
end;
// WriteLN(GuMin.ID , GuMin.Name) 上面的With语句作用.
end;
end;
//删除股民信息.
procedure DeleteGuMin();
var
GuMin : Holder;
DName:string;
Istrue : string;
indexs: Integer;
ArrayLength: Integer;
begin
Writeln('你选择了删除功能,请输入要删除的韭菜名:');
Readln(DName);
indexs := 0;
//获取删除之前的数据总数.
arrayLength := Length(GuMinList);
//遍历数组中的所有.
for GuMin in GuMinList do
begin
//with语句
with GuMin do
begin
if (DName=Name) then
begin
//删除需要二次确认.
Writeln('确认删除【',ID,Name,'】吗? Y/N'); //为什么是[',ID,Name,']
Readln(IsTrue);
if (Istrue = 'Y') then
begin
Delete(GuMinList,indexs,1);
//删除之后,比对元素总数.
if (Length(GuMinList)>Arraylength) then
begin
Writeln('删除成功!!!');
end
else
begin
WriteLN('删除失败');
end;
end;
Exit;
end;
end;
Inc(indexs);
end;
end;
// 修改姓名与ID
procedure Update();
var
UName:string;
i:Integer;
isExist :boolean;
begin
isExist := False;
Writeln('你选择了修改功能,请输入修改的姓名..');
Readln(UName);
//遍历数组,查找修改
for I := Low(GuMinList) to High(GuMinList) do
begin
with GuMinList[i] do
begin
if (Name = Uname) then
begin
Writeln('请输入新的名字,,');
Readln(Uname); //赋值?
Name := UName;
isExist := True;
Break;
end;
end;
end;
if (isExist = false) then
begin
Writeln('查无此人..');
end;
end;
procedure ShowMenu(); //选择菜单
begin
Writeln('');
Writeln('********韭菜名单********');
Writeln('');
Writeln('1,添加韭菜');
Writeln('2,删除韭菜');
Writeln('3,查询韭菜');
Writeln('4,修改韭菜');
Writeln('************************');
end;
procedure UserChoose();
var
UserChooseindex:Integer;
begin
Writeln('请选择你要使用的功能');
//获取用户输入编号.
Readln(UserChooseIndex);
//判断用户输入编号多少.
case UserChooseIndex of
1:
begin
addGuMin(); //调用过程.
end;
2:
begin
DeleteGuMin();
end;
3:
begin
LisHolder(); //调用过程proceduce XXXX
end;
4:
begin
Update();
end
else
begin
Writeln('请输入正确的编号');
end;
end;
end;
begin
//初始化股民信息列表
GuMinList := [];
//无线循环 选择页面.
while True do
begin
ShowMenu();
UserChoose();
end;
Readln;
end.
|
|