|
|
Регистрация Восстановить пароль |
Повторная активизация e-mail |
Регистрация | Задать вопрос |
Заплачу за решение |
Новые сообщения |
Сообщения за день |
Расширенный поиск |
Правила |
Всё прочитано |
|
|
Опции темы | Поиск в этой теме |
23.06.2009, 15:41 | #1 |
Пользователь
Регистрация: 23.06.2009
Сообщений: 12
|
Методы-в класс
У меня есть текст программы.
Она полностью правильная. В ней есть две функции и процедура. Их надо выделить в отдельный модуль, в класс. Также есть модуль, 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[i] 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[i] 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[i] <> '(') then writeLn('error: Invalid expression format') else begin j := 1; while ((i <= length(e)) and (j > 0)) do begin inc(i); if (e[i] = ')') then dec(j) else if (e[i] = '(') 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. |
23.06.2009, 16:02 | #2 |
Белик Виталий :)
Старожил
Регистрация: 23.07.2007
Сообщений: 57,097
|
Ну в целом выглядеть это должно примерно так:
Код:
I'm learning to live...
|
23.06.2009, 16:25 | #3 |
Пользователь
Регистрация: 23.06.2009
Сообщений: 12
|
а функция BuildElement??
сейчас выложу модуль,может яснее станет) Кстати прога работает нормально |
23.06.2009, 16:25 | #4 |
Пользователь
Регистрация: 23.06.2009
Сообщений: 12
|
кстати,и как потом вызывать эти методы в основной проге
|
23.06.2009, 16:27 | #5 |
Пользователь
Регистрация: 23.06.2009
Сообщений: 12
|
unit el_func;
interface const OUT_WIDTH = 0; OUT_DECIMALS = 2; type TCalcResult = (crOk, crFail); TOperation = (oNULL, oOnlyFirst, oOnlySecond, oAdd, oSub, oMul, oDiv, oPow, oLog, oF1ofF2); PString =^string; PBaseFunction =^TBaseFunction; TBaseFunction = object private Name : PString; public constructor Create(s : string); destructor Destroy; function Calculate(x : real; var r : real) : TCalcResult; virtual; procedure OutputFLine(level : integer); virtual; end; PElementaryFunction =^TElementaryFunction; TElementaryFunction = object (TBaseFunction) private Param : real; public constructor Create(s : string; p : real); function GetParam : real; procedure SetParam(p : real); function Calculate(x : real; var r : real) : TCalcResult; virtual; procedure OutputFLine(level : integer); virtual; end; PFunction =^TFunction; TFunction = object (TElementaryFunction) private Operation : TOperation; First, Second : PElementaryFunction; public constructor Create(func1, func2 : PElementaryFunction; op : TOperation); destructor Destroy; procedure SetParam(p : real); function SetOperation(op : TOperation) : TOperation; function Calculate(x : real; var r : real) : TCalcResult; virtual; procedure OutputFLine(level : integer); virtual; end; { -= Elementary functions =- } PFConst =^TFConst; TFConst = object (TElementaryFunction) public constructor Create(p : real); function Calculate(x : real; var r : real) : TCalcResult; virtual; procedure OutputFLine(level : integer); virtual; end; PFEquivalence =^TFEquivalence; TFEquivalence = object (TElementaryFunction) public constructor Create; function Calculate(x : real; var r : real) : TCalcResult; virtual; procedure OutputFLine(level : integer); virtual; end; PFSin =^TFSin; TFSin = object (TElementaryFunction) public constructor Create; function Calculate(x : real; var r : real) : TCalcResult; virtual; procedure OutputFLine(level : integer); virtual; end; PFCos =^TFCos; TFCos = object (TElementaryFunction) public constructor Create; function Calculate(x : real; var r : real) : TCalcResult; virtual; procedure OutputFLine(level : integer); virtual; end; PFTg =^TFTg; TFTg = object (TElementaryFunction) public constructor Create; function Calculate(x : real; var r : real) : TCalcResult; virtual; procedure OutputFLine(level : integer); virtual; end; PFCtg =^TFCtg; TFCtg = object (TElementaryFunction) public constructor Create; function Calculate(x : real; var r : real) : TCalcResult; virtual; procedure OutputFLine(level : integer); virtual; end; PFArcSin =^TFArcSin; TFArcSin = object (TElementaryFunction) public constructor Create; function Calculate(x : real; var r : real) : TCalcResult; virtual; procedure OutputFLine(level : integer); virtual; end; PFArcCos =^TFArcCos; TFArcCos = object (TElementaryFunction) public constructor Create; function Calculate(x : real; var r : real) : TCalcResult; virtual; procedure OutputFLine(level : integer); virtual; end; PFArcTg =^TFArcTg; TFArcTg = object (TElementaryFunction) public constructor Create; function Calculate(x : real; var r : real) : TCalcResult; virtual; procedure OutputFLine(level : integer); virtual; end; PFArcCtg =^TFArcCtg; TFArcCtg = object (TElementaryFunction) public constructor Create; function Calculate(x : real; var r : real) : TCalcResult; virtual; procedure OutputFLine(level : integer); virtual; end; function CreateFunction(func1, func2 : PElementaryFunction; op : TOperation) : PFunction; function CreateFConst(c : real) : PElementaryFunction; function CreateFEquivalence : PElementaryFunction; function CreateFSin : PElementaryFunction; function CreateFCos : PElementaryFunction; function CreateFTg : PElementaryFunction; function CreateFCtg : PElementaryFunction; function CreateFArcSin : PElementaryFunction; function CreateFArcCos : PElementaryFunction; function CreateFArcTg : PElementaryFunction; function CreateFArcCtg : PElementaryFunction; implementation |
23.06.2009, 16:27 | #6 |
Пользователь
Регистрация: 23.06.2009
Сообщений: 12
|
это без раздела реализации(описания этих методов),так как слишком много)
|
23.06.2009, 16:32 | #7 | |
Белик Виталий :)
Старожил
Регистрация: 23.07.2007
Сообщений: 57,097
|
Цитата:
переменка.OutputTree(чето там...)
I'm learning to live...
|
|
23.06.2009, 16:40 | #8 |
Пользователь
Регистрация: 23.06.2009
Сообщений: 12
|
посмотри на мой модуль тоже.
а этот класс не должен иметь родителя? |
23.06.2009, 16:44 | #9 |
Белик Виталий :)
Старожил
Регистрация: 23.07.2007
Сообщений: 57,097
|
Во-первых: Я не пойму зачем тебе функции Create...?
Ведь если ты обернул некоторые функции в обьект, то "создавать" их проще просто создав их обьект. Во-вторых: Соответственно зачем тебе указатели на эти обьекты?
I'm learning to live...
|
23.06.2009, 16:50 | #10 |
Пользователь
Регистрация: 23.06.2009
Сообщений: 12
|
мне не за чеМ))
а преподу зачем то надо)) это все им уже просмотрено и исправлено. Он только сказал сделать то что я написал в первом сообщении |
|
Похожие темы | ||||
Тема | Автор | Раздел | Ответов | Последнее сообщение |
численные методы | Desha | Помощь студентам | 2 | 24.05.2009 12:46 |
Численные методы | improvement | Общие вопросы .NET | 4 | 08.05.2009 01:58 |
методы в ООП | albatros | Общие вопросы Delphi | 3 | 04.02.2009 22:59 |
Методы... | Arkuz | Свободное общение | 6 | 11.10.2008 16:53 |
Методы шифрования | D@rk M@k | Свободное общение | 3 | 27.02.2008 13:56 |