From c1147629f7aae2ee90ccd7c9f1ccbf106361d486 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Sat, 13 Dec 2025 16:35:46 +0100 Subject: =?UTF-8?q?Add=20book=20"=D0=97=D0=B0=D0=BD=D0=B8=D0=BC=D0=B0?= =?UTF-8?q?=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D0=BE=D0=B5=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=B3=D1=80=D0=B0=D0=BC=D0=BC=D0=B8=D1=80=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../1/11_8_fma/Project1.lpi" | 60 ++++++ .../1/11_8_fma/Project1.lps" | 92 +++++++++ .../1/11_8_fma/Project1.pas" | 228 +++++++++++++++++++++ 3 files changed, 380 insertions(+) create mode 100644 "\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/11_8_fma/Project1.lpi" create mode 100644 "\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/11_8_fma/Project1.lps" create mode 100644 "\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/11_8_fma/Project1.pas" (limited to 'Занимательное программирование/1/11_8_fma') diff --git "a/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/11_8_fma/Project1.lpi" "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/11_8_fma/Project1.lpi" new file mode 100644 index 0000000..ec719b8 --- /dev/null +++ "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/11_8_fma/Project1.lpi" @@ -0,0 +1,60 @@ + + + + + + + + + + + + <UseAppBundle Value="False"/> + <ResourceType Value="res"/> + </General> + <BuildModes> + <Item Name="Default" Default="True"/> + </BuildModes> + <PublishOptions> + <Version Value="2"/> + <UseFileFilters Value="True"/> + </PublishOptions> + <RunParams> + <FormatVersion Value="2"/> + </RunParams> + <Units> + <Unit> + <Filename Value="Project1.pas"/> + <IsPartOfProject Value="True"/> + </Unit> + </Units> + </ProjectOptions> + <CompilerOptions> + <Version Value="11"/> + <Target> + <Filename Value="Project1"/> + </Target> + <SearchPaths> + <IncludeFiles Value="$(ProjOutDir)"/> + <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/> + </SearchPaths> + <Linking> + <Debugging> + <DebugInfoType Value="dsDwarf3"/> + </Debugging> + </Linking> + </CompilerOptions> + <Debugging> + <Exceptions> + <Item> + <Name Value="EAbort"/> + </Item> + <Item> + <Name Value="ECodetoolError"/> + </Item> + <Item> + <Name Value="EFOpenError"/> + </Item> + </Exceptions> + </Debugging> +</CONFIG> diff --git "a/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/11_8_fma/Project1.lps" "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/11_8_fma/Project1.lps" new file mode 100644 index 0000000..00da674 --- /dev/null +++ "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/11_8_fma/Project1.lps" @@ -0,0 +1,92 @@ +<?xml version="1.0" encoding="UTF-8"?> +<CONFIG> + <ProjectSession> + <Version Value="12"/> + <BuildModes Active="Default"/> + <Units> + <Unit> + <Filename Value="Project1.pas"/> + <IsPartOfProject Value="True"/> + <IsVisibleTab Value="True"/> + <TopLine Value="81"/> + <CursorPos X="27" Y="105"/> + <UsageCount Value="21"/> + <Loaded Value="True"/> + </Unit> + </Units> + <JumpHistory HistoryIndex="16"> + <Position> + <Filename Value="Project1.pas"/> + <Caret Line="63" Column="31" TopLine="25"/> + </Position> + <Position> + <Filename Value="Project1.pas"/> + <Caret Line="51" Column="31" TopLine="27"/> + </Position> + <Position> + <Filename Value="Project1.pas"/> + <Caret Line="76" Column="47" TopLine="45"/> + </Position> + <Position> + <Filename Value="Project1.pas"/> + <Caret Line="22" Column="37"/> + </Position> + <Position> + <Filename Value="Project1.pas"/> + <Caret Line="14" Column="5"/> + </Position> + <Position> + <Filename Value="Project1.pas"/> + <Caret Line="77" Column="16" TopLine="39"/> + </Position> + <Position> + <Filename Value="Project1.pas"/> + <Caret Line="107" Column="27" TopLine="75"/> + </Position> + <Position> + <Filename Value="Project1.pas"/> + <Caret Line="86" Column="14" TopLine="75"/> + </Position> + <Position> + <Filename Value="Project1.pas"/> + <Caret Line="53" Column="5" TopLine="14"/> + </Position> + <Position> + <Filename Value="Project1.pas"/> + <Caret Line="97" Column="9" TopLine="57"/> + </Position> + <Position> + <Filename Value="Project1.pas"/> + <Caret Line="103" Column="57" TopLine="67"/> + </Position> + <Position> + <Filename Value="Project1.pas"/> + <Caret Line="112" Column="59" TopLine="78"/> + </Position> + <Position> + <Filename Value="Project1.pas"/> + <Caret Line="118" Column="58" TopLine="87"/> + </Position> + <Position> + <Filename Value="Project1.pas"/> + <Caret Line="122" Column="9" TopLine="98"/> + </Position> + <Position> + <Filename Value="Project1.pas"/> + <Caret Line="116" Column="62" TopLine="97"/> + </Position> + <Position> + <Filename Value="Project1.pas"/> + <Caret Line="4" Column="16"/> + </Position> + <Position> + <Filename Value="Project1.pas"/> + <Caret Line="12" Column="12" TopLine="12"/> + </Position> + </JumpHistory> + <RunParams> + <FormatVersion Value="2"/> + <Modes ActiveMode=""/> + </RunParams> + </ProjectSession> +</CONFIG> diff --git "a/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/11_8_fma/Project1.pas" "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/11_8_fma/Project1.pas" new file mode 100644 index 0000000..f8e0fc3 --- /dev/null +++ "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/11_8_fma/Project1.pas" @@ -0,0 +1,228 @@ +program Project1; + +{$mode objfpc}{$H+} +{$codepage utf8} + +uses + {$IFDEF UNIX} + cthreads, + {$ENDIF} + Classes, SysUtils, CustApp + { you can add units after this }; + + type StateType = (pay, coffee, cup, back); + type CommandType = ( + pay5, pay10, pay20, pay50, pay100, pay200, + chooseblack, choosesugar, coosecappu, choosecacao, + choosecup, choosenocup, payback + ); + +type + + { TStateMachine } + + TStateMachine = class(TCustomApplication) + protected + procedure DoRun; override; + public + constructor Create(TheOwner: TComponent); override; + destructor Destroy; override; + function GetNextCommand: CommandType; + end; + +{ TStateMachine } + +procedure TStateMachine.DoRun; +var + ErrorMsg: String; + State: StateType = pay; + Command: CommandType; + moneyPayed: Integer = 0; +begin + // quick check parameters + ErrorMsg := CheckOptions('h', 'help'); + if ErrorMsg <> '' then begin + ShowException(Exception.Create(ErrorMsg)); + Terminate; + Exit; + end; + + while true do + begin + Command := GetNextCommand; + case State of + pay: + begin + case Command of + pay5: + begin + moneyPayed := moneyPayed + 5; + end; + pay10: + begin + moneyPayed := moneyPayed + 10; + end; + pay20: + begin + moneyPayed := moneyPayed + 20; + end; + pay50: + begin + moneyPayed := moneyPayed + 50; + end; + pay100: + begin + moneyPayed := moneyPayed + 100; + end; + pay200: + begin + moneyPayed := moneyPayed + 200; + end; + chooseblack, choosesugar, coosecappu, choosecacao: + begin + if moneyPayed >= 70 then + begin + State := coffee; + end + else + begin + WriteLn('Вы бросили недостаточно денег.'); + end; + end + else + WriteLn('Неверная команда!'); + end; + end; + coffee: + begin + case Command of + choosecup, choosenocup: + begin + State := cup; + end; + else + WriteLn('Неверная команда!'); + end; + end; + cup: + begin + case Command of + payback: + begin + State := back; + WriteLn('Ваша сдача: ' + IntToStr(moneyPayed - 70)); + Break; + end; + else + WriteLn('Неверная команда!'); + end; + end; + back: + begin + end; + end; + end; + + // stop program loop + Terminate; +end; + +constructor TStateMachine.Create(TheOwner: TComponent); +begin + inherited Create(TheOwner); + StopOnException:=True; +end; + +destructor TStateMachine.Destroy; +begin + inherited Destroy; +end; + +function TStateMachine.GetNextCommand: CommandType; +var + Input: String; +begin + Writeln('Введите команду:'); + while true do + begin + Readln(Input); + case Input of + 'pay5': + begin + Result := pay5; + Exit; + end; + 'pay10': + begin + Result := pay10; + Exit; + end; + 'pay20': + begin + Result := pay20; + Exit; + end; + 'pay50': + begin + Result := pay50; + Exit; + end; + 'pay100': + begin + Result := pay100; + Exit; + end; + 'pay200': + begin + Result := pay200; + Exit; + end; + 'chooseblack': + begin + Result := chooseblack; + Exit; + end; + 'choosesugar': + begin + Result := choosesugar; + Exit; + end; + 'choosecappu': + begin + Result := coosecappu; + Exit; + end; + 'choosecacao': + begin + Result := choosecacao; + Exit; + end; + 'choosecup': + begin + Result := choosecup; + Exit; + end; + 'choosenocup': + begin + Result := choosenocup; + Exit; + end; + 'payback': + begin + Result := payback; + Exit; + end + else Writeln('Команда не существует. Попробуйте еще раз:'); + end; + end; +end; + +var + Application: TStateMachine; +begin + Application:=TStateMachine.Create(nil); + Application.Title:='State automat'; + Application.Run; + Application.Free; +end. + -- cgit v1.2.3