这是一个有效的 Turbo Pascal 示例
uses graph, crt;
const xmax=600;
ymax=400;
type vreal=array[1..xmax] of real;
var
y:vreal;
r,h,vmax,vmin,a,b:real;
i,linie0:integer;
grDriver: Integer;
grMode: Integer;
s:string;
c:char;
{****************************************}
procedure regimgrafic;
begin
grDriver := Detect;
InitGraph(grDriver, grMode,'');
setcolor(15);
end;
{****************************************}
function f(x:real):real;
begin
f:=exp(cos(2*x)*ln(x))+3*sin(x);
end;
{**************************************************************}
procedure calcul(a,b:real;var z:vreal);
begin
h:=abs(b-a)/(xmax-1);
for i:=1 to xmax do z[i]:=f(a+(i-1)*h);
end;
{**************************************************************}
procedure normare(var z:vreal; var l0:integer;var vmax,vmin:real);
var
delta,deplasare:real;
begin
vmax:=z[1];vmin:=z[1];
for i:=2 to xmax do
begin
if z[i]>vmax then vmax:=z[i];
if z[i]<vmin then vmin:=z[i];
end;
delta:=(vmax - vmin)/(ymax);
deplasare:=0-vmin;
l0:=round(ymax-deplasare/delta);
if vmin>0 then l0:=415;
if vmax<0 then l0:=10;
for i:=1 to xmax do
z[i]:=ymax-(z[i]+deplasare)/delta;
end;
{*******************************************************}
procedure axax(linie0:integer);
begin
setcolor(11);
outtextxy(getmaxx-15,linie0-10,'X');
line(20,linie0, getmaxx-20,linie0);
h:=(b-a)/2;
for i:=0 to 2 do
begin
fillellipse(20+i*300,linie0,2,2);
r:=a+i*h;
str(r:0:2,s);
outtextxy(20+i*290,linie0+10,s);
end;
end;
procedure axay;
begin
setcolor(14);
outtextxy(10,10,'Y');
h:=(vmax-vmin);
for i:=0 to 1 do
begin
fillellipse(20,10+i*400,2,2);
r:=vmax-i*h;
str(r:0:2,s);
outtextxy(20,10+i*400,s);
end;
line(20,10,20,getmaxy-65);
end;
procedure modeleazagrafic(y:vreal);
begin
rectangle(1,1,getmaxx,getmaxy);
setcolor(11);
axay;
axax(linie0);
for i:=1 to xmax do putpixel(i+20,10+round(y[i]),15);
outtextxy(20,460,'Alt interval (D)a / (N)u');
end;
begin
repeat
clrscr;
write('Introdu extremitatile intervalului: ');
readln(a,b);
calcul(a,b,y);
normare(y,linie0,vmax,vmin);
regimgrafic;
modeleazagrafic(y);
c:=readkey;
closegraph;
until upcase(c)='N';
end.
这是我的c代码
#include<graphics.h>
#include<string>
#include<math.h>
#include<iostream>
const int xmax = 600;
int ymax = 400;
typedef float vreal[600];
using namespace std;
vreal y;
float r,h,vmax,vmin,a,b;
int linie0;
int grDriver;
int grMode;
string s;
char c;
void regimgrafic()
{
initwindow(xmax,ymax,"COOL");
setcolor(WHITE);
}
float f(float x)
{
return exp(cos(2*x)+log(x)+3*sin(x));
}
void calcul(float a, float b,float* z)
{
h = fabs(b-a)/(xmax-1);
for(int i=1;i <= xmax;i++)
{
z[i] = f(a+(i-1)*h);
}
}
void normare(float *z, int* l0, float *vmin, float *vmax)
{
float delta, deplasare;
*vmax = z[1];
*vmin = z[1];
for(int i=2;i<= xmax;i++)
{
if(z[i] > *vmax) *vmax = z[i];
if(z[i] < *vmin) *vmin = z[i];
}
delta = (*vmax - *vmin)/(ymax);
deplasare = 0-*vmin;
*l0 = (int)(round(ymax - deplasare/delta));
//<static_cast><int>()
if((*vmin)>0) l0 = 415;
if(*vmax<0) l0 = 10;
for(int i=1;i<= xmax;i++)
z[i]=ymax - (z[i]+deplasare)/delta;
}
void axax(int linie0)
{
setcolor(11);
outtextxy(getmaxx-15,linie0-10,'X');
line(20,linie0,getmaxx-20,linie0)
h=(b-a)/2;
for(int i =0;i<2;i++)
{
fillellipse(20,10+i*400,2,2);
r=vmax-i*h;
sprintf(s, "%d", r);
outtextxy(20+i*290,linie0+10,s);
}
}
void axay
{
setcolor(14);
outtextxy(10,10,'Y');
h=(vmax-vmin);
for(int i=0;i<1;i++)
{
fillellipse(20,10+i*400,2,2);
r=vmax-i*h;
sprintf(s,r);
outtextxy(20,10+i*400,s);
}
}
void modeleazagrafic(vreal y){
rectangle(1,1,getmaxx,getmaxy);
setcolor(11);
axay;
axax(linie0);
for(int i=1;i<xmax;i++)
putpixel(i+20,10+round(y[i]),15);
outtextxy(20,460,'Alt interval (D)a / (N)u');
}
int main()
{
do {
printf("Introduceti extremitatile intervalului: ");
scanf("%f %f",&a,&b);
calcul(a,b,y);
normare(y,linie0,vmax,vmin);
regimgrafic;
modeleazagrafic(y);
c=getch();
closegraph();
}while(toupper(c) == 'N');
}
我有一堆错误,这里是一些主题代码
Line 60:(in normare function) invalid conversion from `int' to `int*'
line:61 the same error;
line:69 69 pointer to a function used in arithmetic
请帮助解决这些错误