回复:(a273369457)[QUOTE]会出现输入数组:asd将大...
请问个问题:下请问个问题:下面的程序应该建在什么工程一下阿?谢谢大侠了!!!!
#include"stdafx.h"
#include"EXP9_3.h"
#include"ChildView.h"
#include"math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#endif
#define T_END 1000.0 //模拟终止时刻
#define T_DISP 20.0
#define TAU_MAX 10 //tau的最大值
double exponent(double lambda,double tau);
//CChildView
CChildView::CChildView()
{
}
CChildView::~CChildView()
{
}
BEGIN_MESSAGE_MAP(CChildView,CWnd)
//{{AFX_MSG_MAP(CChildView)
ON_WM_PAINT()
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//CChildView message handlers
BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs)
{
if(!CWnd::PreateWindow(cs)
return FALSE;
cs.style &=~WS_BORDER;
cs.lpszClass=AfxRegisterWndClass(CS_HREDRAMM|CS_VREDRAM|CS_DBLCLKS,
::LoadCursor(NULL,IDC_ARROW),HBRUSH(COLOR_WINDOM+1),NULL);
return TRUE;
}
void CChildView::OnPaint()
{
CPaintDC dc(this); //device context for painting
//TODO:Add your message handler code here
RECT rect;
dc.GetClipBox(&rect);
dc.SelectStockObject(BLACK_BRUSH);
dc.Rectangle(&rect);
window1.Paint(&dc);
window2.Paint(&dc);
//DO not call CWnd::OnPaint() for painting messages
}
int CChildView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if(CWnd::OnCreate(lpCreateStruct)==-1)
return -1;
//TODO:Add your specialized create code here
long j; //事件发生次数
int f[TAU_MAX+1]={0}; //柱状图
int u; //tau的整数部分
double lambda=1;
double dt=0.01; //微小时间
double t0=0.0;
double t=0.0; //现在时间
double tau=0.0; //事件发生间隔TAU
srand(time(NULL));
//图形准备
InitWindow(this->GetParentFrame(),WIDTH,HEIGHT);
window1.SetWindow(0.0,0.0,T_DISP,1.0,0,0,WIDTH,100);
window2.SetWindow(0.0,0.0,T_DISP/2,1.0,0,80,WIDTH,HEIGTH-100);
window2.Axis(1.0,0.1,"模拟指数分布","τ","freq");
window2.MoveTo(0,exponent(lambda,0));
while(tau<=TAU_MAX)
{
window2.LineTo(tau,exponent(lambda,tau));
tau+=dt;
}
//主循环
j=0;
while(t<=T_END)
{
if((lambda*dt)>RANDOM())
{
if(t<T_DISP)
{
window1.Line(t,0,t,1);
}
tau=t-t0;
u=(int)tau;
if(u<TAU_MAX)
{
f[u]=f[u]+1;
}
t0=t;
j=j+1;
}
t+=dt;
}
//绘制柱状图
window2.SetLineStyle(PS_SOLID,3);
for(u=0;u<TAU_MAX;u++)
{
window2.Line(u+0.5,u+0.5,(double)f[u]/j);
}
return 0;
}
double exponent(double lambda, double tau)
{
return lambda* exp(-lambda*tau);
}