




版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
1、/ StudentInformationSystem.cpp : Defines the entry point for the console application./#include "stdafx.h"#include <cstring>#include <iostream>#include <conio.h>#include<vector>#include<algorithm>class Studentprivate: char idNumber13; /學號char name30; /姓名char ad
2、dress50; /地址char telephone14; /電話號碼int gradeMath; /數(shù)學成績int gradePhysics; /物理成績int gradeEnglish; /英語成績double gradeMaPhEgAverage; /物數(shù)外平均int rankGrade; /成績排名int gradeClassmate; /同學評分int gradeTeacher; /老師評分int gradeEthic; /道德評分double gradeAll; /綜合成績int rankAll; /綜合排名public:Student(); /默認構造函數(shù)void Student
3、_WritePersonalInformation(char *iD, char *nam, char *add, char *tel); /更改學生信息void Student_WriteMaPhEgGrade(int graMa, int graPh, int graEg); /更改學生考試成績void Student_WriteOtherGrade(int graCl, int graTe, int graEth); /更改學生其他成績void Student_DisplayInformation(); /顯示學生信息char *Student_ReadID();double Stude
4、nt_ReadGrade();double Student_ReadTotalGrade();int Student_ReadGradeRank();int Student_ReadTotalGradeRank();void Student_WriteGradeRank(int ranGr); /更改學生成績排名void Student_WriteTotalGradeRank(int ranAl); /更改學生綜合排名char *Student_ReadName();Student:Student() /默認構造函數(shù)strncpy_s(idNumber, "000000000000&
5、quot;,12);strncpy_s(name,"空",30);strncpy_s(address, "空", 50);strncpy_s(telephone, "空", 14); /電話號碼gradeMath=0; /數(shù)學成績gradePhysics=0; /物理成績gradeEnglish=0; /英語成績gradeMaPhEgAverage=0; /物數(shù)外平均rankGrade=0; /成績排名gradeClassmate=0; /同學評分gradeTeacher=0; /老師評分gradeEthic=0; /道德評分 gra
6、deAll=0; /綜合成績rankAll=0; /綜合排名 void Student:Student_WritePersonalInformation(char *iD, char *nam, char *add, char *tel)strncpy_s(idNumber,iD,12);strncpy_s(name, nam, 30);strncpy_s(address, add,50);strncpy_s(telephone, tel, 14);void Student:Student_WriteMaPhEgGrade(int graMa, int graPh, int graEg)gra
7、deMath = graMa;gradePhysics = graPh;gradeEnglish = graEg;gradeMaPhEgAverage = (gradeMath + gradePhysics + gradeEnglish) / 3;void Student:Student_WriteOtherGrade(int graCl, int graTe, int graEth)gradeClassmate = graCl;gradeTeacher = graTe;gradeEthic = graEth;gradeAll = gradeMaPhEgAverage*0.6 + gradeC
8、lassmate*0.1 + gradeEthic*0.1 + gradeTeacher*0.2;void Student:Student_WriteGradeRank(int ranGr)rankGrade = ranGr;void Student:Student_WriteTotalGradeRank(int ranAl)rankAll = ranAl;void Student:Student_DisplayInformation()using namespace std;cout << "-" << endl;cout << &qu
9、ot; 學生信息 " << endl;cout << "姓名:" << name << endl<< "學號:" << idNumber << endl<< "地址:" << address << endl<< "電話:" << telephone << endl << "數(shù)學成績:" << gradeMat
10、h << endl<< "物理成績:" << gradePhysics << endl<< "英語成績:" << gradeEnglish << endl<< "三科平均成績:" << gradeMaPhEgAverage << endl<< "學習成績排名:" << rankGrade << endl<< "同學評價得分:" &
11、lt;< gradeClassmate << endl<< "教師評價得分:" << gradeTeacher << endl<< "道德修養(yǎng)評分:" << gradeEthic << endl<< "綜合成績:" << gradeAll << endl<< "綜合成績排名:" << rankAll << endl;cout << "
12、-" << endl;char *Student:Student_ReadID()return idNumber;double Student:Student_ReadGrade()return gradeMaPhEgAverage;double Student:Student_ReadTotalGrade()return gradeAll;int Student:Student_ReadGradeRank()return rankGrade;int Student:Student_ReadTotalGradeRank()return rankAll;namespace
13、studentInformationstd:vector<Student> studentVector;int flagStudentChoose=0;int flagStudentFound=1;char *Student:Student_ReadName()return name;/-以上是基本數(shù)據(jù)結構的定義,同時定義了對數(shù)據(jù)的基本操作。定義完畢了,接下來是功能函數(shù)-void MainMenu();void EditMenu();void AddStudentPersonalInformation(int mode);void ModifyStudentInformation(
14、);void SearchStudent();void DeleteStudentInformation();void DisplayStudentInformation();void RankByGrade();void RankByTotalGrade();void RankByID();bool CmpGrade(Student student1,Student student2); /這個函數(shù)的參數(shù)是兩個Student類的對象bool CmpTotalGrade(Student student1, Student student2);bool CmpID(Student student
15、1, Student student2);void DisplayAllStudentInformation();/-以下是主菜單界面函數(shù)-void MainMenu()int flagOperateInformation = 1;while (flagOperateInformation)using namespace std;cout << "-" << endl;cout << "歡迎進入學生信息管理系統(tǒng)V1.0." << endl << endl;cout << "
16、按下1:進入學生信息管理系統(tǒng)." << endl;cout << "按下0:退出." << endl;cout << "-" << endl<<endl<<endl;cin >> flagOperateInformation;cin.clear();cout << endl;if (flagOperateInformation)EditMenu();/-主菜單界面函數(shù)定義完畢-/-以下是編輯界面函數(shù)-void EditMenu()int
17、flagContinueOperation = 1;while (flagContinueOperation)flagContinueOperation = 0;using namespace std;cout << "-" << endl;cout << " 主菜單 " << endl;cout << "按下1:添加學生信息." << endl;cout << "按下2:修改學生信息." << endl;cout &l
18、t;< "按下3:刪除學生信息." << endl;cout << "按下4:顯示學生信息." << endl;cout << "按下5:按學號升序排序" << endl;cout << "按下6:讀入已有信息(暫時沒實現(xiàn))" << endl;cout << "按下7:將信息輸出(暫時沒實現(xiàn))" << endl;cout << "按下8:顯示系統(tǒng)內(nèi)所有學生的信息
19、" << endl;cout << "按下0:返回上一級." << endl;cout << "-" << endl << endl;cin >> flagContinueOperation;cin.clear();cout << endl;switch (flagContinueOperation) case 1:AddStudentPersonalInformation(1); break;case 2:ModifyStudentInformat
20、ion(); break;case 3:DeleteStudentInformation(); break;case 4:DisplayStudentInformation(); break;case 5:RankByID(); break;case 6:cout << "功能暫未實現(xiàn)" << endl; break;case 7:cout << "功能暫未實現(xiàn)" << endl; break;case 8:DisplayAllStudentInformation(); break; case 0:brea
21、k;/-/-以下是添加信息的界面-void AddStudentPersonalInformation(int mode)using namespace std;int flagAddPersonalInformation;int flagAddGrade;int falgAddOtherGrade;Student student1;studentInformation:studentVector.push_back(student1);int currentObjectPosition;if (mode = 1)currentObjectPosition = studentInformati
22、on:studentVector.size() - 1;elsecurrentObjectPosition = studentInformation:flagStudentChoose;/-cout << "請依次添加基本信息、學習成績和其他成績,且不要使用空格" << endl;cout << "-" << endl;cout << " 基本信息 " << endl;cout << "按下1:錄入學生基本信息;" <<
23、 endl<< "按下0:跳過基本信息。"<<endl<<"-"<<endl;cin >> flagAddPersonalInformation;cin.clear();if (flagAddPersonalInformation)char name30;char iD13;char address50;char phone14;cout << "請輸入學生姓名:"cin >> name;cin.clear();cout << "
24、請輸入學生學號:"cin >> iD;cin.clear();cout << "請輸入學生地址:"cin >> address;cin.clear();cout << "請輸入學生電話:"cin >> phone;cin.clear();studentInformation:studentVectorcurrentObjectPosition.Student_WritePersonalInformation(iD,name,address,phone);cout << &q
25、uot;基本信息輸入成功!" << endl<< "-" << endl;/-cout << "-" << endl;cout << " 學習成績 " << endl;cout << "按下1:錄入學生學習成績;" << endl<< "按下0:跳過學習成績信息。" << endl<< "-" << endl;c
26、in >> flagAddGrade;cin.clear();if (flagAddGrade)int mathGrade;int physicsGrade;int englishGrade;cout << "請輸入數(shù)學成績:"cin >> mathGrade;cin.clear();cout << "請輸入物理成績:"cin >> physicsGrade;cin.clear();cout << "請輸入英語成績:"cin >> englishGra
27、de;cin.clear();studentInformation:studentVectorcurrentObjectPosition.Student_WriteMaPhEgGrade(mathGrade, physicsGrade, englishGrade);cout << "學習成績輸入成功!" << endl<< "-" << endl;/-cout << "-" << endl;cout << " 其他成績 " <
28、< endl;cout << "按下1:錄入學生其他成績;" << endl<< "按下0:跳過其他成績信息。" << endl<< "-" << endl;cin >> flagAddGrade;cin.clear();if (flagAddGrade)int peerGrade;int teacherGrade;int ethicGrade;cout << "請輸入同學評議成績:"cin >> pe
29、erGrade;cin.clear();cout << "請輸入教師評議成績:"cin >> teacherGrade;cin.clear();cout << "請輸入道德測評成績成績:"cin >> ethicGrade;cin.clear();studentInformation:studentVectorcurrentObjectPosition.Student_WriteOtherGrade(peerGrade, teacherGrade, ethicGrade);cout << &qu
30、ot;其他成績輸入成功!" << endl<< "-" << endl;RankByGrade();RankByTotalGrade();cout << "學生成績錄入成功!" << endl;cout << "-" << endl<<endl;void SearchStudent()using namespace std;using namespace studentInformation;char ID13;cout <
31、< "請輸入學生的學號:"<<endl;cin >> ID;cin.clear();cout << "-"<<endl;int vectorSize = studentVector.size();int i = 0;while (i<vectorSize) & (flagStudentFound!=0)flagStudentFound = strcmp(ID, studentVectori.Student_ReadID();i = i + 1;if (flagStudentFound =
32、 0)flagStudentChoose = i - 1;flagStudentFound = 1;cout << "您所查找的學生信息如下:"<<endl;studentVectorflagStudentChoose.Student_DisplayInformation();elsecout << "未找到該學生" << endl;void ModifyStudentInformation()using namespace std;using namespace studentInformation;in
33、t searchVectorSize = studentVector.size();if (searchVectorSize = 0)cout << "-" << endl;cout << "當前系統(tǒng)中沒有學生信息,請先添加學生信息!" << endl;cout << "-" << endl;elseSearchStudent(); cout << "您想對該學生的信息進行修改嗎?" << endl;cout <&
34、lt; "按下1:是的。" << endl;cout << "按下0:放棄修改。" << endl;cout << "-" << endl;int flagModify;cin >> flagModify;cin.clear();if (flagModify = 1)&(flagStudentFound = 0)AddStudentPersonalInformation(2);void DeleteStudentInformation()using nam
35、espace std;using namespace studentInformation;int deleteVectorSize = studentVector.size();if (deleteVectorSize = 0)cout << "-" << endl;cout << "當前系統(tǒng)中沒有學生信息,請先添加學生信息!" << endl;cout << "-" << endl;elseSearchStudent();cout << "
36、;您想刪除該學生的信息嗎?" << endl;cout << "按下1:刪除。" << endl;cout << "按下0:取消。" << endl;cout << "-" << endl;int flagModify;cin >> flagModify;cin.clear();if (flagModify = 1)&(flagStudentFound = 0)std:vector<Student>:itera
37、tor iter = studentVector.begin() + flagStudentChoose; /這樣就選中了一個查到的元素studentVector.erase(iter);cout << "學生信息刪除成功!" << endl<< "-" << endl;void DisplayStudentInformation()using namespace std;using namespace studentInformation;int displayVectorSize = studentVe
38、ctor.size();if (displayVectorSize = 0)cout << "-" << endl;cout << "當前系統(tǒng)中沒有學生信息,請先添加學生信息!" << endl;cout << "-" << endl;elseSearchStudent();if (flagStudentFound = 0)studentVectorflagStudentChoose.Student_DisplayInformation();bool CmpGra
39、de(Student student1, Student student2)return student1.Student_ReadGrade() > student2.Student_ReadGrade(); /如果student1成績大于student2,則返回1.這樣能實現(xiàn)成績的降序排列void RankByGrade()using namespace studentInformation;using namespace std;int rankVectorSize = studentVector.size();if (rankVectorSize = 1)studentVecto
40、r0.Student_WriteGradeRank(1);elsesort(studentVector.begin(), studentVector.end(), CmpGrade); /使用sort必須加上#include algorithm和std。sort的前兩個參數(shù)是指針int i = 0;for (i = 0; i <= rankVectorSize-1; i+)if (i>=1)&&(studentVectori.Student_ReadGrade() = studentVectori - 1.Student_ReadGrade()studentVect
41、ori.Student_WriteGradeRank(studentVectori - 1.Student_ReadGradeRank();elsestudentVectori.Student_WriteGradeRank(i + 1);bool CmpTotalGrade(Student student1, Student student2)return student1.Student_ReadTotalGrade() > student2.Student_ReadTotalGrade(); /如果student1成績大于student2,則返回1.這樣能實現(xiàn)成績的降序排列void
42、RankByTotalGrade()using namespace studentInformation;using namespace std;int rankVectorSize = studentVector.size();if (rankVectorSize = 1)studentVector0.Student_WriteTotalGradeRank(1);elsesort(studentVector.begin(), studentVector.end(), CmpGrade); /使用sort必須加上#include algorithm和std。sort的前兩個參數(shù)是指針int i
43、 = 0;for (i = 0; i <= rankVectorSize - 1; i+)if (i >= 1) && (studentVectori.Student_ReadTotalGrade() = studentVectori - 1.Student_ReadTotalGrade()studentVectori.Student_WriteTotalGradeRank(studentVectori - 1.Student_ReadTotalGradeRank();elsestudentVectori.Student_WriteTotalGradeRank(i
44、+ 1);bool CmpID(Student student1, Student student2)int result;result = strcmp(student1.Student_ReadID(), student2.Student_ReadID();if (result<0)return true;elsereturn false;void RankByID()using namespace studentInformation;using namespace std;int rankVectorSize = studentVector.size();sort(student
45、Vector.begin(), studentVector.end(), CmpID);cout << "-" << endl;cout << "排序成功!" << endl;cout << "-" << endl;void DisplayAllStudentInformation()using namespace std;using namespace studentInformation;int displayVectorSize = studentVecto
46、r.size();int i;if (displayVectorSize = 0)cout << "-" << endl;cout << "當前系統(tǒng)中沒有學生信息!" << endl;cout << "-" << endl;elsecout << "-" << endl;cout << "姓名 學號 綜合成績 綜合排名" << endl;for (i = 0; i < d
47、isplayVectorSize; i+)cout << studentVectori.Student_ReadName() << " "<< studentVectori.Student_ReadID() << " "<< studentVectori.Student_ReadTotalGrade() << " "<< studentVectori.Student_ReadTotalGradeRank() << endl;cout <
48、;< "-" << endl;/-以下是主函數(shù)-void main()MainMenu();/*-下面的這是一個排序函數(shù),用到了冒泡排序法,但是程序沒用到。上面的排序用了sort()函數(shù)來實現(xiàn),功能是一樣的。*/*void RankByGrade()using namespace studentInformation;using namespace std;int flagCompareOut=0;int flagCompareIn=0;int rankVectorSize;rankVectorSize = studentVector.size();if
49、(rankVectorSize = 0)cout << "-" << endl<< "系統(tǒng)當前沒有學生信息!" << endl<< "-" << endl;else if (rankVectorSize = 1)studentVectorflagCompareOut.Student_WriteGradeRank(flagCompareOut + 1);elseint flagCompareOut = 0;int flagCompareIn = 0;for (fla
50、gCompareOut = 0; flagCompareOut < rankVectorSize - 1; flagCompareOut+)for (flagCompareIn = 0; flagCompareIn < rankVectorSize - flagCompareOut - 1; flagCompareIn+)if (studentVectorflagCompareIn.Student_ReadGrade() < studentVectorflagCompareIn + 1.Student_ReadGrade()Student studentTemp;studentTe
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年甘肅省平?jīng)鍪徐o寧一中高三下學期摸底測試語文試題含解析
- 智能調(diào)度與路徑優(yōu)化-全面剖析
- 區(qū)塊鏈應用規(guī)范-全面剖析
- 社交媒體營銷對品牌認知影響-全面剖析
- 數(shù)字旅游發(fā)展趨勢-全面剖析
- 知識產(chǎn)權交易中的價值評估方法-全面剖析
- 棗莊市山亭區(qū)實驗中學招聘真題2024
- 天津職業(yè)技術師范大學招聘真題2024
- 共享經(jīng)濟中的用戶責任界定與經(jīng)濟法治化-全面剖析
- 磁盤介質(zhì)故障檢測技術-全面剖析
- 提高施工現(xiàn)場從業(yè)人員隱患上報(舉報)率 -4:3
- 戲劇常識知識考試試題題庫及答案
- 斷絕父子關系協(xié)議書
- 小牛在線2018第四季度營銷方案20181106
- 職業(yè)院?!敖鹫n”建設方案
- 醫(yī)療護理員基礎理論知識考試試題題庫及答案
- JT-T-1051-2016城市軌道交通運營突發(fā)事件應急預案編制規(guī)范
- 山東省濟南市槐蔭中區(qū)2023-2024學年八年級下學期期中考試物理試卷
- 藝術中國智慧樹知到期末考試答案2024年
- 30道計量員崗位常見面試問題含HR問題考察點及參考回答
- (正式版)YST 1694-2024 鉛冶煉企業(yè)節(jié)能診斷技術規(guī)范
評論
0/150
提交評論