Float Fmodif(float x);
Void graphF(float Xst, float Xen, float Step, int color);
Void main()
{
Clrscr();
Float Xst, Xen, Step;
cout << " F(x).\n";
cout << "Xstart = "; cin>>Xst;
cout << "Xend = "; cin>>Xen;
cout << "Step = "; cin>>Step;
Tabular_for(Xst, Xen, Step);
Getch();
cout<<"\n F(x).\n";
cout<<"Xstart ="; cin>>Xst;
cout<<"Xend = "; cin>>Xen;
cout<<"Step = "; cin>>Step;
GraphF(Xst, Xen, Step, 1);
}
// :
Float F(float x)
{ if(x == 0) return 1; else return sin(x)/x; }
Void tabular_for(float Xst, float Xen, float Step)
{for(float x = Xst; x <= Xen; x += Step)
{ cout<<"\n x = " << setw(6)<<setprecision(2)<<x; // ;
cout<<" F(x) = "<<setw(6)<<setprecision(3)<<F(x);
}
}
Float Fmodif(float x)
{ if(x!= 0) return sin(x/6)/(x/6); else return 1; }
Void graphF(float Xst, float Xen, float Step, int color)
{int gd=DETECT, gm, err;
// graph:
initgraph(&gd, &gm, "d:\\bc5\\bgi");
// :
err = graphresult();
if (err!= grOk) // !
{cout<<"\n : "<< grapherrormsg(err); // ;
cout<<" :";
Getch();
exit(1); // 1;
}
setbkcolor(15); // ;
setcolor(color); // ;
// :
int cX= (int) getmaxx()/2, cY= (int) getmaxy()/2;
Float x, y;
line(0, cY, 2*cX, cY); // OX;
line(cX, 0, cX, 2*cY); // OY;
// :
for(x = Xst; x <= Xen; x += Step)
{ y = Fmodif(x); putpixel((int) x + cX, (int) -40*y + cY, color); }
Getch();
}
. C++ Help - (\HELP\bcdos.hlp Borland Graphic Interface (BGI)).
: Ctrl + F9, Run.
: Alt + F9, Compile this file.
:
F(x) [-1; 1] 0,4:
F(x) [-100; 100] 0,01:
1
, , F [st; en] Step ; st, en Step .
1. ,
2. ,
3. ,
|
|
4. ,
5. ,
6. ,
7. ,
8. ,
9. ,
10. ,
11. ,
12. ,
13. ,
14. ,
15. ,
[1] , "_", "_".
[2] .
[3] .
[4] ← , , .
[5] (, ) , , : if(x < 0) {int r = 2;} else ++r; else (!) r.
[6] cin C Input.
[7] cout C Output.
[8] .