⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 student.cpp

📁 非常棒的VC入门课件
💻 CPP
字号:
// Student.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include "console.h"
#include "student.h"
#include "studentui.h"

CStudentUI theUI;			
CStudentFile theFile("student.dat");

// 定义命令函数
void DoAddRec(void);
void DoDelRec(void);
void DoListAllRec(void);
void DoFindRec(void);
void main()
{
	const int nItemNum = 7;
	char *strItem[nItemNum] = {	"Add a student data record", 
					"Delete a student data record",
					"-", 
					"List all data records", 
					"Find a student data record",
					"-",
					"Exit" };
	theUI._SetOptionsTitle(" Main Menu ");
	for (;;) {
		int nIndex = theUI._GetOptions(strItem,0,0,nItemNum);
		switch(nIndex)	{
			case 0:		// Add a student data record
				DoAddRec();		break;
			case 1:		// Delete a student data record
				DoDelRec();		break;
			case 2:		// List all data records
				DoListAllRec();	break;
			case 3:		// Find a student data record
				DoFindRec();	break;
				break;
			case 4:		// Exit
				return;
		}
	}
}
void DoAddRec(void)
{
	CStudentRec rec;
	if ( theUI.InputStuRec( rec ) ) {
		theFile.Add( rec );
		DoListAllRec();
	}
}
void DoDelRec(void)
{
	CStudentRec rec;
	char strID[80], str[80]=" No find the record of ";
	strcpy(strID, theUI._InputBox( " Input Deleted Student ID ", 0, 0 ));
	if (strID) {
		int nIndex = theFile.Seek( strID, rec );
		if (nIndex>=0) {
			theFile.Delete( strID );
			DoListAllRec();
		} else {
			strcat( str, strID );
			strcat( str, " !" );
			theUI._MessageBox(" Notice ", str, 1 );
		}
	}	
}
void DoListAllRec(void)
{
	int nCount = theFile.GetRecCount();
	CStudentRec *stu;
	stu = new CStudentRec[nCount];
	theFile.GetStuRec( stu );
	theUI.DispStuRecs( stu, nCount );
	delete [nCount]stu;
}
void DoFindRec(void)
{
	CStudentRec rec;
	char strID[80], str[80]=" No find the record of ";
	strcpy(strID, theUI._InputBox( " Input Finded Student ID ", 0, 0 ));
	if (strID) {
		int nIndex = theFile.Seek( strID, rec );
		if (nIndex>=0)
			theUI.DispStuRecs( &rec, 1 );
		else {
			strcat( str, strID );
			strcat( str, " !" );
			theUI._MessageBox(" Notice ", str, 1 );
		}
	}
}

⌨️ 快捷键说明

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