program curve; uses graph, crt; function xvalue(x:real;i,r:integer;s1:string):real; var j,counter,code,mm,x3:integer; xx:real; c:char; s2:string; e: array [1..100] of real; d: array [1..100] of byte; begin asm lea di,d mov cx,100 mov ax,0 rep stosw lea di,e mov cx,100 mov ax,0 rep stosw end; mm:=1; x3:=1; repeat i:=i+3; c:=s1[i]; until c=#40; {(} repeat i:=i+1; c:=s1[i]; if (c<=#57) and (c>=#47) then begin j:=i; repeat i:=i+1; c:=s1[i]; until (c>#57) or (c<#47) or (c=' '); s2:=copy(s1,j,i-j); val(s2,e[mm],code); mm:=mm+1; i:=i-1; end; if (c<=#47) and (c>=#42) then begin case c of '+':d[x3]:=1; '-':d[x3]:=2; '*':d[x3]:=3; '/':d[x3]:=4; end; x3:=x3+1; i:=i+1; end; c:=s1[i]; if c='x' then begin e[mm]:=x; mm:=mm+1; i:=i+1; end; until c=#41; {)} asm lea si,d lodsw cmp ax,3 je @m jmp @exit @m : push si lea si,e lodsw mov bx,ax lodsw mul bx mov di,si sub di,4 stosw mov ax,0 stosw @exit: end; {for i:=1 to r do case d[i] of 3: begin e[i]:=e[i]*e[i+1]; e[i+1]:=0; end; 4: begin e[i]:=e[i]/e[i+1]; e[i+1]:=0; end; end;} xx:=e[1]; for i:=1 to r do case d[i] of 1: xx:=xx+e[i+1]; 2: xx:=xx-e[i+1]; end; xvalue:=xx; end; procedure identify (x:real;s1:string;var z:real); function icount (i:integer;s1:string):integer; var c:char; begin repeat c:=s1[i]; i:=i+1; until c=#40; {(} repeat c:=s1[i]; i:=i+1; until c=#41; {)} icount:=i-1; end; var s2,s3:string; c:char; x3,counter,mm,i,i1,j,r,code:integer; t1,t2:real; t: array [1..100] of real; s: array [1..100] of integer; label 1,2; begin asm lea di,s mov cx,100 mov ax,0 rep stosw lea di,t mov cx,100 mov ax,0 rep stosw end; mm:=1; i1:=1; x3:=1; r:=length(s1); repeat begin c:=s1[i1]; if c>#65 then {letters} begin s2:=copy(s1,i1,3); begin if s2='cos' then begin t[mm]:=cos(xvalue(x,i1,r,s1)); mm:=mm+1; i1:=icount(i1+3,s1); end else if s2='sin' then begin t[mm]:=sin(xvalue(x,i1,r,s1)); mm:=mm+1; i1:=icount(i1+3,s1); end else if c='x' then begin t[mm]:=x; mm:=mm+1; end; end; end else if (c<=#57) and (c>#47) then begin j:=i1; repeat i1:=i1+1; c:=s1[i1]; if c=#46 then begin i1:=i1+1; c:=s1[i1]; end; until (c>#57) or (c<=#47) or (c=' '); s2:=copy(s1,j,i1-j); val(s2,t[mm],code); mm:=mm+1; i1:=i1-1; end else if (c<=#47) and (c>=#42) then begin case c of '+':s[x3]:=1; '-':s[x3]:=2; '*':s[x3]:=3; '/':s[x3]:=4; end; x3:=x3+1; end; end; i1:=i1+1; until i1>r; 1: for i1:=1 to r do case s[i1] of 3: begin t[i1]:=t[i1]*t[i1+1]; t[i1+1]:=0; s[i1]:=0; for j:=i1+1 to r do begin t[j]:=t[j+1]; s[j-1]:=s[j]; s[j]:=0; t[j+1]:=0; end; goto 1 end; 4: begin t[i1]:=t[i1]/t[i1+1]; t[i1+1]:=0; s[i1]:=0; for j:=i1+1 to r do begin t[j]:=t[j+1]; s[j-1]:=s[j]; s[j]:=0; t[j+1]:=0; end; goto 1 end; end; z:=t[1]; for i1:=1 to r do case s[i1] of 1: z:=z+t[i1+1]; 2: z:=z-t[i1+1]; end; end; var as1,as2,a,code,coords,counter,i,xt,y,ox,oy,px,py,t,t2,r,mx,my,c,cc,gd,gm: integer; b,bb:byte; a1,a2,z1,z2,z3,z4,x,x1,k,k1,z,m:real; s1,s2,s3,s4,s5: string; begin { writeln; writeln('You can type 2 functions limited by mathematical operands like'); writeln('+,-, *, / and you can use two garmonic functions like cos and sin, every'); writeln('function must be typed correctly, using form exactly. For examle 5*x+cos(2-x/3).'); readln; writeln; write('Input function 1 = '); readln(s1); write('Input function 2 = '); read(s2); write('Input frequency = '); read(t);} s1:='cos(2*3)'; t:=1; s5:=s1; gd:=detect; initgraph (gd,gm,''); mx:=getmaxx; my:=getmaxy; ox:=mx div 2; oy:=my div 2; {t:=3;} m:=9.2*t; xt:=29; k:=1; a2:=10; begin z1:=0; z2:=0; z3:=0; z4:=0; {Now we find maximum value of every functions} for i:=0 to 320 do begin identify(i/m,s1,z); z1:=abs(z); if abs(z1)>abs(z2) then z2:=abs(z1); end; for i:=0 to 320 do begin identify(i/m,s2,z); z3:=abs(z); if abs(z3)>abs(z4) then z4:=abs(z3); end; if z2>z4 then a1:=round(z2) else a1:=round(z4); a2:=a1; if a2>10 then begin repeat a2:=a2/10; k:=k*0.1; until a2<=10; end; if a2<1 then a2:=1; if (a2>=1) and (a2<=10) then begin if (a2>=1) and (a2<2) then k:=k*10 else if (a2>=2) and (a2<10) then k:=k else if (a2=10) then k:=k*0.1; end; end; a1:=k*10; a2:=1/k; setcolor(12); for cc:=1 to 2 do begin x:=0; identify(x/m,s1,z); xt:=0; moveto(ox,oy-round(z*a1)); {begin of drawing graphic} repeat begin x:=xt; identify(x/m,s1,z); px:=ox+xt; py:=oy-round(a1*z); xt:=xt+1; lineto(px,py); end; until px>getmaxx; identify(0,s1,z); moveto (ox,oy-round(z*a1)); xt:=0; x:=0; repeat begin identify(x/m,s1,z); xt:=xt+1; x:=-xt; px:=ox-xt; py:=oy-round(z*a1); lineto(px,py); end; until px<0; s1:=s2; setcolor(9); end; setcolor(green); line(mx div 2,0,mx div 2,my); line(0,my div 2,mx,my div 2); xt:=29; settextstyle(2,0,4); setcolor(11); {end of drawing graphic} {mapping} begin {Pi} outtextxy(ox+t*xt-15*t,355,'Pi'); line (ox+t*xt,355,ox+t*xt,240); line (ox-20,350,ox+t*xt+20,350); {Arrows} moveto (ox,350); for i:=1 to 10 do begin lineto (ox-i,350-i div 3); lineto (ox-i,350+i div 3); end; moveto (ox+t*xt,350); for i:=1 to 10 do begin lineto (ox+t*xt+i,350-i div 3); lineto (ox+t*xt+i,350+i div 3); end; setlinestyle(2, 0, 3); {X coords} for i:=0 to getmaxx div xt do begin setcolor(11); circle(ox+i*t*xt,oy,1); circle(ox-i*t*xt,oy,1); { setcolor(red); circle(ox+i*t*100,oy,1);} end; setcolor(11); {Y coords} for i:=0 to getmaxy do begin circle(ox,oy-i*round(10),1); circle(ox,oy+i*round(10),1); end; for i:=1 to getmaxy do begin setcolor(red); circle(ox,oy-i*round(50),1); circle(ox,oy+i*round(50),1); end; circle(ox,oy-1*round(10),1); circle(ox,oy+1*round(10),1); setcolor(11); {Text about maximums} str(round(a2), s3); str(round(-a2),s4); outtextxy(336,oy-10-6,s3); outtextxy(330,oy+10-6,s4); str(round(a2*10), s3); str(round(-a2*10),s4); outtextxy(336,oy-100-6,s3); outtextxy(330,oy+100-6,s4); str(round(a2*20), s3); str(round(-a2*20),s4); outtextxy(336,oy-200-6,s3); outtextxy(330,oy+200-6,s4); if length(s5)>0 then begin str(z2:4:4,s3); s4:='Maximum value of function:'; s3:='is '+s3; outtextxy(10,10,s4); setcolor(12); outtextxy(10,20,s5); setcolor(11); outtextxy(10,30,s3); end; if length(s2)>0 then begin str(z4:4:4,s3); s3:='is '+s3; outtextxy(10,60,s4); setcolor(9); outtextxy(10,70,s2); setcolor(11); outtextxy(10,80,s3); end; end; readln; readln; cleardevice; closegraph; end.