用c++语言 如何画出以e为底的指数函数曲线 如函数y=exp(-x⼀200)

2025-01-07 17:21:53
推荐回答(1个)
回答1:

void drawExp(HWND hWnd){

static RECT rc; if(rc.right==0) GetClientRect(hWnd,&rc); 

static float w=rc.right, h=rc.bottom, xo=w/2-w/4, yo=h/2+h/4;

 

HDC hdc=GetDC(hWnd);

SetGraphicsMode(hdc,GM_ADVANCED); 

SetMapMode(hdc, MM_LOENGLISH); 

SetViewportOrgEx(hdc,xo,yo,0L); 

 

MoveToEx(hdc,-w/2 +140,0,0L); LineTo(hdc,w, 0);  MoveToEx(hdc,0,-h/2+80,0L); LineTo(hdc,0,h/2+ 80); 

float r=100; 

float x=-w/2 +160, y=0; xo=x; yo=exp(-x/200)*r;  MoveToEx(hdc,xo,yo,0L); 

float dx=1;

do{

x+=dx; y=exp(-x/200)*r; 

LineTo(hdc,x,y); 

 

xo=x, yo=y; }while(x

ReleaseDC(hWnd,hdc); }