Модераторы: volvo877, Snowy, MetalFan
  

Поиск:

Ответ в темуСоздание новой темы Создание опроса
> Помогите перевести из Pascal в C, Учеба 
:(
    Опции темы
dimugan
Дата 31.5.2014, 20:24 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 1
Регистрация: 31.5.2014

Репутация: нет
Всего: нет



unit Unit1;

interface

uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs, StdCtrls, Menus, Mask;

const Digit: set of Char=['1'..'9', '0'];
//Множество символов, воспринимаемых как символ-разделитель:
 Separator: set of Char=['/', '.', ',', 'ю', 'Ю', 'б', 'Б'];
 firstdigit: set of char=['-','1'..'9', '0'];
type
 TForm1 = class(TForm)
 Edit1: TEdit;
 GroupBox1: TGroupBox;
 MainMenu1: TMainMenu;
 MenuClear: TMenuItem;
 MenuExit: TMenuItem;
 Label1: TLabel;
 Edit2: TEdit;
 Label5: TLabel;
 Edit9: TEdit;
 Edit3: TEdit;
 Edit4: TEdit;
 GroupBox3: TGroupBox;
 Label2: TLabel;
 Edit5: TEdit;
 Edit6: TEdit;
 Edit7: TEdit;
 Edit8: TEdit;
 Label3: TLabel;
 Edit10: TEdit;
 Label8: TLabel;
 Edit11: TEdit;
 Label6: TLabel;
 Edit12: TEdit;
 Button1: TButton;
 Label4: TLabel;
 MenuSave: TMenuItem;
 procedure Button1Click(Sender: TObject);
 procedure MenuExitClick(Sender: TObject);
 procedure Edit1KeyPress(Sender: TObject; var Key: Char);
 procedure Edit2KeyPress(Sender: TObject; var Key: Char);
 procedure Edit3KeyPress(Sender: TObject; var Key: Char);
 procedure Edit4KeyPress(Sender: TObject; var Key: Char);
 procedure Edit5KeyPress(Sender: TObject; var Key: Char);
 procedure Edit6KeyPress(Sender: TObject; var Key: Char);
 procedure Edit7KeyPress(Sender: TObject; var Key: Char);
 procedure Edit8KeyPress(Sender: TObject; var Key: Char);
 procedure MenuClearClick(Sender: TObject);
 procedure MenuSaveClick(Sender: TObject);
 private
 { Private declarations }

 public
 { Public declarations }
 end;

 TComplex=record
 Real: Extended;//Вещественная часть комплексного числа
 Imag: Extended;//Мнимая часть комплексного числа
 Modul: Extended;//модуль комплексного числа
 Angle: Extended;//угол поворота
 end;

var
 Form1: TForm1;
 Z1,Z2: TComplex;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var Modul,Angle:extended;
begin
 if Edit1.Text<>'' then Z1.Real:=StrToFloat(Edit1.Text);
 if Edit2.Text<>'' then Z1.Imag:=StrToFloat(Edit2.Text);
 if Edit3.Text<>'' then Z1.Modul:=StrToFloat(Edit3.Text);
 if Edit4.Text<>'' then Z1.Angle:=StrToFloat(Edit4.Text);
 if Edit5.Text<>'' then Z2.Real:=StrToFloat(Edit5.Text);
 if Edit6.Text<>'' then Z2.Imag:=StrToFloat(Edit6.Text);
 if Edit7.Text<>'' then Z2.Modul:=StrToFloat(Edit7.Text);
 if Edit8.Text<>'' then Z2.Angle:=StrToFloat(Edit8.Text);
 if (Edit1.Text<>'') and (Edit2.Text<>'') then
 begin
 Z1.Modul:=SQRT(SQR(Z1.Real)+SQR(Z1.Imag));
 if Z1.Real=0 then Z1.Angle:=1.57
 else if(Z1.Real>0) then Z1.Angle:=arctan(Z1.Imag/Z1.Real)
 else Z1.Angle:=3.14+arctan(Z1.Imag/Z1.Real);
 Edit3.Text:=floatToStrF(Z1.Modul,ffFixed,6,1);
 Edit4.Text:=floatToStrF(Z1.Angle,ffFixed,6,1);
 end;
 if (Edit3.Text<>'') and (Edit4.Text<>'') then
 begin
 Z1.Real:=Z1.Modul*cos(Z1.Angle);
 Z1.Imag:=Z1.Modul*sin(Z1.Angle);
 Edit1.Text:=floatToStrF(Z1.Real,ffFixed,6,1);
 Edit2.Text:=floatToStrF(Z1.Imag,ffFixed,6,1);
 end;

 if (Edit5.Text<>'') and (Edit6.Text<>'') then
 begin
 Z2.Modul:=SQRT(SQR(Z2.Real)+SQR(Z2.Imag));
 if Z2.Real=0 then Z2.Angle:=1.57
 else if (Z2.Real>0) then Z2.Angle:=arctan(Z2.Imag/Z2.Real)
 else Z2.Angle:=3.14+arctan(Z2.Imag/Z2.Real);
 Edit7.Text:=floatToStrF(Z2.Modul,ffFixed,6,1);
 Edit8.Text:=floatToStrF(Z2.Angle,ffFixed,6,1);
 end;

 if (Edit7.Text<>'') and (Edit8.Text<>'') then
 begin
 Z2.Real:=Z2.Modul*cos(Z2.Angle);
 Z2.Imag:=Z2.Modul*sin(Z2.Angle);
 Edit5.Text:=floatToStrF(Z2.Real,ffFixed,6,1);
 Edit6.Text:=floatToStrF(Z2.Imag,ffFixed,6,1);
 end;

 {Z1+Z2}

 If Z1.Imag>=0 then Edit9.Text:=floatToStrF(Z1.Real,ffFixed,6,1)+'+j'+floatToStrF(Z1.Imag,ffFixed,6,1)
 else Edit9.Text:=floatToStrF(Z1.Real,ffFixed,6,1)+'-j'+floatToStrF(-Z1.Imag,ffFixed,6,1);
 If Z2.Real>=0 then Edit9.Text:=Edit9.Text+'+'+floatToStrF(Z2.Real,ffFixed,6,1)
 else Edit9.Text:=Edit9.Text+floatToStrF(Z2.Real,ffFixed,6,1);
 If Z2.Imag>=0 then Edit9.Text:=Edit9.Text+'+j'+floatToStrF(Z2.Imag,ffFixed,6,1)
 else Edit9.Text:=Edit9.Text+'-j'+floatToStrF(-Z2.Imag,ffFixed,6,1);
 Edit9.Text:=Edit9.Text+'='+floatToStrF(Z1.Real+Z2.Real,ffFixed,6,1);
 If (Z1.Imag+Z2.Imag)>=0 then Edit9.Text:=Edit9.Text+'+j'+floatToStrF(Z1.Imag+Z2.Imag,ffFixed,6,1)
 else Edit9.Text:=Edit9.Text+'-j'+floatToStrF(-(Z1.Imag+Z2.Imag),ffFixed,6,1);
 modul:=SQRT(SQR(Z1.Real+Z2.Real)+SQR(Z1.Imag+Z2.Imag));
 if (Z1.Real+Z2.Real)=0 then Angle:=1.57
 else if (Z1.Real+Z2.Real)>0 then Angle:=arctan((Z1.Imag+Z2.Imag)/(Z1.Real+Z2.Real))
 else Angle:=3.14+arctan((Z1.Imag+Z2.Imag)/(Z1.Real+Z2.Real));
Edit9.Text:=Edit9.Text+'='+floatToStrF(modul,ffFixed,6,1)+'exp('+floatToStrF(Angle,ffFixed,6,1)+'j)';
 {Z1-Z2}
If Z1.Imag>=0 then Edit10.Text:=floatToStrF(Z1.Real,ffFixed,6,1)+'+j'+floatToStrF(Z1.Imag,ffFixed,6,1)
 else Edit10.Text:=floatToStrF(Z1.Real,ffFixed,6,1)+'-j'+floatToStrF(-Z1.Imag,ffFixed,6,1);
 If (-Z2.Real)>=0 then Edit10.Text:=Edit10.Text+'+'+floatToStrF(-Z2.Real,ffFixed,6,1)
 else Edit10.Text:=Edit10.Text+floatToStrF(-Z2.Real,ffFixed,6,1);
 If (-Z2.Imag)>=0 then Edit10.Text:=Edit10.Text+'+j'+floatToStrF(-Z2.Imag,ffFixed,6,1)
 else Edit10.Text:=Edit10.Text+'-j'+floatToStrF(Z2.Imag,ffFixed,6,1);
 Edit10.Text:=Edit10.Text+'='+floatToStrF(Z1.Real-Z2.Real,ffFixed,6,1);
 If (Z1.Imag-Z2.Imag)>=0 then Edit10.Text:=Edit10.Text+'+j'+floatToStrF(Z1.Imag-Z2.Imag,ffFixed,6,1)
 else Edit10.Text:=Edit10.Text+'-j'+floatToStrF(-(Z1.Imag-Z2.Imag),ffFixed,6,1);
 modul:=SQRT(SQR(Z1.Real-Z2.Real)+SQR(Z1.Imag-Z2.Imag));
 if (Z1.Real-Z2.Real)=0 then Angle:=1.57
 else if (Z1.Real-Z2.Real)>0 then Angle:=arctan((Z1.Imag-Z2.Imag)/(Z1.Real-Z2.Real))
 else Angle:=3.14+arctan((Z1.Imag-Z2.Imag)/(Z1.Real-Z2.Real));
 Edit10.Text:=Edit10.Text+'='+floatToStrF(modul,ffFixed,6,1)+'exp('+floatToStrF(Angle,ffFixed,6,1)+'j)';

{Z1*Z2}
Edit11.Text:=floatToStrF(Z1.Modul,ffFixed,6,1)+'exp('+floatToStrF(Z1.Angle,ffFixed,6,1)+
'j)*'+floatToStrF(Z2.Modul,ffFixed,6,1)+'exp('+floatToStrF(Z2.Angle,ffFixed,6,1)+'j)='+
 floatToStrF(Z1.Modul*Z2.Modul,ffFixed,6,1)+'exp('+floatToStrF(Z1.Angle+Z2.Angle,ffFixed,6,1)+'j)='+
 floatToStrF(Z1.Modul*Z2.Modul*cos(Z1.Angle+Z2.Angle),ffFixed,6,1);
 if sin(Z1.Angle+Z2.Angle)>=0 then Edit11.Text:=Edit11.Text+'+j'+floatToStrF(Z1.Modul*Z2.Modul*sin(Z1.Angle+Z2.Angle),ffFixed,6,1)
 else Edit11.Text:=Edit11.Text+'-j'+floatToStrF(-Z1.Modul*Z2.Modul*sin(Z1.Angle+Z2.Angle),ffFixed,6,1);
{Z1/Z2}
Edit12.Text:=floatToStrF(Z1.Modul,ffFixed,6,1)+'exp('+floatToStrF(Z1.Angle,ffFixed,6,1)+
'j)/'+floatToStrF(Z2.Modul,ffFixed,6,1)+'exp('+floatToStrF(Z2.Angle,ffFixed,6,1)+'j)='+
floatToStrF(Z1.Modul/Z2.Modul,ffFixed,6,1)+'exp('+floatToStrF(Z1.Angle-Z2.Angle,ffFixed,6,1)+'j)='+
 floatToStrF(Z1.Modul/Z2.Modul*cos(Z1.Angle-Z2.Angle),ffFixed,6,1);
 if sin(Z1.Angle-Z2.Angle)>=0 then Edit12.Text:=Edit12.Text+'+j'+floatToStrF(Z1.Modul/Z2.Modul*sin(Z1.Angle-Z2.Angle),ffFixed,6,1)
 else Edit12.Text:=Edit12.Text+'-j'+floatToStrF(-Z1.Modul/Z2.Modul*sin(Z1.Angle-Z2.Angle),ffFixed,6,1);

end;

procedure TForm1.MenuExitClick(Sender: TObject);
begin
Form1.Close;
end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if (length(edit1.Text)=0) then
 if (key in firstdigit) then exit
 else key:=#0;
if (Key in Separator)
 then Key:=DecimalSeparator //Delphi-константа типа Char, равная символу-разделителю Windows
 else
 if (not(Key in Digit))
 then Key:=#0;
if ((Key=DecimalSeparator)and(pos(DecimalSeparator, Edit1.Text)<>0))
 then Key:=#0;
end;

procedure TForm1.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
if (length(edit12.Text)=0) then
 if (key in firstdigit) then exit
 else key:=#0;
if (Key in Separator)
 then Key:=DecimalSeparator //Delphi-константа типа Char, равная символу-разделителю Windows
 else
 if (not(Key in Digit))
 then Key:=#0;
if ((Key=DecimalSeparator)and(pos(DecimalSeparator, Edit1.Text)<>0))
 then Key:=#0;
end;

procedure TForm1.Edit3KeyPress(Sender: TObject; var Key: Char);
begin
if (Key in Separator)
 then Key:=DecimalSeparator //Delphi-константа типа Char, равная символу-разделителю Windows
 else
 if (not(Key in Digit))
 then Key:=#0;
if ((Key=DecimalSeparator)and(pos(DecimalSeparator, Edit1.Text)<>0))
 then Key:=#0;
end;

procedure TForm1.Edit4KeyPress(Sender: TObject; var Key: Char);
begin
if (length(edit4.Text)=0) then
 if (key in firstdigit) then exit
 else key:=#0;
if (Key in Separator)
 then Key:=DecimalSeparator //Delphi-константа типа Char, равная символу-разделителю Windows
 else
 if (not(Key in Digit))
 then Key:=#0;
if ((Key=DecimalSeparator)and(pos(DecimalSeparator, Edit1.Text)<>0))
 then Key:=#0;
end;

procedure TForm1.Edit5KeyPress(Sender: TObject; var Key: Char);
begin
if (length(edit5.Text)=0) then
 if (key in firstdigit) then exit
 else key:=#0;
if (Key in Separator)
 then Key:=DecimalSeparator //Delphi-константа типа Char, равная символу-разделителю Windows
 else
 if (not(Key in Digit))
 then Key:=#0;
if ((Key=DecimalSeparator)and(pos(DecimalSeparator, Edit1.Text)<>0))
 then Key:=#0;
end;

procedure TForm1.Edit6KeyPress(Sender: TObject; var Key: Char);
begin
if (length(edit6.Text)=0) then
 if (key in firstdigit) then exit
 else key:=#0;
if (Key in Separator)
 then Key:=DecimalSeparator //Delphi-константа типа Char, равная символу-разделителю Windows
 else
 if (not(Key in Digit))
 then Key:=#0;
if ((Key=DecimalSeparator)and(pos(DecimalSeparator, Edit1.Text)<>0))
 then Key:=#0;
end;

procedure TForm1.Edit7KeyPress(Sender: TObject; var Key: Char);
begin
if (Key in Separator)
 then Key:=DecimalSeparator //Delphi-константа типа Char, равная символу-разделителю Windows
 else
 if (not(Key in Digit))
 then Key:=#0;
if ((Key=DecimalSeparator)and(pos(DecimalSeparator, Edit1.Text)<>0))
 then Key:=#0;
end;

procedure TForm1.Edit8KeyPress(Sender: TObject; var Key: Char);
begin
if (length(edit8.Text)=0) then
 if (key in firstdigit) then exit
 else key:=#0;
if (Key in Separator)
 then Key:=DecimalSeparator //Delphi-константа типа Char, равная символу-разделителю Windows
 else
 if (not(Key in Digit))
 then Key:=#0;
if ((Key=DecimalSeparator)and(pos(DecimalSeparator, Edit1.Text)<>0))
 then Key:=#0;
end;

procedure TForm1.MenuClearClick(Sender: TObject);
begin
 Edit1.Text:='';
 Edit2.Text:='';
 Edit3.Text:='';
 Edit4.Text:='';
 Edit5.Text:='';
 Edit6.Text:='';
 Edit7.Text:='';
 Edit8.Text:='';
 Edit9.Text:='';
 Edit10.Text:='';
 Edit11.Text:='';
 Edit12.Text:='';
end;

procedure TForm1.MenuSaveClick(Sender: TObject);
 var F: TextFile;
 FName: TOpenDialog;
begin
 FName:=TOpenDialog.Create(self);
 FName.InitialDir := GetCurrentDir;

 // Разрешено выбрать только .txt
 FName.Filter :='Текстовый файл|*.txt';

 // Выбор файлов Паскаля как стартовый тип фильтра
 FName.FilterIndex := 1;

 // Показ диалог открытия файла
 if not FName.Execute then exit;

 assignfile(f,FName.FileName);
 if not FileExists(FName.FileName) then
 begin
 Rewrite(f);
 CloseFile(f);
 end;
 Append(f);
 Writeln(f,DateTimeToStr(now));
 Writeln(f,'Z1+Z2='+edit9.Text);
 Writeln(f,'Z1-Z2='+edit10.Text);
 Writeln(f,'Z1*Z2='+edit11.Text);
 Writeln(f,'Z1/Z2='+edit12.Text);
 Flush(f);
 CloseFile(f);
 // Освобождение диалога
 FName.Free;
end;

end.

PM MAIL   Вверх
CynicRus
Дата 31.5.2014, 21:53 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Бывалый
*


Профиль
Группа: Участник
Сообщений: 248
Регистрация: 31.5.2012

Репутация: нет
Всего: 5



Адский ###код без форматирования. Друже, напиши сам, на Си и с нуля. Так оно, поверь, проще.
PM MAIL   Вверх
  
Ответ в темуСоздание новой темы Создание опроса
Правила форума "Delphi"
THandle
Rrader
volvo877

Запрещается!

1. Обсуждать и делится взломанными компонентами или программным обеспечением

2. Публиковать ссылки на варез

3. Оффтопить

  • Действия модераторов можно обсудить здесь
  • С просьбами о написании курсовой, реферата и т.п. обращаться сюда
  • Вопросы по реализации алгоритмов рассматриваются здесь
  • 90% ответов на свои вопросы можно найти в DRKB (Delphi Russian Knowledge Base) - крупнейшем в рунете сборнике материалов по Дельфи

Если Вам понравилась атмосфера форума, заходите к нам чаще! С уважением, THandle, Rrader, volvo877.

 
0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | Object Pascal: кроссплатформенные технологии | Следующая тема »


 




[ Время генерации скрипта: 0.1049 ]   [ Использовано запросов: 22 ]   [ GZIP включён ]


Реклама на сайте     Информационное спонсорство

 
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности     Powered by Invision Power Board(R) 1.3 © 2003  IPS, Inc.