16.05.2013, 09:49 | #1 (ссылка) |
Новичок
Регистрация: 16.05.2013
Сообщений: 9
Репутация: 0
|
Кракозябры вместо строк в ТП7
Модуль:
Код:
unit lab3unit; interface type TKomp_chis=object z:string[10]; procedure vvod(var Zdeis, Zmnim: integer); function slojenie(a1, b1, a2, b2:integer):string; function vichitanie(a1, b1, a2, b2:integer):string; function umnojenie(a1, b1, a2, b2:integer):string; function delenie(a1, b1, a2, b2:integer):string; end; var deis, mnim: string[3]; code: integer; implementation procedure Tkomp_chis.vvod(var Zdeis, Zmnim: integer); var i, j: byte; a, b: string[3]; znak: char; begin write ('Vvedite kompleksnoe chislo: '); readln (z); i:=0; j:=0; while i<length(z) do begin i:=i+1; if ((ord(z[i])>=48) and (ord(z[i])<=57)) then a[i]:=z[i] else if ((z[i]='+') or (z[i]='-')) then znak:=z[i] else if z[i]='i' then while i<length(z) do begin i:=i+1; j:=j+1; b[j]:=z[i]; end; end; val(a,Zdeis,code); if znak='+' then val(b,Zmnim,code) else begin val(b,Zmnim,code); Zmnim:=-Zmnim; end; end; function Tkomp_chis.slojenie(a1, b1, a2, b2:integer):string; var a, b: string[3]; c:string[10]; begin str(a1+a2,a); str(b1+b2,b); if b1+b2<>0 then begin if b1+b2>0 then insert('+',b,1); insert('i',b,2); end; slojenie:=concat(a,b); end; function Tkomp_chis.vichitanie(a1, b1, a2, b2:integer):string; var a, b: string[3]; c:string[10]; begin str(a1-a2,a); str(b1-b2,b); if b1-b2<>0 then begin if b1-b2>0 then insert('+',b,1); insert('i',b,2); end; vichitanie:=concat(a,b); end; function Tkomp_chis.umnojenie(a1, b1, a2, b2:integer):string; var a, b: string[3]; c:string[10]; begin str((a1*a2)-(b1*b2),a); str((a1*b2)+(b1*a2),b); if (b1*a2)+(b2*a1)<>0 then begin if (a1*b2)+(b1*a2)>0 then insert('+',b,1); insert('i',b,2); end; umnojenie:=concat(a,b); end; function Tkomp_chis.delenie (a1, b1, a2, b2:integer):string; var chisA, chisB, znam: integer; a, b: string[3]; c:string[10]; begin if ((a2<>0) and (b2<>0)) then begin chisA:=(a1*a2)-(b1*(-b2)); chisB:=(a1*(-b2))+(b1*a2); znam:=sqr(a1)+sqr(b1); if chisA mod znam=0 then str(chisA/znam,a) else begin str(chisA,a); insert('/',a,length(a)); str(znam,c); insert(c,a,length(a)); end; if chisB mod znam=0 then str(chisB/znam,b) else begin str(chisB,b); insert('/',b,length(b)); str(znam,c); insert(c,b,length(b)); end; if (chisB)<>0 then begin if (chisB/znam)>0 then insert('+',b,1); insert('i',b,2); end; delenie:=concat(a,b); end; else write('Delit na 0 nelzya!'); end; begin end. Код:
program lab3; uses crt, lab3unit; var zdeis1, zmnim1, zdeis2, zmnim2: integer; znak: string[5]; otvet: string[10]; Komp_chis: TKomp_chis; begin clrscr; write ('Vvedite deistvie v vide "z1?z2": '); readln (znak); with Komp_chis do begin vvod(zdeis1,zmnim1); vvod(zdeis2,zmnim2); case znak[3] of '+': otvet:=slojenie(zdeis1, zmnim1, zdeis2, zmnim2); '-': otvet:=vichitanie(zdeis1, zmnim1, zdeis2, zmnim2); '*': otvet:=umnojenie(zdeis1, zmnim1, zdeis2, zmnim2); '/': otvet:=delenie(zdeis1, zmnim1, zdeis2, zmnim2); end; end; write ('Otvet - ',otvet); readln; end. Вот скрин: |
17.05.2013, 19:37 | #4 (ссылка) |
Стажёр
Регистрация: 04.01.2013
Сообщений: 490
Репутация: 57
|
Согласен причина не в этом - при попытке проверить правильность работы программы не выводится ответ.
Выводится: Otvet - Попробую завести код в delphi ---------- Добавлено в 19:37 ---------- Предыдущее сообщение было написано в 19:18 ---------- В delphi оказалось что в процедуре procedure Tkomp_chis.vvod(var Zdeis, Zmnim: integer); в цикле while i<length(z) do begin i:=i+1; if ((ord(z[i])>=48) and (ord(z[i])<=57)) then a[i]:=z[i] else if ((z[i]='+') or (z[i]='-')) then znak:=z[i] else if z[i]='i' then while i<length(z) do begin i:=i+1; j:=j+1; b[j]:=z[i]; end; end; переменная a не получает никаких данных от переменной z те же проблемы с переменной b посмотрю что можно сделать |
17.05.2013, 20:00 | #5 (ссылка) | |
Новичок
Регистрация: 16.05.2013
Сообщений: 9
Репутация: 0
|
Цитата:
Пы.Сы. Удивлён что кто-то ещё заходит в эту тему)) Благодарю за попытки помочь) |
|
17.05.2013, 20:07 | #6 (ссылка) |
Стажёр
Регистрация: 04.01.2013
Сообщений: 490
Репутация: 57
|
Попробовал переделать программу. Вариант рабочий, не знаю подойдет или нет
Код:
unit lab3unit; interface type TKomp_chis=object procedure vvod(var Zdeis, Zmnim: real); function slojenie(a1, b1, a2, b2:real):string; function vichitanie(a1, b1, a2, b2:real):string; function umnojenie(a1, b1, a2, b2:real):string; function delenie(a1, b1, a2, b2:real):string; end; var deis, mnim: real; code: integer; implementation procedure Tkomp_chis.vvod(var Zdeis, Zmnim: real); begin writeln('Vvedite dejstvitelnuju i mnimuju chasti kompleksnogo chisla (cherez probel)'); readln(Zdeis, Zmnim); end; function Tkomp_chis.slojenie(a1, b1, a2, b2:real):string; var c1,c2:string; begin a1:=a1+a2; b1:=b1+b2; if (a1=0) and (b1=0) then slojenie:='0'; if (a1<>0) and (b1=0) then begin str(a1:5:3, c1); slojenie:=c1; end; if (a1=0) and (b1<>0) then begin str(b1:5:3, c1); slojenie:=c1+'i'; end; if (a1<>0) and (b1<>0) then begin str(a1:5:3, c1); str(b1:5:3, c2); slojenie:=c1+' '+c2+'i'; end; end; function Tkomp_chis.vichitanie(a1, b1, a2, b2:real):string; var c1,c2:string; begin a1:=a1-a2; b1:=b1-b2; if (a1=0) and (b1=0) then vichitanie:='0'; if (a1<>0) and (b1=0) then begin str(a1:5:3, c1); vichitanie:=c1; end; if (a1=0) and (b1<>0) then begin str(b1:5:3, c1); vichitanie:=c1+'i'; end; if (a1<>0) and (b1<>0) then begin str(a1:5:3, c1); str(b1:5:3, c2); vichitanie:=c1+' '+c2+'i'; end; end; function Tkomp_chis.umnojenie(a1, b1, a2, b2:real):string; var c1,c2:string; begin a1:=a1*a2; b1:=b1*b2; if (a1=0) and (b1=0) then umnojenie:='0'; if (a1<>0) and (b1=0) then begin str(a1:5:3, c1); umnojenie:=c1; end; if (a1=0) and (b1<>0) then begin str(b1:5:3, c1); umnojenie:=c1+'i'; end; if (a1<>0) and (b1<>0) then begin str(a1:5:3, c1); str(b1:5:3, c2); umnojenie:=c1+' '+c2+'i'; end; end; function Tkomp_chis.delenie (a1, b1, a2, b2:real):string; var c1,c2:string; begin if (a2<>0) and (b2<>0) then begin a1:=a1*a2; b1:=b1*b2; if (a1=0) and (b1=0) then delenie:='0'; if (a1<>0) and (b1=0) then begin str(a1:5:3, c1); delenie:=c1; end; if (a1=0) and (b1<>0) then begin str(b1:5:3, c1); delenie:=c1+'i'; end; if (a1<>0) and (b1<>0) then begin str(a1:5:3, c1); str(b1:5:3, c2); delenie:=c1+' '+c2+'i'; end; end; end; begin end. Код:
program lab3; uses crt, lab3unit; var zdeis1, zmnim1, zdeis2, zmnim2: real; znak: string[5]; otvet: string; Komp_chis: TKomp_chis; begin write ('Vvedite deistvie v vide "z1?z2": '); readln (znak); with Komp_chis do begin vvod(zdeis1,zmnim1); vvod(zdeis2,zmnim2); case znak[3] of '+': otvet:=slojenie(zdeis1, zmnim1, zdeis2, zmnim2); '-': otvet:=vichitanie(zdeis1, zmnim1, zdeis2, zmnim2); '*': otvet:=umnojenie(zdeis1, zmnim1, zdeis2, zmnim2); '/': otvet:=delenie(zdeis1, zmnim1, zdeis2, zmnim2); end; end; writeln('Otvet:'); writeln(otvet); readln; end. Последний раз редактировалось Serega_490101; 17.05.2013 в 20:26. |
17.05.2013, 22:45 | #7 (ссылка) |
Новичок
Регистрация: 16.05.2013
Сообщений: 9
Репутация: 0
|
Ну, что я могу сказать, спасибо за старания) Но всё же я пытаюсь всё делать сам, ибо это всё-таки мне надо) И всё же хочется разобраться от чего проблема. У тебя кстати есть пару изъянов в модуле:
1) Ввод чисел странный (но сравнительно приемлимый). 2) Все числа лучше делать целыми, ибо пока что не видел использования десятичных дробей среди комплексных чисел. 3) Ты не учёл, что если мнимая часть будет положительной, то при создании строки плюса не будет, а будут цифры подряд. 4) Деление в твоей программе почти идентично умножению) Но всё же, спасибо за помощь, некоторые твои строчки возьму себе на заметку) |
19.05.2013, 01:10 | #8 (ссылка) |
Стажёр
|
Mizantrop, немного переписал твой код,проверил только сложение и вычитание,дальше смотри сам если что не так.
Код:
program project0001; uses crt,lab3unit; var zdeis1, zmnim1, zdeis2, zmnim2: integer; znak: char; otvet: string[10]; Komp_chis: TKomp_chis; begin write ('Vvedite deistvie v vide "z1?z2": '); readln (znak); with Komp_chis do begin vvod(zdeis1,zmnim1); vvod(zdeis2,zmnim2); case znak of '+': otvet:=slojenie(zdeis1, zmnim1, zdeis2, zmnim2); '-': otvet:=vichitanie(zdeis1, zmnim1, zdeis2, zmnim2); '*': otvet:=umnojenie(zdeis1, zmnim1, zdeis2, zmnim2); '/': otvet:=delenie(zdeis1, zmnim1, zdeis2, zmnim2); end; end; write ('Otvet - ',otvet); readln; end. Код:
unit lab3unit; interface type TKomp_chis=object z:string[10]; procedure vvod(var Zdeis, Zmnim: integer); function slojenie(a1, b1, a2, b2:integer):string; function vichitanie(a1, b1, a2, b2:integer):string; function umnojenie(a1, b1, a2, b2:integer):string; function delenie(a1, b1, a2, b2:integer):string; end; var deis, mnim: string[3]; code: integer; implementation procedure Tkomp_chis.vvod(var Zdeis, Zmnim: integer); var fl:boolean; i, j: byte; a, b: string[3]; znak: char; begin write ('Vvedite kompleksnoe chislo: '); readln (z); fl:=true; i:=0; j:=0; a:=''; b:=''; while i<length(z) do begin inc(i); if fl and (z[i] in ['0'..'9']) then a:=a+z[i] else if ((z[i]='+') or (z[i]='-')) then begin znak:=z[i]; fl:=false; end else if z[i] in ['0'..'9'] then b:=b+z[i]; end; val(a,Zdeis,code); if znak='+' then val(b,Zmnim,code) else begin val(b,Zmnim,code); Zmnim:=-Zmnim; end; end; function Tkomp_chis.slojenie(a1, b1, a2, b2:integer):string; var a, b: string[3]; c:string[10]; begin str(a1+a2,a); str(b1+b2,b); if b1+b2<>0 then begin if b1+b2>0 then insert('+',b,1); insert('i',b,2); end; slojenie:=concat(a,b); end; function Tkomp_chis.vichitanie(a1, b1, a2, b2:integer):string; var a, b: string[3]; c:string[10]; begin str(a1-a2,a); str(b1-b2,b); if b1-b2<>0 then begin if b1-b2>0 then insert('+',b,1); insert('i',b,2); end; vichitanie:=concat(a,b); end; function Tkomp_chis.umnojenie(a1, b1, a2, b2:integer):string; var a, b: string[3]; c:string[10]; begin str((a1*a2)-(b1*b2),a); str((a1*b2)+(b1*a2),b); if (b1*a2)+(b2*a1)<>0 then begin if (a1*b2)+(b1*a2)>0 then insert('+',b,1); insert('i',b,2); end; umnojenie:=concat(a,b); end; function Tkomp_chis.delenie (a1, b1, a2, b2:integer):string; var chisA, chisB, znam: integer; a, b: string[3]; c:string[10]; begin if ((a2<>0) and (b2<>0)) then begin chisA:=(a1*a2)-(b1*(-b2)); chisB:=(a1*(-b2))+(b1*a2); znam:=sqr(a1)+sqr(b1); if chisA mod znam=0 then str(chisA/znam,a) else begin str(chisA,a); insert('/',a,length(a)); str(znam,c); insert(c,a,length(a)); end; if chisB mod znam=0 then str(chisB/znam,b) else begin str(chisB,b); insert('/',b,length(b)); str(znam,c); insert(c,b,length(b)); end; if (chisB)<>0 then begin if (chisB/znam)>0 then insert('+',b,1); insert('i',b,2); end; delenie:=concat(a,b); end else write('Delit na 0 nelzya!'); end; end. |
Ads | |
Здесь присутствуют: 1 (пользователей: 0 , гостей: 1) | |
|
|
Похожие темы | ||||
Тема | Автор | Раздел | Ответов | Последнее сообщение |
Кракозябры вместо русских букв | michal | MacOS | 2 | 10.04.2013 15:33 |
Кракозябры на флешке | denismm-105 | Периферия | 3 | 16.03.2013 15:22 |
На LETITBIT отображаются кракозябры.. | rkol | Интернет и сети | 1 | 24.03.2010 01:11 |
кракозябры в фотошопе. | lego601 | Графика | 1 | 08.12.2009 21:04 |
photoshop 5 кракозябры | lego601 | Графика | 3 | 28.10.2009 23:40 |