📄 exam8_3doc.cpp
字号:
// Exam8_3Doc.cpp : implementation of the CExam8_3Doc class
//
#include "stdafx.h"
#include "Exam8_3.h"
#include "Exam8_3Doc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CExam8_3Doc
IMPLEMENT_DYNCREATE(CExam8_3Doc, CDocument)
BEGIN_MESSAGE_MAP(CExam8_3Doc, CDocument)
//{{AFX_MSG_MAP(CExam8_3Doc)
// 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
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CExam8_3Doc construction/destruction
CExam8_3Doc::CExam8_3Doc()
{
// TODO: add one-time construction code here
}
CExam8_3Doc::~CExam8_3Doc()
{
}
BOOL CExam8_3Doc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CExam8_3Doc serialization
void CExam8_3Doc::Serialize(CArchive& ar)
{
/*if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}*/
m_ObArray.Serialize(ar);
}
/////////////////////////////////////////////////////////////////////////////
// CExam8_3Doc diagnostics
#ifdef _DEBUG
void CExam8_3Doc::AssertValid() const
{
CDocument::AssertValid();
}
void CExam8_3Doc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CExam8_3Doc commands
void CExam8_3Doc::delStuAll()
{
/*int index;
CStudent*ps;
index=this->GetStuNumber();//获取数据中元素个数
while(index--)//循环删除学生记录
{
ps=GetStu(index-1);
delete ps;
}
m_ObArray.RemoveAll(); //清空对象数据
SetModifiedFlag(); //设置修改标志
this->UpdateAllViews(NULL);//更新视图*/
DeleteContents();
SetModifiedFlag();
this->UpdateAllViews(NULL);
}
void CExam8_3Doc::DelStu(int index)
{
CStudent*ps=GetStu(index);//获取要删除的学生对象指针
delete ps; //删除学生对象
m_ObArray.RemoveAt(index);//在对象数组中删除元素(指针)
SetModifiedFlag(); //设置修改标志
//更新视图,将调用视图类的OnUpdate函数
this->UpdateAllViews(NULL);
}
int CExam8_3Doc::GetStuNumber()
{
//调用GetSize函数返回数组中的元素个数
return m_ObArray.GetSize();
}
CStudent* CExam8_3Doc::GetStu(int index)
{
//GetUpperBound返回最大索引值
if(index<0||index>m_ObArray.GetUpperBound() )
return 0;
//调用GetAt函数返回一个学生对象指针
return (CStudent*)m_ObArray.GetAt(index);
}
void CExam8_3Doc::AddStu(CString Name, int Grade)
{
//动态创建一个学生对象,并使用构造函数赋值
CStudent*pStu=new CStudent(Name,Grade);
//调用Add函数增加一个学生对象到对象数组
m_ObArray.Add(pStu);
SetModifiedFlag(); //设置修改标志
}
void CExam8_3Doc::DeleteContents()
{
// TODO: Add your specialized code here and/or call the base class
int index;
index=m_ObArray.GetSize();
while(index--)
delete m_ObArray.GetAt(index);
m_ObArray.RemoveAll();
CDocument::DeleteContents();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -