第六章3.txt

来自「本书在复习C++基础知识后」· 文本 代码 · 共 40 行

TXT
40
字号
// 在Ex_StudentDoc.h文件中的class CEx_StudentDoc前添加的
class CStudent : public CObject
{
	CString strName;				// 姓名
	CString strID;				// 学号
	float fScore1, fScore2, fScore3;	// 三门成绩
	float fAverage;				// 平均成绩
	DECLARE_SERIAL(CStudent)
public:
	CStudent() {};
	CStudent(CString name, CString id, float f1, float f2, float f3);
	void Serialize(CArchive &ar);
	void Display(int y, CDC *pDC);	// 在坐标为(0,y)处显示数据
};
// 在Ex_StudentDoc.cpp文件中添加的CStudent实现代码
CStudent::CStudent(CString name, CString id, float f1, float f2, float f3)
{
	strName = name;
	strID = id;
	fScore1 = f1;
	fScore2 = f2;
	fScore3 = f3;
	fAverage = (float)((f1 + f2 + f3)/3.0);
}
void CStudent::Display(int y, CDC *pDC)
{
	CString str;
	str.Format("%s  %s  %f  %f  %f  %f", strName, strID,
		fScore1, fScore2, fScore3, fAverage);
	pDC->TextOut(0, y, str);
}
IMPLEMENT_SERIAL(CStudent, CObject, 1)
void CStudent::Serialize(CArchive &ar)
{
	if (ar.IsStoring())
		ar<<strName<<strID<<fScore1<<fScore2<<fScore3<<fAverage;
	else
		ar>>strName>>strID>>fScore1>>fScore2>>fScore3>>fAverage;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?