?? scandlg.cpp
字號:
// scanDlg.cpp : implementation file
//
#include "stdafx.h"
#include "NDisk.h"
#include "scanDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CscanDlg dialog
CscanDlg::CscanDlg(CWnd* pParent /*=NULL*/)
: CDialog(CscanDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CscanDlg)
m_sum = 0;
m_i = 0;
m_flag = -1;
m_d1 = 0.0f;
m_d2 = 0.0f;
m_d3 = _T("");
m_d4 = 0.0f;
m_d5 = _T("");
m_d6 = 0.0f;
m_d7 = 0.0f;
//}}AFX_DATA_INIT
}
void CscanDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CscanDlg)
DDX_Text(pDX, IDC_EDIT1, m_d1);
DDX_Text(pDX, IDC_EDIT2, m_d2);
DDX_Text(pDX, IDC_EDIT3, m_d3);
DDX_Text(pDX, IDC_EDIT4, m_d4);
DDX_Text(pDX, IDC_EDIT5, m_d5);
DDX_Text(pDX, IDC_EDIT6, m_d6);
DDX_Text(pDX, IDC_EDIT7, m_d7);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CscanDlg, CDialog)
//{{AFX_MSG_MAP(CscanDlg)
ON_BN_CLICKED(IDC_BUTTON_Add, OnBUTTONAdd)
ON_BN_CLICKED(IDC_BUTTON_Carray, OnBUTTONCarray)
ON_BN_CLICKED(IDC_RADIO1, OnRadio_in)
ON_BN_CLICKED(IDC_RADIO4, OnRadio_out)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CscanDlg message handlers
void CscanDlg::OnBUTTONAdd()
{
// TODO: Add your control notification handler code here
CString str;
UpdateData(true);
if(m_i<m_d4)
{
int temp;
m_array[m_i] = m_d1;
temp = m_d1;
str.Format("%i",temp);
m_d3.Insert(m_d3.GetLength(),str);
m_d3.Insert(m_d3.GetLength()," ");
m_i++;
UpdateData(false);
}
else
MessageBox("進(jìn)程數(shù)不符合");
}
void CscanDlg::OnBUTTONCarray()
{
// TODO: Add your control notification handler code here
UpdateData(true);
if(m_flag == 1||m_flag == 2)
{
int c[16],d[16],e[16],k,t=0,p=0,y,x,temp,index=0;
/*******************把磁道與開始磁道比較后分別放入兩個數(shù)組中***************************/
for(k=0;k<m_d4;k++)
{
if(m_d2 >= m_array[k])
{
c[t] = m_array[k];
t++;
}
else
{
d[p] = m_array[k];
p++;
}
}
/**************************************************************************************/
//磁頭向里面運動
if(m_flag == 1)
{
CString str;
for(k=0;k<t;k++)
{
int r=0,f1;
f1 = m_d2;
x=159; y=0;
for(int s=0;s<t;s++)
{
y=c[s]-f1;
if (y<0)
y=-y;
if(y<x)
{
x=y;r=s;
}
}
temp = c[r];
str.Format("%i",temp);
m_d5.Insert(m_d3.GetLength(),str);
m_d5.Insert(m_d3.GetLength()," ");
f1=c[r];
e[index] = c[r];
c[r]=500;
index++;
}
for(k=0;k<p;k++)
{
int r=0,f2;
f2 = m_d2;
x=159; y=0;
for(int s=0;s<p;s++)
{
y=d[s]-f2;
if (y<0)
y=-y;
if(y<x)
{
x=y;r=s;
}
}
temp = d[r];
str.Format("%i",temp);
m_d5.Insert(m_d3.GetLength(),str);
m_d5.Insert(m_d3.GetLength()," ");
// cout<<d[r]<<endl;
f2=d[r];
e[index] = d[r];
d[r]=500;
index++;
}
}
//磁頭向外運動
else if(m_flag == 2)
{
CString str;
for(k=0;k<p;k++)
{
int r=0,f2;
f2 = m_d2;
x=159; y=0;
for(int s=0;s<p;s++)
{
y=d[s]-f2;
if (y<0)
y=-y;
if(y<x)
{
x=y;r=s;
}
}
temp = d[r];
str.Format("%i",temp);
m_d5.Insert(m_d3.GetLength(),str);
m_d5.Insert(m_d3.GetLength()," ");
f2=d[r];
e[index] = d[r];
d[r]=500;
}
for(k=0;k<t;k++)
{
int r=0,f3;
f3 = m_d2;
x=159; y=0;
for(int s=0;s<t;s++)
{
y=c[s]-f3;
if (y<0)
y=-y;
if(y<x)
{
x=y;r=s;
}
}
temp = c[r];
str.Format("%i",temp);
m_d5.Insert(m_d3.GetLength(),str);
m_d5.Insert(m_d3.GetLength()," ");
f3=c[r];
e[index] = c[r];
c[r]=500;
index++;
}
}
//求磁頭運行總數(shù)和平均尋道長度
if(m_d2 < e[0])
{
m_sum+=(e[0] - m_d2);
}
else
{
m_sum+=(m_d2-e[0]);
}
for(int n = 0;n < m_d4-1;n++)
{
if(e[n] < e[n+1])
{
m_sum+=(e[n+1] - e[n]);
}
else
{
m_sum+=(e[n] - e[n+1]);
}
}
m_d6 = m_sum; //總尋道數(shù)
m_d7 = m_sum/m_d4; //平均尋道長度
UpdateData(false);
}
else
MessageBox("你還沒有選擇磁頭運行方向");
}
void CscanDlg::OnRadio_in()
{
// TODO: Add your control notification handler code here
m_flag = true;
UpdateData(false);
}
void CscanDlg::OnRadio_out()
{
// TODO: Add your control notification handler code here
m_flag = false;
UpdateData(false);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -