Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
unit VariableForm;

interface

//git test
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
Expand All @@ -18,7 +18,7 @@ TForm1 = class(TForm)
// �� ��(����)������ ����ϴ� ������ �Լ��� ����

{ TODO : (1) ���� �� FSum ������ �����ϼ���. }

FSum : Integer;
function AddNum(ANum: Integer): Integer;
public
// �ٸ� ���ֿ��� ������ �� �ִ� ������ �Լ� ����
Expand All @@ -36,7 +36,8 @@ function TForm1.AddNum(ANum: Integer): Integer;
{ TODO :
(2) FSum ������ �Ķ���� ANum ���� ���մϴ�.
FSum ���� ��ȯ }
Result := 0;
FSum := FSum + ANum;
Result := FSum;
end;

procedure TForm1.Button1Click(Sender: TObject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ TForm2 = class(TForm)
��ȯ��: ���ڿ�(�޽���)
(2-2) �Լ� ���� �� Ctrl + Shift + C�� ���� ������ ����
}
function GetUserInfoMsg(AName: string; AAge: integer; AIsMan: boolean): string;

public
// �ٸ� ���ֿ��� ������ �� �ִ� ������ �Լ� ����
end;
Expand All @@ -47,12 +49,13 @@ function TForm2.GetNameMsg(AName: string): string;
var
Msg: string;
begin
Msg := '�ȳ��ϼ���. ';
Msg := '�ݰ����ϴ�. ';
Msg := Msg + AName + '��';

Result := Msg;
end;


function TForm2.GetAgeMsg(AName: string; AAge: Integer): string;
var
Msg, Adult: string;
Expand All @@ -66,6 +69,12 @@ function TForm2.GetAgeMsg(AName: string; AAge: Integer): string;
���ڿ��� ������ ����(���ϱ�) �ϼ���.
������ ���ڷ� ��ȯ(IntToStr)�ϼ���.
}
if AAge >= 20 then
Adult := '����'
else
Adult := '�̼���';

Msg := Msg + AName + '���� ' + intToStr(AAge) + '���� ' + Adult + '�Դϴ�.';

Result := Msg;
end;
Expand Down Expand Up @@ -109,6 +118,7 @@ procedure TForm2.Button3Click(Sender: TObject);
��ȯ�ϴ� �Լ�(GetUserInfoMsg)�� �ۼ��ϼ���
Msg := GetUserInfoMsg(Name, Age, IsMan);
}
Msg := GetUserInfoMsg(Name,Age,IsMan);

ShowMessage(Msg);
end;
Expand All @@ -118,4 +128,25 @@ procedure TForm2.Button3Click(Sender: TObject);
�λ縻 + ���ο��� Ȯ�� + ����Ȯ�� �޽����� ��ȯ�ϵ��� �ۼ��ϼ���.
�̹� ������ GetNameMsg, GetAgeMsg ���� �����ϼ���.
}
function TForm2.GetUserInfoMsg(AName: string; AAge: integer; AIsMan: boolean): string;

var
Msg, Gender: string;

begin
if AIsMan = True then
Gender := '����'
else
Gender := '����';

Msg := GetNameMsg(AName);
Msg := Msg + #13#10;
Msg := GetAgeMsg(AName, AAge);
Msg := Msg + #13#10;
Msg := Msg+AName+'���� '+Gender+'�Դϴ�.';
Msg := Msg + #13#10;

result := Msg;
end;

end.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ procedure TForm3.Button1Click(Sender: TObject);
(1) for ���� �̿��� �迭�� ������ ����ϼ���.
�迭�� ũ�� ����ǵ� �����ϵ��� �ݺ��� ���� Length(FNumArr) - 1�� ����
��> for I := 0 to Length(FNumArr) - 1 do }
for I := 0 to Length(FNumArr) - 1 do
Memo1.Lines.Add('- '+IntToStr(FNumArr[I]));


Memo1.Lines.Add('�迭�� ���� ' + IntToStr(Sum) + ' �Դϴ�.');
Memo1.Lines.Add('�迭�� �ִ밪�� ' + IntToStr(MaxNum) + ' �Դϴ�.');
Expand All @@ -75,6 +78,8 @@ function TForm3.GetArraySum: Integer;
begin
Sum := 0;
{ TODO : (2) for ���� �̿��� �迭�� ���� ��� ���� ��ȯ�ϵ��� ���� }
for I := 0 to Length(FNumArr) - 1 do
Sum := Sum + FNumArr[I];

Result := Sum;
end;
Expand All @@ -87,6 +92,9 @@ function TForm3.GetArrayMaxNum: Integer;
{ TODO :
(3) for ���� �̿��� �迭�� �� �� ���� ū ���� ��ȯ�ϵ��� ����
if ���� �̿��� ���ڸ� �� }
for I := 0 to Length(FNumArr) - 1 do
if FNumArr[I] > MaxNum then
MaxNum := FNumArr[I];

Result := MaxNum;
end;
Expand All @@ -103,6 +111,11 @@ procedure TForm3.Button2Click(Sender: TObject);
50 �̻�(>=)�� ��� CountOver 1 ����
50 �̸�(<)�� ��� CountUnder 1 ���� �ϵ��� ����
}
for I := 0 to Length(FNumArr) - 1 do
if FNumArr[I] >= 50 then
Inc(CountOver)
else
Inc(CountUnder);

Memo1.Lines.Add('50 �̻��� ���� ����: ' + IntToStr(CountOver));
Memo1.Lines.Add('50 �̸��� ���� ����: ' + IntToStr(CountUnder));
Expand Down
Binary file not shown.
File renamed without changes.
158 changes: 158 additions & 0 deletions 20_Task/JJ-HH/M2/Accumulator.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
unit Accumulator;

interface

Uses
VCL.Dialogs, System.Sysutils;

type

// TCalc : ���� ���α׷����� ������ ��� �� ��� ���� ��ȯ�ϴ�Class
TCalc = class(TObject)
{
������ ��Ģ������ �ǿ������� Ÿ��(����/�Ǽ�)�� ���� overload�� ����
opd�� operand�� �����Դϴ�.
}

function Add( _opdA, _opdB:real): real;
function Sub( _opdA, _opdB:real): real;
function Multi( _opdA, _opdB:real): real;
function Divide( _opdA, _opdB:real): extended;
function Accumulate(_opds_Arr:array of Float64; _symbols:array of string): string;

public
constructor create;
end;


implementation

{ TCalc }


function TCalc.Add(_opdA, _opdB: real): real;
begin
Result := _opdA + _opdB;
end;

function TCalc.Sub(_opdA, _opdB: real): real;
begin
Result := _opdA - _opdB;
end;

function TCalc.Multi(_opdA, _opdB: real): real;
begin
Result := _opdA * _opdB;
end;

function TCalc.Divide(_opdA, _opdB: real): extended;
begin
try
Result:=_opdA / _opdB;
except
on e: EMathError do
showMessage('0���� ���� �� �����ϴ�.');
end;
end;


function TCalc.Accumulate(_Opds_Arr: array of Float64; _Symbols: array of string): string;
var
I,J,K : integer; // for loops
tmpOpd : array of Float64;
tmpSym : array of string; // setLength ����� �� ��� �迭 ���
LC:integer; // Break�� ���� Loop Count
extA : extended;
accResult:Float64; // ���� �����

begin
LC:=0;
SetLength(tmpOpd, Length(_Opds_Arr));
SetLength(tmpSym, Length(_Symbols));
for I := 0 to Length(_symbols)-1 do
begin
tmpOpd[I] := _opds_Arr[I];
tmpSym[I] := _symbols[I];
//ShowMessage('sym:'+tmpSym[I]);
//ShowMessage('opd:'+ FloatToStr(tmpopd[I]));

end;
tmpOpd[Length(_Opds_ARr)-1] := _Opds_ARr[Length(_Opds_ARr)-1];
//ShowMessage('opd:'+ FloatToStr(tmpopd[Length(_Opds_ARr)-1]));

I:=0;


// �� �Է� �� ������ �������� ���� ����,
while Length(tmpOpd) > 1 do
begin
LC:=LC+1;
if tmpSym[I] = '*' then
begin
tmpOpd[I]:=Multi(tmpOpd[I],tmpOpd[I+1]);

for J := I to Length(tmpSym)-2 do
begin
tmpOpd[J+1] := tmpOpd[J+2];
tmpSym[J] := tmpSym[J+1];
end;

SetLength(tmpSym, Length(tmpSym)-1);
SetLength(tmpOpd, Length(tmpOpd)-1);

//accResult:=tmpOpd[I];
I:=0;
end
else
begin
if tmpSym[I] = '/' then
begin

extA:=Divide(tmpOpd[I],tmpOpd[I+1]);
tmpOpd[I] := extA;
for J := I to Length(tmpSym)-2 do
begin
tmpOpd[J+1] := tmpOpd[J+2];
tmpSym[J] := tmpSym[J+1];
end;

SetLength(tmpSym, Length(tmpSym)-1);
SetLength(tmpOpd, Length(tmpOpd)-1);

//accResult:=tmpOpd[I];
I:=0;

end
else
I:=I+1;
end;
if LC > Length(tmpOpd) then
break;
end;
// �� �Է� �� ������ �������� ���� ����

for K := 0 to Length(tmpSym)-1 do
begin

if tmpSym[K] = '+' then
begin
tmpOpd[K+1]:=Add(tmpOpd[K],tmpOpd[K+1]);
end
else
begin
if tmpSym[K] = '-' then
tmpOpd[K+1]:=Sub(tmpOpd[K],tmpOpd[K+1]);
end;
end;

accResult:=tmpOpd[length(tmpOpd)-1];
//ShowMessage(FloatToStr(accResult));
Result:=FloatToStr(accResult);
end;

constructor TCalc.create;
begin

end;

end.
Loading