Калькулятор (расширенная функциональность)

uses crt;

var 
a:char;
c1,c2,i:real;
n:string;
l1,l2:byte;
b:boolean:=true;

label tobegin;


procedure addition(c1,c2:real; var sum:real);
begin
sum:=c1+c2;
end;

procedure subtraction(c1,c2:real; var dif:real);
begin
dif:=c1-c2;
end;

procedure multiply(c1,c2:real; var pr:real);
begin
pr:=c1*c2;
end;

procedure division(c1,c2:real; var q:real);
begin
if c2<>0 then q:=c1/c2 else
begin writeln; writeln('Деление на 0!'); end;
end;

procedure exponentiation(c1,c2:real; var pw:real);
begin
pw:=exp(c2*ln(c1));
end;

procedure squareroot(c1:real; var sq:real);
begin
if c1>=0 then sq:=sqrt(c1) else
begin writeln; writeln('Невозможно извлечь квадратный корень из отрицательного числа!'); end;
end;

procedure sine(c1:real; var s:real);
begin
s:=sin(c1);
end;

procedure cosine(c1:real; var c:real);
begin
c:=cos(c1);
end;


begin

crt.setwindowsize(80,30);
crt.setwindowtitle('PasCALC');
crt.textcolor(crt.black);
crt.textbackground(white);
crt.clrscr;

crt.gotoxy(crt.wherex+30,crt.wherey);
writeln('PacCALC, version 1.6, 2014');
crt.gotoxy(crt.wherex+3,crt.wherey+1); writeln('Для выбора действия используйте клавиши ниже. Для ввода используйте Enter.');
crt.gotoxy(crt.wherex+20,crt.wherey); writeln('Буквенные клавиши не зависят от раскладки.');
crt.gotoxy(crt.wherex+17,crt.wherey+1); write('Сложение: + и p');
crt.gotoxy(crt.wherex+17,crt.wherey); writeln('Вычитание: - и m');
crt.gotoxy(crt.wherex+18,crt.wherey); write('Умножение: * и x');
crt.gotoxy(crt.wherex+18,crt.wherey); writeln('Деление: / и :');
crt.gotoxy(crt.wherex+6,crt.wherey); write('Возведение в степень: ^ и 6');
crt.gotoxy(crt.wherex+6,crt.wherey); writeln('Нахождение квадратного корня: √ и q'); 
crt.gotoxy(crt.wherex+20,crt.wherey); write('Синус: s');
crt.gotoxy(crt.wherex+20,crt.wherey); write('Косинус: c');
crt.gotoxy(crt.wherex,crt.wherey+2);

while (b=true) do begin

writeln;

try

tobegin:
write('Выберите математическое действие: ');
a:=crt.readkey;

if (a='+') or (a='p') or (a='P') or (a='з') or (a='З') then begin
writeln('сложение'); writeln('Введите слагаемые'); read(c1);
str(c1,n); l1:=length(n); crt.gotoxy(crt.wherex+l1,crt.wherey-1); write('+');
read(c2); str(c2,n); l2:=length(n); crt.gotoxy(crt.wherex+l1+l2+1,crt.wherey-1);
addition(c1,c2,i); writeln('=',i);
end
else

if (a='-') or (a='m') or (a='M') or (a='ь') or (a='Ь') then begin
writeln('вычитание'); writeln('Введите уменьшаемое и вычитаемое'); read(c1);
str(c1,n); l1:=length(n); crt.gotoxy(crt.wherex+l1,crt.wherey-1); write('-');
read(c2); l2:=length(n); crt.gotoxy(crt.wherex+l1+l2+1,crt.wherey-1);
subtraction(c1,c2,i); writeln('=',i);
end
else

if (a='*') or (a='x') or (a='X') or (a='ч') or (a='Ч') then begin
writeln('умножение'); writeln('Введите множители'); read(c1);
str(c1,n); l1:=length(n); crt.gotoxy(crt.wherex+l1,crt.wherey-1); write('x');
read(c2); str(c2,n); l2:=length(n); crt.gotoxy(crt.wherex+l1+l2+1,crt.wherey-1);
multiply(c1,c2,i); writeln('=',i);
end
else

if (a=':') or (a='/') then begin
writeln('деление'); writeln('Введите делимое и делитель'); read(c1);
str(c1,n); l1:=length(n); crt.gotoxy(crt.wherex+l1,crt.wherey-1); write(':');
read(c2); str(c2,n); l2:=length(n); crt.gotoxy(crt.wherex+l1+l2+1,crt.wherey-1);
division(c1,c2,i); if c2<>0 then writeln('=',i);
end
else

if (a='^') or (a='6') or (a='e') then begin
writeln('возведение в степень'); writeln('Введите число'); read(c1);
str(c1,n); l1:=length(n); crt.gotoxy(crt.wherex+l1,crt.wherey-1); write('^');
read(c2); str(c2,n); l2:=length(n); crt.gotoxy(crt.wherex+l1+l2+1,crt.wherey-1);
exponentiation(c1,c2,i); writeln('=',i);
end
else

if (a='q') or (a='Q') or (a='й') or (a='Й') then begin
writeln('нахождение квадратного корня'); writeln('Введите число'); write('√'); read(c1);
str(c1,n); l1:=length(n); crt.gotoxy(crt.wherex+l1+1,crt.wherey-1);
squareroot(c1,i); if c1>=0 then writeln('=',i);
end
else

if (a='s') or (a='S') or (a='ы') or (a='Ы') then begin
writeln('синус'); writeln('Введите число'); write('sin('); read(c1);
str(c1,n); l1:=length(n); crt.gotoxy(crt.wherex+l1+4,crt.wherey-1); write(')');
sine(c1,i); writeln('=',i);
end
else

if (a='c') or (a='C') or (a='с') or (a='С') then begin
writeln('косинус'); writeln('Введите число'); write('cos('); read(c1);
str(c1,n); l1:=length(n); crt.gotoxy(crt.wherex+l1+4,crt.wherey-1); write(')');
cosine(c1,i); writeln('=',i);
end

else 
begin crt.clearline; goto tobegin; end;

except on system.formatexception do writeln('Неверный формат ввода! Попробуйте еще раз.'); end;

writeln;
writeln('Нажмите любую клавишу, чтобы продолжить работу, пробел, чтобы очистить окно, или Esc, чтобы выйти');
a:=crt.readkey; if (a=#27) then b:=false; if (a=#32) then crt.clrscr;

end;

end.
Добавлено: 17 Июня 2014 09:15:02 Добавил: Андрей Ковальчук Нравится 0
Добавить
Комментарии:
Нету комментариев для вывода...