📄 chapter27view.cpp
字号:
// Chapter27View.cpp : implementation of the CChapter27View class
//
#include "stdafx.h"
#include "Chapter27.h"
#include "Chapter27Doc.h"
#include "Chapter27View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CChapter27View
IMPLEMENT_DYNCREATE(CChapter27View, CView)
BEGIN_MESSAGE_MAP(CChapter27View, CView)
//{{AFX_MSG_MAP(CChapter27View)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChapter27View construction/destruction
CChapter27View::CChapter27View()
{
// TODO: add construction code here
}
CChapter27View::~CChapter27View()
{
}
BOOL CChapter27View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CChapter27View drawing
void CChapter27View::OnDraw(CDC* pDC)
{
CChapter27Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
//随机种子
srand((unsigned)time(NULL));
//总的随机数数目
#define nCount 10
int array[nCount];
CString strResult,strTem;
strResult="原始顺序:";
for(int i=0;i<nCount;i++)
{
array[i]=rand();
TRACE("%d\n",array[i]);
strTem.Format("%d-",array[i]);
strResult+=strTem;
}
pDC->TextOut(10,10,strResult);
//冒泡排序
BubbleSort(array,1,nCount);
//冒泡排序结果
strResult="冒泡排序:";
for(i=0;i<nCount;i++)
{
strTem.Format("%d-",array[i]);
strResult+=strTem;
}
//输出
pDC->TextOut(10,40,strResult);
}
void CChapter27View::BubbleSort(int array[], BOOL asc,int num)
{
//排序
while(num>=0)
{
for(int j=0;j<num-1;j++)
switch(asc)
{
case 1:
if(array[j]>array[j+1])
{
Swap(array[j],array[j+1]);
}
break;
case 0:
if(array[j]<array[j+1])
{
Swap(array[j],array[j+1]);
}
break;
}
num--;
}
}
void CChapter27View::Swap(int &a, int &b)
{
int c=a;
a=b;
b=c;
}
/////////////////////////////////////////////////////////////////////////////
// CChapter27View printing
BOOL CChapter27View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CChapter27View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CChapter27View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CChapter27View diagnostics AfxWndProc
#ifdef _DEBUG
void CChapter27View::AssertValid() const
{
Dump(afxDump);
CView::AssertValid();
}
void CChapter27View::Dump(CDumpContext& dc) const
{
CTime m_time=CTime::GetCurrentTime();
CString strTime=m_time.Format("%H-%M-%S");
dc<<"当前时间:"<<strTime;
CView::Dump(dc);
}
CChapter27Doc* CChapter27View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CChapter27Doc)));
return (CChapter27Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CChapter27View message handlers
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -