методы-в класс

Ответить
xMoNaHx
Сообщения: 1
Зарегистрирован: 23 июн 2009, 15:52

У меня есть текст программы.
Она полностью правильная.
В ней есть две функции и процедура.

Их надо выделить в отдельный модуль, в класс.
Также есть модуль, el_func.
Если надо могу выложить.
Если можете сделайте пожалуйста этот класс))
Просто надо завтра с утра сдавать курсовую.Осталось только овт это исправить.

Вот прога:

program parse_expr;
uses el_func;
function BuildTree(var e : string) : PElementaryFunction; forward;
function BuildElement(var e : string) : PElementaryFunction;
var
lp, fname : string(255);
i, j : integer;
r : real;
begin
writeLn('Enter to BuildElement(''' + e + ''')!');
i := 1;

BuildElement := nil;
while ((i <= length(e)) and (e in ['0'..'9', '.'])) do
inc(i);
if (i > 1) then
begin
lp := copy(e, 1, i - 1);
delete(e, 1, i - 1);
val(lp, r, i);
writeLn('Number: ', r:0:2);
if (i <> 0) then
writeLn('error: Invalid number format')
else
BuildElement := CreateFConst(r);
exit;
end;
fname := '';
while ((i <= length(e)) and (e in ['a'..'z', 'A'..'Z'])) do
inc(i);
if (i > 1) then
begin
fname := copy(e, 1, i - 1);
delete(e, 1, i - 1);
if (fname = 'x') then
begin
writeLn('Variable: ' + fname);
BuildElement := CreateFEquivalence;
exit;
end;
i := 1;
writeLn('Function: ' + fname);
end;
if (e <> '(') then
writeLn('error: Invalid expression format')
else
begin
j := 1;
while ((i <= length(e)) and (j > 0)) do
begin
inc(i);
if (e = ')') then
dec(j)
else if (e = '(') then
inc(j);
end;
if (j > 0) then
begin
writeLn('error: ''('' without '')''');
exit;
end;
lp := copy(e, 2, i - 2);
delete(e, 1, i);
writeLn('Expression: ' + lp);
end;
if (fname = '') then
BuildElement := BuildTree(lp)
else if (fname = 'sin') then
BuildElement := CreateFunction(CreateFSin, BuildTree(lp), oF1ofF2)
else if (fname = 'cos') then
BuildElement := CreateFunction(CreateFCos, BuildTree(lp), oF1ofF2)
else if (fname = 'tg') then
BuildElement := CreateFunction(CreateFTg, BuildTree(lp), oF1ofF2)
else if (fname = 'ctg') then
BuildElement := CreateFunction(CreateFCtg, BuildTree(lp), oF1ofF2)
else if (fname = 'arcsin') then
BuildElement := CreateFunction(CreateFArcSin, BuildTree(lp), oF1ofF2)
else if (fname = 'arccos') then
BuildElement := CreateFunction(CreateFArcCos, BuildTree(lp), oF1ofF2)
else if (fname = 'arctg') then
BuildElement := CreateFunction(CreateFArcTg, BuildTree(lp), oF1ofF2)
else if (fname = 'arcctg') then
BuildElement := CreateFunction(CreateFArcCtg, BuildTree(lp), oF1ofF2)
end;

function BuildTree(var e : string) : PElementaryFunction;
var
lf : PElementaryFunction;
begin
writeLn('Enter to BuildTree(''' + e + ''')!');
BuildTree := nil;
lf := BuildElement(e);
while (length(e) > 0) do
if (e[1] = '*') then
begin
writeLn('*');
delete(e, 1, 1);
lf := CreateFunction(lf, BuildElement(e), oMul);
writeLn('buildtree: e = ' + e);
end else if (e[1] = '/') then
begin
writeLn('/');
delete(e, 1, 1);
lf := CreateFunction(lf, BuildElement(e), oDiv);
writeLn('buildtree: e = ' + e);
end else if (e[1] = '+') then
begin
writeLn('+');
delete(e, 1, 1);
lf := CreateFunction(lf, BuildTree(e), oAdd);
writeLn('buildtree: e = ' + e);
end else if (e[1] = '-') then
begin
writeLn('-');
delete(e, 1, 1);
lf := CreateFunction(lf, BuildTree(e), oSub);
writeLn('buildtree: e = ' + e);
end;
BuildTree := lf;
end;

procedure OutputTree(f : PElementaryFunction);
begin
writeLn('Tree:');
f^.OutputFLine(0);
end;

var
s, t : string(255);
tree : PElementaryFunction;

begin
write('Enter expression: ');
readLn(s);{}
t := s;
tree := BuildTree(t);
writeLn('s = ' + s);
if (tree <> nil) then
OutputTree(tree)
else
writeLn('Tree is null');
end.
Ответить