📄 studentui.h
字号:
// 文件studentui.h中的内容
class CStudentUI: public CConUI
{
public:
CStudentUI();
bool InputStuRec(CStudentRec &stu); // 通过键盘输入记录
void DispStuRecs(CStudentRec *stu, int nNum); // 显示nNum个记录
private:
void DispListHead(int nRow = 0); // 显示表头
};
CStudentUI::CStudentUI()
{
_SetMainFrameTitle("Management For The Student Scores");
_InitMainFrame(7);
DispListHead();
}
bool CStudentUI::InputStuRec(CStudentRec &stu)
{
bool bRes = false;
char *str[5] = {"Name:", "Student ID:", "Score 1:", "Score 2:", "Score 3:"};
_SetMultiInputTitle( "Input student record data" );
bRes = _InputMultiBox(str, 0, 0, 20, str, 5);
if (bRes){
strncpy(stu.strName, str[0], 20);
strncpy(stu.strID, str[1], 10);
stu.fAve = (float)0.0;
for (int i=0; i<3; i++) {
stu.fScore[i] = (float)atof(str[i+2]);
stu.fAve += stu.fScore[i];
}
stu.fAve = float(stu.fAve/3.0);
stu.chFlag = 'A';
}
return bRes;
}
void CStudentUI::DispListHead(int nRow)
{
int nSizeX, nSizeY;
_GetWindowSize(&nSizeX, &nSizeY); // 获得窗口的大小
_SaveSettings();
_SetBackColor(15); // 背景色为白色
_SetForeColor(0); // 文本色为黑色
_FillBox(0, nRow, nSizeX-1, 1, false); // 画背景水平条
_SetCursorPos(0, nRow);
cout.setf(ios::left);
cout<<setw(10)<<" Rec NO"<<setw(20)<<"Student Name"<<setw(10)<<" ID";
cout<<setw(10)<<"Score 1"<<setw(10)<<"Score 2"<<setw(10)<<"Score 3";
cout<<"Average"<<endl;
_LoadSettings();
_GetConwinSize(&nSizeX, &nSizeY); // 获得控制台窗口的大小
_DefineWindow(1, 3, nSizeX-2, nSizeY-3); // 重新定义窗口
}
void CStudentUI::DispStuRecs(CStudentRec *stu, int nNum)
{
// 每屏显示nMaxLine个,若nNum>nMaxLine,
// 则可按PageUp和PageDown向上和向下翻页
// 若nNum>nMaxLine,则按ESC键退出
const int nMaxLine = 20;
int nStart, nEnd, nPage = 0, nMaxPages, nRow=0;
nMaxPages = (nNum-1)/nMaxLine; // 最大可显示的页数
unsigned int ch;
int nSizeX, nSizeY, nBkColor, nForeColor;
for (;;) {
nStart = nPage * nMaxLine;
nEnd = nStart + nMaxLine;
if (nEnd>=nNum) nEnd = nNum;
nRow = 0;
_ClearWindow();
for (int i=nStart; i<nEnd; i++) {
if (stu[i].chFlag == 'A') {
_SetCursorPos( 1, nRow ); nRow++;
cout.setf(ios::left);
cout<<setw(10)<<i+1<<setw(20)<<stu[i].strName
<<setw(10)<<stu[i].strID;
cout<<setw(10)<<stu[i].fScore[0]
<<setw(10)<<stu[i].fScore[1]
<<setw(10)<<stu[i].fScore[2];
cout<<stu[i].fAve;
cout.flush(); // 必须有这行代码,否则显示不出来
}
}
if (nMaxPages == 0) break;
else {
// 显示提示信息,背景为黄色,前景色为黑色
nBkColor = _GetBackColor();
nForeColor = _GetForeColor();
_SetBackColor( 14 ); // 黄色
_SetForeColor( 0 ); // 黑色
_GetWindowSize( &nSizeX, &nSizeY );
_FillBox( 0, nSizeY-1, nSizeX, 1, false );
_SetCursorPos( 1, nSizeY-1 );
cout<<"PAGE: "<<nPage<<" RECS: "<<nNum;
cout.flush();
_SetForeColor( nBkColor );
cout<<" <PL. press PAGEUP or"
<<" PAGEDOWN to change pages, and ESC to exit...>";
cout.flush();
// 恢复原来的颜色设置
_SetBackColor( nBkColor );
_SetForeColor( nForeColor );
for(;;) {
ch = _GetKeyChar();
// 当按下ESC退出
if (ch == VK_ESCAPE) return;
if (ch == VK_PRIOR ) { // PAGEUP键
nPage--;
if (nPage<0) nPage = 0;
break;
}
if (ch == VK_NEXT ) { // PAGEDOWN键
nPage++;
if (nPage>nMaxPages) nPage = nMaxPages;
break;
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -