📄 cse5805dlg.cpp
字号:
// cse5805Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "cse5805.h"
#include "cse5805Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include <fstream.h>
#include <math.h>
#include <io.h>
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCse5805Dlg dialog
CCse5805Dlg::CCse5805Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CCse5805Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCse5805Dlg)
m_strDataFile = _T("");
m_strMFile = _T("");
m_strVarAFile = _T("");
m_strCovAFile = _T("");
m_strAcrAFile = _T("");
m_strHFile = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CCse5805Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCse5805Dlg)
DDX_Text(pDX, IDC_EDIT1, m_strDataFile);
DDX_Text(pDX, IDC_EDIT2, m_strMFile);
DDX_Text(pDX, IDC_EDIT3, m_strVarAFile);
DDX_Text(pDX, IDC_EDIT4, m_strCovAFile);
DDX_Text(pDX, IDC_EDIT5, m_strAcrAFile);
DDX_Text(pDX, IDC_EDIT6, m_strHFile);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCse5805Dlg, CDialog)
//{{AFX_MSG_MAP(CCse5805Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnBrowse)
ON_BN_CLICKED(IDC_BUTTON2, OnCalcAll)
ON_BN_CLICKED(IDC_BUTTON3, OnBrowseM)
ON_BN_CLICKED(IDC_BUTTON4, OnBrowseVarA)
ON_BN_CLICKED(IDC_BUTTON5, OnBrowseCov)
ON_BN_CLICKED(IDC_BUTTON6, OnBrowseAcrA)
ON_BN_CLICKED(IDC_BUTTON7, OnBrowseH)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCse5805Dlg message handlers
BOOL CCse5805Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
///////////Get System path//////////////
CString strSystemPath;
char chExePath[256];
GetModuleFileName(NULL,chExePath,256);
strSystemPath=chExePath;
int pos=strSystemPath.ReverseFind('\\');
strSystemPath=strSystemPath.Left(pos);
m_strDataFile=strSystemPath+"\\assign2data.txt";
m_strMFile=strSystemPath+"\\m.txt";
m_strVarAFile=strSystemPath+"\\Var(A).txt";
m_strCovAFile=strSystemPath+"\\Cov(A).txt";
m_strAcrAFile=strSystemPath+"\\Acr(A).txt";
m_strHFile=strSystemPath+"\\H.txt";
UpdateData(false);
/////////////////////////////////////////////////
return TRUE; // return TRUE unless you set the focus to a control
}
void CCse5805Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CCse5805Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CCse5805Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CCse5805Dlg::OnBrowse()
{
CFileDialog fd(true,NULL,NULL,OFN_HIDEREADONLY,"Text File(*.txt)|*.txt||",NULL);
if(IDOK==fd.DoModal())
{
m_strDataFile=fd.GetPathName();
UpdateData(false);
}
}
void CCse5805Dlg::OnBrowseM()
{
CFileDialog fd(false,NULL,NULL,OFN_HIDEREADONLY,"Text File(*.txt)|*.txt||",NULL);
if(IDOK==fd.DoModal())
{
m_strMFile=fd.GetPathName()+".txt";
UpdateData(false);
}
}
void CCse5805Dlg::OnBrowseVarA()
{
CFileDialog fd(false,NULL,NULL,OFN_HIDEREADONLY,"Text File(*.txt)|*.txt||",NULL);
if(IDOK==fd.DoModal())
{
m_strVarAFile=fd.GetPathName()+".txt";
UpdateData(false);
}
}
void CCse5805Dlg::OnBrowseCov()
{
CFileDialog fd(false,NULL,NULL,OFN_HIDEREADONLY,"Text File(*.txt)|*.txt||",NULL);
if(IDOK==fd.DoModal())
{
m_strCovAFile=fd.GetPathName()+".txt";
UpdateData(false);
}
}
void CCse5805Dlg::OnBrowseAcrA()
{
CFileDialog fd(false,NULL,NULL,OFN_HIDEREADONLY,"Text File(*.txt)|*.txt||",NULL);
if(IDOK==fd.DoModal())
{
m_strAcrAFile=fd.GetPathName()+".txt";
UpdateData(false);
}
}
void CCse5805Dlg::OnBrowseH()
{
CFileDialog fd(false,NULL,NULL,OFN_HIDEREADONLY,"Text File(*.txt)|*.txt||",NULL);
if(IDOK==fd.DoModal())
{
m_strHFile=fd.GetPathName()+".txt";
UpdateData(false);
}
}
void CCse5805Dlg::CalcM()
{
char chtemp[1024];
int nOrder,nCounter=1,nSumPerSec=0,nSumAllSec=0;
float fTime;
ifstream ifile(m_strDataFile,ios::nocreate);
ofstream ofile(m_strMFile);
ofile<<"second"<<'\t'<<"number"<<endl;
ifile.getline(chtemp,1024);
while(ifile>>nOrder)
{
ifile>>fTime;
while(true)
{
if(fTime<=nCounter)
{
nSumPerSec++;
break;
}
else
{
nSumAllSec+=nSumPerSec;
ofile<<nCounter<<'\t'<<nSumPerSec<<endl;
nSumPerSec=0;
nCounter++;
}
}
}
K=nCounter;
m=float(nSumAllSec)/K;
ofile<<"M values:"<<m<<endl;
ifile.close();
ofile.close();
}
void CCse5805Dlg::CalcVarA()
{
char chtemp[1024];
float sum=0;
int temp,nSumPerSec;
ifstream ifile(m_strMFile);
ofstream ofile(m_strVarAFile);
ifile.getline(chtemp,1024);
while(ifile>>temp)
{
ifile>>nSumPerSec;
sum+=(nSumPerSec-m)*(nSumPerSec-m);
}
sum/=K;
fVar=sum;
ofile<<"Var(A)="<<fVar<<endl;
}
void CCse5805Dlg::CalcCovA()
{
char chtemp[1024];
float sum=0;
int temp,A,Anext;
ifstream ifile(m_strMFile);
ofstream ofile(m_strCovAFile);
ifile.getline(chtemp,1024);
ifile>>temp>>A;
while(ifile>>temp)
{
ifile>>Anext;
sum+=(A-m)*(Anext-m);
A=Anext;
}
sum/=K;
fCov=sum;
ofile<<"Cov(A)="<<fCov<<endl;
ifile.close();
ofile.close();
}
void CCse5805Dlg::CalcAcrA()
{
fAcr=fCov/fVar;
ofstream ofile(m_strAcrAFile);
ofile<<"Acr(A)="<<fAcr<<endl;
ofile.close();
}
void CCse5805Dlg::CalcH()
{
fH=0.5*(1+log(1+fAcr)/log(2));
ofstream ofile(m_strHFile);
ofile<<"H="<<fH<<endl;
ofile.close();
}
void CCse5805Dlg::OnCalcAll()
{
UpdateData(true);
if(0==_access(m_strDataFile,00))
{
CalcM();
CalcVarA();
CalcCovA();
CalcAcrA();
CalcH();
CString strMsg;
strMsg.Format("H values:%f",fH);
AfxMessageBox(strMsg);
}
else
{
AfxMessageBox("Please input correct scr file!");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -