c++學(xué)生管理系統(tǒng).doc_第1頁
c++學(xué)生管理系統(tǒng).doc_第2頁
c++學(xué)生管理系統(tǒng).doc_第3頁
c++學(xué)生管理系統(tǒng).doc_第4頁
c++學(xué)生管理系統(tǒng).doc_第5頁
已閱讀5頁,還剩39頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

/ Student.cpp : Defines the entry point for the console application./#include stdafx.h#include console.h#include student.h#include studentui.hCStudentUI theUI;CStudentFile theFile(student.dat);/ 定義命令函數(shù)void DoAddRec(void);void DoDelRec(void);void DoListAllRec(void);void DoFindRec(void);void main()const int nItemNum = 7;char *strItemnItemNum = 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 recordDoAddRec();break;case 1:/ Delete a student data recordDoDelRec();break;case 2:/ List all data recordsDoListAllRec();break;case 3:/ Find a student data recordDoFindRec();break;break;case 4:/ Exitreturn;void DoAddRec(void)CStudentRec rec;if ( theUI.InputStuRec( rec ) ) theFile.Add( rec );DoListAllRec();void DoDelRec(void)CStudentRec rec;char strID80, str80= 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 CStudentRecnCount;theFile.GetStuRec( stu );theUI.DispStuRecs( stu, nCount );delete nCountstu;void DoFindRec(void)CStudentRec rec;char strID80, str80= 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 );#include #include #include #include class CStudentRecpublic:CStudentRec()chFlag = N;/ 默認(rèn)構(gòu)造函數(shù)CStudentRec();/ 默認(rèn)析構(gòu)函數(shù)friendostream& operator ( istream& is, CStudentRec& stu );CStudentRec& operator = (CStudentRec &stu)/ 賦值運(yùn)算符重載strncpy(strName, stu.strName, 20);strncpy(strID, stu.strID, 10);for (int i=0; i3; i+)fScorei = stu.fScorei;fAve = stu.fAve;chFlag = stu.chFlag;return *this;charchFlag;/ 標(biāo)志,A表示正常,N表示空charstrName20;/ 姓名charstrID10;/ 學(xué)號(hào)floatfScore3;/ 三門成績floatfAve;/ 總平均分;/ CStudentRec類的實(shí)現(xiàn)ostream& operator ( istream& is, CStudentRec& stu )char name20,id10;is.read(&stu.chFlag, sizeof(char);is.read(name, sizeof(name);is.read(id, sizeof(id);is.read(char*)stu.fScore, sizeof(float)*3);is.read(char*)&stu.fAve, sizeof(float);strncpy(stu.strName, name, sizeof(name);strncpy(stu.strID, id, sizeof(id);return is;class CStudentFilepublic:CStudentFile(char* filename);CStudentFile();voidAdd(CStudentRec stu);/ 添加記錄voidDelete(char* id);/ 刪除學(xué)號(hào)為id的記錄voidUpdate(int nRec, CStudentRec stu);/ 更新記錄號(hào)為nRec的內(nèi)容,nRec從0開始 intSeek(char* id, CStudentRec &stu);/ 按學(xué)號(hào)查找, 返回記錄號(hào),-1表示沒有找到 intGetRecCount(void);/ 獲取文件中的記錄數(shù)intGetStuRec( CStudentRec* data );/ 獲取所有記錄,返回記錄數(shù)private:char*strFileName;/ 文件名;/ CStudentFile類的實(shí)現(xiàn)CStudentFile:CStudentFile(char* filename)strFileName = new charstrlen(filename)+1;strcpy(strFileName, filename);CStudentFile:CStudentFile()if (strFileName) delete strFileName;void CStudentFile:Add(CStudentRec stu)/ 打開文件用于添加fstream file(strFileName, ios:out|ios:app|ios:binary );filestu;file.close();void CStudentFile:Delete(char *id)CStudentRec temp;int nDel = Seek(id, temp); if (nDel0) return;/ 設(shè)置記錄中的chFlag為Ntemp.chFlag = N;Update( nDel, temp );void CStudentFile:Update(int nRec, CStudentRec stu)fstream file(strFileName, ios:in|ios:out|ios:binary);/ 二進(jìn)制讀寫方式if (!file) coutthe strFileName file cant open !n;return ; int nSize = sizeof(CStudentRec) - 1;file.seekg( nRec * nSize);filestu;file.close();int CStudentFile:Seek(char* id, CStudentRec& stu)/ 按學(xué)號(hào)查找 int nRec = -1;fstream file(strFileName, ios:in|ios:nocreate);/ 打開文件用于只讀if (!file) coutthe strFileNamestu;if (strcmp(id, stu.strID) = 0) & (stu.chFlag = A)nRec = i;break;i+;file.close();return nRec;intCStudentFile:GetRecCount(void)fstream file(strFileName, ios:in|ios:nocreate);/ 打開文件用于只讀if (!file) coutthe strFileNamedata;if (data.chFlag = A)nRec+;file.close();return nRec;int CStudentFile:GetStuRec( CStudentRec* data)fstream file(strFileName, ios:in|ios:nocreate);/ 打開文件用于只讀if (!file) coutthe strFileNamestu;if (stu.chFlag = A) datanRec = stu;nRec+;file.close();return nRec;/ 文件studentui.h中的內(nèi)容class CStudentUI: public CConUIpublic:CStudentUI();bool InputStuRec(CStudentRec &stu);/ 通過鍵盤輸入記錄void DispStuRecs(CStudentRec *stu, int nNum);/ 顯示nNum個(gè)記錄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 *str5 = 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, str0, 20);strncpy(stu.strID, str1, 10);stu.fAve = (float)0.0;for (int i=0; i3; i+) stu.fScorei = (float)atof(stri+2);stu.fAve += stu.fScorei;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);coutsetw(10) Rec NOsetw(20)Student Namesetw(10) ID;coutsetw(10)Score 1setw(10)Score 2setw(10)Score 3;coutAveragenMaxLine,/ 則可按PageUp和PageDown向上和向下翻頁/ 若nNumnMaxLine,則按ESC鍵退出const int nMaxLine = 20;int nStart, nEnd, nPage = 0, nMaxPages, nRow=0;nMaxPages = (nNum-1)/nMaxLine;/ 最大可顯示的頁數(shù)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; inEnd; i+) if (stui.chFlag = A) _SetCursorPos( 1, nRow );nRow+;cout.setf(ios:left);coutsetw(10)i+1setw(20)stui.strNamesetw(10)stui.strID;coutsetw(10)stui.fScore0setw(10)stui.fScore1setw(10)stui.fScore2;coutstui.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 );coutPAGE: nPage RECS: nNum;cout.flush();_SetForeColor( nBkColor );cout PL. press PAGEUP or;cout.flush();/ 恢復(fù)原來的顏色設(shè)置_SetBackColor( nBkColor );_SetForeColor( nForeColor );for(;)ch = _GetKeyChar();/ 當(dāng)按下ESC退出if (ch = VK_ESCAPE) return;if (ch = VK_PRIOR ) / PAGEUP鍵nPage-;if (nPagenMaxPages) nPage = nMaxPages;break;/*用于控制臺(tái)窗口界面設(shè)計(jì),版本1.02002 - 20032006.5(1) 添加了控制臺(tái)窗口的字體設(shè)計(jì),(2) 添加了邊框型式,(3) 添加主框架窗口的界面*/#include #include #include #include #include #include typedef struct CONSOLE_FONT DWORD index; COORD dim; *PCONSOLE_FONT; typedef BOOL (WINAPI *GetConsoleFontInfoFunc)(HANDLE,BOOL,DWORD,PCONSOLE_FONT); typedef COORD (WINAPI *GetConsoleFontSizeFunc)(HANDLE, DWORD); typedef BOOL (WINAPI *GetCurrentConsoleFontFunc)(HANDLE, BOOL, PCONSOLE_FONT); typedef DWORD (WINAPI *GetNumberOfConsoleFontsFunc)(); typedef BOOL (WINAPI *SetConsoleFontFunc)(HANDLE, DWORD); GetConsoleFontInfoFunc pGetConsoleFontInfo; GetConsoleFontSizeFunc pGetConsoleFontSize; GetCurrentConsoleFontFunc pGetCurrentConsoleFont; GetNumberOfConsoleFontsFunc pGetNumberOfConsoleFonts; SetConsoleFontFunc pSetConsoleFont; PCONSOLE_FONT fonts = NULL; int GetAvailableFonts(HANDLE hCon,PCONSOLE_FONT *fonts) int fontcount = pGetNumberOfConsoleFonts(); *fonts = new CONSOLE_FONTfontcount; pGetConsoleFontInfo(hCon,0,fontcount,*fonts); return fontcount; BOOL SetFont(HANDLE hCon,int index) if (!pSetConsoleFont(hCon,index) return FALSE; return TRUE; BOOL Init() HINSTANCE hLib = NULL; BOOL bRet = TRUE; hLib = LoadLibrary(KERNEL32.DLL); if (hLib = NULL) return FALSE; pGetConsoleFontInfo = (GetConsoleFontInfoFunc)GetProcAddress(hLib,GetConsoleFontInfo); pGetConsoleFontSize = (GetConsoleFontSizeFunc)GetProcAddress(hLib,GetConsoleFontSize); pGetCurrentConsoleFont = (GetCurrentConsoleFontFunc)GetProcAddress(hLib,GetCurrentConsoleFont); pGetNumberOfConsoleFonts = (GetNumberOfConsoleFontsFunc)GetProcAddress(hLib,GetNumberOfConsoleFonts); pSetConsoleFont = (SetConsoleFontFunc)GetProcAddress(hLib,SetConsoleFont); return bRet; class CConsolepublic:CConsole();CConsole();void _ClearWindow(void);/ 清除當(dāng)前窗口文本,并將光標(biāo)移至左上角,即位置(0,0)void _DefineWindow(int left, int top, int right, int bottom);/ 重新定義一個(gè)窗口,使得所有操作都與這個(gè)窗口有關(guān)void _GetConwinSize(int *sizex, int *sizey);/ 返回控制臺(tái)窗口的大小void _GetWindowSize(int *sizex, int *sizey);/ 返回當(dāng)前窗口的大小void _SaveWindow(void);/ 將當(dāng)前窗口內(nèi)容保存到內(nèi)存中void _SaveWindow(CHAR_INFO *buf);/ 將當(dāng)前窗口內(nèi)容保存到指定內(nèi)存中void _PutWindow(int absX, int absY);/ 將內(nèi)存的內(nèi)容寫到指定位置處,(absX,absY)是絕對(duì)坐標(biāo)void _PutWindow(int absX, int absY, CHAR_INFO *buf);/ 將指定內(nèi)容寫到指定位置處,(absX,absY)是絕對(duì)坐標(biāo)void _DrawBox(int x, int y, int length, int height, int mode = 0);/ 在指定位置(x, y)繪制一個(gè)長為length,寬為height的框,/ 當(dāng)mode為0是單線,1為雙線,2為混合,其它為單線void _FillBox(int x, int y, int length, int height, bool solid = true);/ 填充指定范圍的區(qū)域,若solid為true則擦除原來區(qū)域內(nèi)容, 否則不擦除void _DrawCharLine(int x, int y, int length, char ch);/ 在指定位置(x, y)繪制一個(gè)長為length字符線條,字符由ch指定void _SaveSettings(void);/ 保存當(dāng)前的屬性:光標(biāo)、顏色和窗口void _LoadSettings(void);/ 恢復(fù)_SaveSettings保存的屬性void _ShowCursor(bool show = true);/ 顯示/隱藏光標(biāo)void _OutText(char *str, int nch = -1);/ 在當(dāng)前光標(biāo)處輸出nch個(gè)字符void _OutTextXY(int x, int y, char *str, int nch = -1);/ 在指定位置處輸出nch個(gè)字符void _SetCursorPos(int x, int y);/ 將光標(biāo)移動(dòng)到指定位置void _GetCursorPos(int *x, int *y);/ 獲取當(dāng)前光標(biāo)的位置void _SetBackColor(int color);/ 設(shè)置當(dāng)前背景色int _GetBackColor(void);/ 獲取當(dāng)前背景色void _SetForeColor(int color);/ 設(shè)置當(dāng)前前景色int _GetForeColor(void);/ 獲取當(dāng)前前景色/ 當(dāng)color = 0表示 黑色/ 當(dāng)color = 1表示 藍(lán)色/ 當(dāng)color = 2表示 綠色/ 當(dāng)color = 3表示 青色/ 當(dāng)color = 4表示 紅色/ 當(dāng)color = 5表示 洋紅/ 當(dāng)color = 6表示 綜色/ 當(dāng)color = 7表示 淡灰/ 當(dāng)color = 8表示 深灰/ 當(dāng)color = 9表示 淡藍(lán)/ 當(dāng)color = 10 表示 淡綠/ 當(dāng)color = 11 表示 淡青/ 當(dāng)color = 12 表示 淡紅/ 當(dāng)color = 13 表示 淡洋紅/ 當(dāng)color = 14 表示 黃色/ 當(dāng)color = 15 表示 白色unsigned int _GetKeyChar(void);/ 返回用戶按鍵的字符,不等待,沒有按鍵時(shí)返回0,/ 若是非打印字符,返回虛擬鍵碼int _GetMouse(int *mx, int *my, int *state);/ 獲取鼠標(biāo)位置(*mx, *my),鼠標(biāo)按鈕操作狀態(tài)*state, 1時(shí)為單擊,2時(shí)為雙擊/ 返回鼠標(biāo)操作的按鈕,5為最右鍵,1為最左鍵,2為第2個(gè)鍵,依次類推,一直到4/ 沒有鼠標(biāo)信息或不在當(dāng)前窗口范圍時(shí)返回-1,沒有按下鼠標(biāo)按鈕,返回0private:HANDLEhOut;/ 輸出句柄HANDLEhIn;/ 輸入句柄SMALL_RECTrcWindow;/ 窗口WORDbkColor16;/ 背景顏色WORDfoColor16;/ 前景顏色intbkColorIndex, foColorIndex;/ 顏色索引值intnSaveColor2;/ 保存顏色intnSavePos2;/ 保存光標(biāo)位置boolbSaveShow;/ 保存光標(biāo)是否顯示SMALL_RECT rcSave;/ 保存窗口boolbSaved;/ 是否可以調(diào)用_LoadSettingsCHAR_INFOcharInfo100*40;/ 保存窗口內(nèi)容unsigned int nMaxCols, nMaxRows;/ 最大的行和列;/ CConsole類實(shí)現(xiàn)代碼CConsole:CConsole()hOut = GetStdHandle(STD_OUTPUT_HANDLE);/ 獲取標(biāo)準(zhǔn)輸出設(shè)備句柄hIn = GetStdHandle(STD_INPUT_HANDLE);/ 獲取標(biāo)準(zhǔn)輸入設(shè)備句柄 / 設(shè)置默認(rèn)字體PCONSOLE_FONT fonts = NULL; HANDLE hConsole = GetStdHandle( STD_ERROR_HANDLE ); Init(); int count = GetAvailableFonts(hConsole,&fonts); SetFont(hConsole,fontscount-1.index); SetConsoleOutputCP(437);/ 設(shè)置代碼頁SMALL_RECT rc = 0,0, 80-1, 25-1;rcWindow = rc;/ 定義默認(rèn)的窗口大小COORD size = 80, 25;SetConsoleScreenBufferSize(hOut,size);/ 設(shè)置緩沖區(qū)大小SetConsoleWindowInfo(hOut,true ,&rc);/ 顯示全部控制臺(tái)窗口/ 定義顏色foColor0 = bkColor0 = 0;foColor1 = FOREGROUND_BLUE;foColor2 = FOREGROUND_GREEN;foColor3 = FOREGROUND_BLUE | FOREGROUND_GREEN;foColor4 = FOREGROUND_RED;foColor5 = FOREGROUND_RED | FOREGROUND_BLUE;foColor6 = FOREGROUND_RED | FOREGROUND_GREEN;foColor7 = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;bkColor1 = BACKGROUND_BLUE;bkColor2 = BACKGROUND_GREEN;bkColor3 = BACKGROUND_BLUE | BACKGROUND_GREEN;bkColor4 = BACKGROUND_RED;bkColor5 = BACKGROUND_RED | BACKGROUND_BLUE;bkColor6 = BACKGROUND_RED | BACKGROUND_GREEN;bkColor7 = BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE;for (int i=0; i=7; i+)foColori+8 = foColori + FOREGROUND_INTENSITY; bkColori+8 = bkColori + BACKGROUND_INTENSITY; bkColorIndex = 15;/ 白色foColorIndex = 0; / 黑色SetConsoleTextAttribute(hOut, bkColorbkColorIndex|foColorfoColorIndex);_ClearWindow();_SetCursorPos(0, 0);bSaved = false;nMaxCols = nMaxRows = 0;CConsole:CConsole()CloseHandle(hOut);/ 關(guān)閉標(biāo)準(zhǔn)輸出設(shè)備句柄CloseHandle(hIn);/ 關(guān)閉標(biāo)準(zhǔn)輸入設(shè)備句柄void CConsole:_DrawCharLine(int x, int y, int length, char ch)COORD pos = rcWindow.Left + x, rcWindow.Top + y;CONSOLE_SCREEN_BUFFER_INFO bInfo; GetConsoleScreenBufferInfo( hOut, &bInfo );WORD att = bInfo.wAttributes;for (int i = 0; i5) mode = 0;if (mode = 0) / 單線chBox0 = (char)0xda;/ 左上角點(diǎn)chBox1 = (char)0xbf;/ 右上角點(diǎn)chBox2 = (char)0xc0;/ 左下角點(diǎn)chBox3 = (char)0xd9;/ 右下角點(diǎn)chBox4 = (char)0xc4;/ 水平chBox5 = (char)0xc4;/ 水平chBox6 = (char)0xb3;/ 堅(jiān)直 else if (mode = 1)/ 雙線chBox0 = (char)0xc9;/ 左上角點(diǎn)chBox1 = (char)0xbb;/ 右上角點(diǎn)chBox2 = (char)0xc8;/ 左下角點(diǎn)chBox3 = (char)0xbc;/ 右下角點(diǎn)chBox4 = (char)0xcd;/ 水平chBox5 = (char)0xcd;/ 水平chBox6 = (char)0xba;/ 堅(jiān)直 else if (mode = 2)/ 混合, 上雙余單chBox0 = (char)0xd5;/ 左上角點(diǎn)chBox1 = (char)0xb8;/ 右上角點(diǎn)chBox2 = (char)0xc0;/ 左下角點(diǎn)chBox3 = (char)0xd9;/ 右下角點(diǎn)chBox4 = (char)0xcd;/ 上水平chBox5 = (char)0xc4;/ 下水平chBox6 = (char)0xb3;/ 堅(jiān)直 else if (mode = 3)/ 混合, 上單雙余chBox0 = (char)0xd6;/ 左上角點(diǎn)chBox1 = (char)0xb7;/ 右上角點(diǎn)chBox2 = (char)0xc8;/ 左下角點(diǎn)chBox3 = (char)0xbc;/ 右下角點(diǎn)chBox4 = (char)0xc4;/ 上水平chBox5 = (char)0xcd;/ 下水平chBox6 = (char)0xba;/ 堅(jiān)直 else if (mode = 4)/ 混合, 下單余雙chBox0 = (char)0xc9;/ 左上角點(diǎn)chBox1 = (char)0xbb;/ 右上角點(diǎn)chBox2 = (char)0xd3;/ 左下角點(diǎn)chBox3 = (char)0xbd;/ 右下角點(diǎn)chBox4 = (char)0xcd;/ 上水平chBox5 = (char)0xc4;/ 下水平chBox6 = (char)0xba;/ 堅(jiān)直 else if (m

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論