




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
綜合實(shí)驗(yàn)要求編寫一個小型學(xué)生信息管理系統(tǒng),可以對中學(xué)生、大學(xué)生和研究生的信息進(jìn)行簡單管理。每一類學(xué)生都包含有學(xué)生的學(xué)生名、成績1、成績2、成績3和平均成績,其中平均成績=〔成績1+成績2+成績3〕/3。每一類學(xué)生還有區(qū)別與其他類學(xué)生的特殊信息,中學(xué)生有家長,大學(xué)生有專業(yè),研究生有導(dǎo)師。實(shí)現(xiàn)以下功能:輸入學(xué)生的根本信息;根據(jù)學(xué)生名查詢某個學(xué)生的信息;計算并顯示某個學(xué)生的平均成績;一、系統(tǒng)分析1、根本信息類的屬性和操作1)屬性學(xué)生類別編號、學(xué)生名、成績1、成績2、成績3、平均成績〔為了方便信息的讀取,程序中給每類學(xué)生設(shè)置了一個學(xué)生類別編號,以便區(qū)別各類學(xué)生〕2)操作數(shù)據(jù)輸入:輸入學(xué)生名、成績1、成績2和成績3;數(shù)據(jù)輸出:輸出學(xué)生類別編號、姓名、成績1、成績2和成績3;計算平均成績:平均成績=〔成績1+成績2+成績3〕/3。2、中學(xué)生類的屬性和操作1〕屬性繼承根本信息類的屬性,并增加中學(xué)生類區(qū)別于其他學(xué)生類的特殊屬性,即家長。2〕操作數(shù)據(jù)輸入:繼承根本信息類的數(shù)據(jù)輸入操作,并增加輸入“家長〞、信息的功能。數(shù)據(jù)輸出:繼承根本信息類的數(shù)據(jù)輸出操作,并增加輸出“家長〞、信息的功能。3、大學(xué)生類的屬性和操作1〕屬性繼承根本信息類的屬性,并增加大學(xué)生類區(qū)別于其他學(xué)生類的特殊屬性,即專業(yè)。2〕操作數(shù)據(jù)輸入:繼承根本信息類的數(shù)據(jù)輸入操作,并增加輸入“專業(yè)〞、信息的功能。數(shù)據(jù)輸出:繼承根本信息類的數(shù)據(jù)輸出操作,并增加輸出“專業(yè)〞、信息的功能。4、研究生屬性和操作1〕屬性繼承根本信息類的屬性,并增加研究生類區(qū)別于其他學(xué)生類的特殊屬性,即導(dǎo)師。2〕操作數(shù)據(jù)輸入:繼承根本信息類的數(shù)據(jù)輸入操作,并增加輸入“導(dǎo)師〞、信息的功能。數(shù)據(jù)輸出:繼承根本信息類的數(shù)據(jù)輸出操作,并增加輸出“導(dǎo)師〞、信息的功能。5、系統(tǒng)管理類操作系統(tǒng)管理類自成一個類:系統(tǒng)管理類。主要操作有:輸入學(xué)生根本信息;根據(jù)學(xué)生姓名查詢某個學(xué)生的信息;計算并顯示某個學(xué)生的平均成績。二、系統(tǒng)設(shè)計1、基類和派生類的設(shè)計基類Record(根本信息類):num(學(xué)生類別編號)、name〔學(xué)生名〕、score1〔成績1〕、score2〔成績2〕、score3〔成績3〕、average〔平均成績〕。Student〔中學(xué)生類〕:從基類繼承來的屬性、patriarch〔家長〕。U_student〔大學(xué)生類〕:從基類繼承來的屬性、major〔專業(yè)〕。Graduate〔研究生類〕:從基類繼承來的屬性、mentor〔導(dǎo)師〕。System〔系統(tǒng)管理類〕:成員函數(shù)In_information負(fù)責(zé)輸入學(xué)生信息,成員函數(shù)Search查詢學(xué)生信息,成員函數(shù)Out_average計算并顯示平均成績,成員函數(shù)Interface負(fù)責(zé)界面輸出。2、系統(tǒng)管理類設(shè)計〔1〕將數(shù)據(jù)文件信息讀入內(nèi)存對象數(shù)組程序一啟動,由System的構(gòu)造函數(shù)自動調(diào)用函數(shù)readFile完成?!?〕信息的輸入成員函數(shù)In_information根據(jù)要輸入學(xué)生的類別分別調(diào)用對應(yīng)的學(xué)生信息輸入功能函數(shù)完成輸入?!?〕成員函數(shù)Search接收從鍵盤輸入的學(xué)生類別和學(xué)生名,在對應(yīng)的對象數(shù)組中查找,找到后調(diào)用對象的成員函數(shù)Output顯示學(xué)生信息?!?〕平均成績計算和顯示接收從鍵盤輸入的學(xué)生類別和姓名,然后查找對象數(shù)組,找到后調(diào)用對象的計算平均成績函數(shù)計算平均成績,然后顯示。三、系統(tǒng)實(shí)現(xiàn)頭文件:Record.h、Student.h、U_student.h、Graudate.h、System.h源文件:Record.cpp、Student.cpp、U_student.cpp、Graudate.cpp、System.cpp、main.cpp.程序運(yùn)行的主界面如圖:實(shí)驗(yàn)代碼:頭文件局部://Record.h#ifndef_RECORD_H_#define_RECORD_H_#include<string>#include<vector>usingnamespacestd;classSystem;classRecord{public: Record(){} Record(stringn,floats1,floats2,floats3,floatavg):name(n),score1(s1),score2(s2),score3(s3),average(avg){average=0;}virtualvoidset_inf()=0;virtualvoiddisplay_inf()=0;floatcaculate_avg();friendclassSystem;protected:stringname;floatscore1;floatscore2;floatscore3;floataverage;};#endif//Student.h#ifndef_STUDENT_H_#define_STUDENT_H_#include<string>#include"Record.h"usingnamespacestd;classSystem;classStudent:publicRecord{public: Student(){}//{//set_inf();} Student(stringn,floats1,floats2,floats3,floatavg,stringpa):Record(n,s1,s2,s3,avg),patriarch(pa){}virtualvoidset_inf();virtualvoiddisplay_inf();friendclassSystem;friendifstream&operator>>(ifstream&i,Student&s);friendofstream&operator<<(ofstream&i,Student&s);protected:stringpatriarch;};#endif//U_student.h#ifndef_U_STUDENT_H_#define_U_STUDENT_H_#include<string>#include"Record.h"usingnamespacestd;classSystem;classU_student:publicRecord{public: U_student(){}//{//set_inf();} U_student(stringn,floats1,floats2,floats3,floatavg,stringma):Record(n,s1,s2,s3,avg),major(ma){}virtualvoidset_inf();virtualvoiddisplay_inf();friendclassSystem;friendifstream&operator>>(ifstream&i,U_student&s);friendofstream&operator<<(ofstream&i,U_student&s);protected:stringmajor;};#endif//Graduate.h#ifndef_GRADUATE_H_#define_GRADUATE_H_#include<string>#include"Record.h"usingnamespacestd;classSystem;classGraduate:publicRecord{public: Graduate(){}//{//set_inf();} Graduate(stringn,floats1,floats2,floats3,floatavg,stringme):Record(n,s1,s2,s3,avg),mentor(me){}virtualvoidset_inf();virtualvoiddisplay_inf();friendclassSystem;friendifstream&operator>>(ifstream&i,Graduate&s);friendofstream&operator<<(ofstream&i,Graduate&s);protected:stringmentor;};#endif//System.h#ifndef_SYSTEM_H_#define_SYSTEM_H_classSystem{public: System();voidIn_information();voidSearch();voidOut_average();voidInterface();voidreadfile();voiddelete_inf();voidwritefile();};#endif//源文件局部//Record.cpp#include"Record.h"#include<iostream>usingnamespacestd;floatRecord::caculate_avg(){returnaverage=(score1+score2+score3)/3;}//Student.cpp#include"Student.h"#include<iostream>#include<fstream>usingnamespacestd;voidStudent::set_inf(){ cout<<"姓名:"<<endl; cin>>name; cout<<"成績一:"<<endl; cin>>score1; cout<<"成績二:"<<endl; cin>>score2; cout<<"成績?nèi)?<<endl; cin>>score3; cout<<"家長:"<<endl; cin>>patriarch;this->caculate_avg();}voidStudent::display_inf(){ cout<<"姓名:"<<name<<endl; cout<<"成績一:"<<score1<<endl; cout<<"成績二:"<<score2<<endl; cout<<"成績?nèi)?<<score3<<endl; cout<<"家長:"<<patriarch<<endl;}ifstream&operator>>(ifstream&infile,Student&s){infile>>>>s.score1>>s.score2>>s.score3>>s.average>>s.patriarch;returninfile;}ofstream&operator<<(ofstream&outfile,Student&s){outfile<<<<""<<s.score1<<""<<s.score2<<""<<s.score3<<""<<s.average<<""<<s.patriarch<<endl;returnoutfile;}//U_student.cpp#include"U_student.h"#include<iostream>#include<fstream>usingnamespacestd;voidU_student::set_inf(){ cout<<"姓名:"<<endl; cin>>name; cout<<"成績一:"<<endl; cin>>score1; cout<<"成績二:"<<endl; cin>>score2; cout<<"成績?nèi)?<<endl; cin>>score3; cout<<"專業(yè):"<<endl; cin>>major;this->caculate_avg();}voidU_student::display_inf(){ cout<<"姓名:"<<name<<endl; cout<<"成績一:"<<score1<<endl; cout<<"成績二:"<<score2<<endl; cout<<"成績?nèi)?<<score3<<endl; cout<<"專業(yè):"<<major<<endl;}ifstream&operator>>(ifstream&infile,U_student&s){ infile>>>>s.score1>>s.score2>>s.score3>>s.average>>s.major;returninfile;}ofstream&operator<<(ofstream&outfile,U_student&s){ outfile<<<<""<<s.score1<<""<<s.score2<<"" <<s.score3<<""<<s.average<<""<<s.major<<endl;returnoutfile;}//Graduate.cpp#include"Graduate.h"#include<iostream>#include<fstream>usingnamespacestd;voidGraduate::set_inf(){ cout<<"姓名:"<<endl; cin>>name; cout<<"成績一:"<<endl; cin>>score1; cout<<"成績二:"<<endl; cin>>score2; cout<<"成績?nèi)?<<endl; cin>>score3; cout<<"導(dǎo)師:"<<endl; cin>>mentor;this->caculate_avg();}voidGraduate::display_inf(){ cout<<"姓名:"<<name<<endl; cout<<"成績一:"<<score1<<endl; cout<<"成績二:"<<score2<<endl; cout<<"成績?nèi)?<<score3<<endl; cout<<"導(dǎo)師:"<<mentor<<endl;}ifstream&operator>>(ifstream&infile,Graduate&s){ infile>>>>s.score1>>s.score2>>s.score3>>s.average>>s.mentor;returninfile;}ofstream&operator<<(ofstream&outfile,Graduate&s){ outfile<<<<""<<s.score1<<""<<s.score2<<"" <<s.score3<<""<<s.average<<""<<s.mentor<<endl;returnoutfile;}//System.cpp#include"System.h"#include"Record.h"#include"Student.h"#include"U_student.h"#include"Graduate.h"#include<iostream>#include<fstream>#include<conio.h>#include<iterator>#include"shlwapi.h"#pragmacomment(lib,"shlwapi.lib")#include<iomanip>usingnamespacestd;vector<Student>stu_m;vector<U_student>stu_u;vector<Graduate>stu_g;System::System(){ system("title小型學(xué)生信息管理"); system("color0b");this->readfile();this->Interface();}voidSystem::readfile(){/*HANDLEhFILE1=CreateFileA("中學(xué)生信息.txt",FILE_ATTRIBUTE_READONLY,0,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);*///***** Studenttemp_stu_m;if(!PathFileExistsA("中學(xué)生信息.txt")){CreateFileA(".//中學(xué)生信息.txt",NULL,0,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);} ifstreamiofile1("中學(xué)生信息.txt",ios::in|ios::out);while(!iofile1.eof()) { iofile1>>temp_stu_m; stu_m.push_back(temp_stu_m); } stu_m.pop_back(); iofile1.close();//***** U_studenttemp_stu_u;/*HANDLEhFILE2=CreateFileA("大學(xué)生信息.txt",FILE_ATTRIBUTE_READONLY,0,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);*/if(!PathFileExistsA("大學(xué)生信息.txt")){CreateFileA(".//大學(xué)生信息.txt",NULL,0,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);} ifstreamiofile2("大學(xué)生信息.txt",ios::in|ios::out);while(!iofile2.eof()) { iofile2>>temp_stu_u; stu_u.push_back(temp_stu_u); } stu_u.pop_back(); iofile2.close();//****** Graduatetemp_stu_g;/*HANDLEhFILE3=CreateFileA("研究生信息.txt",FILE_ATTRIBUTE_READONLY,0,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);*/if(!PathFileExistsA("研究生信息.txt")){CreateFileA(".//研究生信息.txt",NULL,0,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);} ifstreamiofile3("研究生信息.txt",ios::in|ios::out);while(!iofile3.eof()) { iofile3>>temp_stu_g; stu_g.push_back(temp_stu_g); } stu_g.pop_back(); iofile3.close();}voidSystem::writefile(){//***** ofstreamiofile4("中學(xué)生信息.txt",ios::in|ios::out|ios::trunc);if(!iofile4){ cerr<<"openerror!"<<endl; system("pause"); exit(0); }for(vector<Student>::iteratorit=stu_m.begin();it!=stu_m.end();it++) { iofile4<<*it; } iofile4.close();//***** ofstreamiofile5("大學(xué)生信息.txt",ios::in|ios::out|ios::trunc);if(!iofile5){ cerr<<"openerror!"<<endl; system("pause"); exit(0); }for(vector<U_student>::iteratorit=stu_u.begin();it!=stu_u.end();it++) { iofile5<<*it; } iofile5.close();//****** ofstreamiofile6("研究生信息.txt",ios::in|ios::out|ios::trunc);if(!iofile6){ cerr<<"openerror!"<<endl; system("pause"); exit(0); }for(vector<Graduate>::iteratorit=stu_g.begin();it!=stu_g.end();it++) { iofile6<<*it; } iofile6.close();}voidSystem::In_information(){intn; cout<<"輸入要創(chuàng)立的學(xué)生類別:"<<endl; cout<<"1.中學(xué)生"<<"2.大學(xué)生"<<"3.研究生"<<endl; cin>>n;if(n==1){ Student*p_s=newStudent; p_s->set_inf(); stu_m.push_back(*(p_s)); }elseif(n==2){ U_student*p_s=newU_student; p_s->set_inf(); stu_u.push_back(*(p_s)); }elseif(n==3){ Graduate*p_s=newGraduate; p_s->set_inf(); stu_g.push_back(*(p_s)); } cout<<endl<<"任意鍵返回"<<endl; _getch();}voidSystem::Search(){ stringna;intn; cout<<"請輸入學(xué)生類別:"<<endl; cout<<"1.中學(xué)生"<<"2.大學(xué)生"<<"3.研究生"<<endl; cin>>n; cout<<"請輸入學(xué)生的名字:"<<endl; cin>>na;if(n==1){inti=0;for(vector<Student>::iteratorit=stu_m.begin();it<stu_m.end();it++){if(it->name==na){i=1;it->display_inf();}if(it==stu_m.end()-1&&i==0){cout<<"沒有信息!"<<endl;break;} } }elseif(n==2){inti=0;for(vector<U_student>::iteratorit=stu_u.begin();it<stu_u.end();it++){if(it->name==na){i=1;it->display_inf();}if(it==stu_u.end()-1&&i==0){cout<<"沒有信息!"<<endl;break;} } }elseif(n==3){inti=0;for(vector<Graduate>::iteratorit=stu_g.begin();it<stu_g.end();it++){if(it->name==na){i=1;it->display_inf();}if(it==stu_g.end()-1&&i==0){cout<<"沒有信息!"<<endl;break;} } } cout<<endl<<"任意鍵返回"<<endl; _getch();}voidSystem::Out_average(){ stringna;intn; cout<<"請輸入學(xué)生類別:"<<endl; cout<<"1.中學(xué)生"<<"2.大學(xué)生"<<"3.研究生"<<endl; cin>>n; cout<<"請輸入學(xué)生的名字:"<<endl; cin>>na;if(n==1){for(vector<Student>::iteratorit=stu_m.begin();it<stu_m.end();it++){if(it->name==na) { cout<<"姓名:"<<it->name<<endl; cout<<"平均成績?yōu)?<<it->caculate_avg()<<endl; } } }elseif(n==2){for(vector<U_student>::iteratorit=stu_u.begin();it<stu_u.end();it++){if(it->name==na){ cout<<"姓名:"<<it->name<<endl; cout<<"平均成績?yōu)?<<it->caculate_avg()<<endl; } } }elseif(n==3){for(vector<Graduate>::iteratorit=stu_g.begin();it<stu_g.end();it++){if(it->name==na){ cout<<"姓名:"<<it->name<<endl; cout<<"平均成績?yōu)?<<it->caculate_avg()<<endl; } } } cout<<endl<<"任意鍵返回"<<endl; _getch();}voidSystem::delete_inf(){ stringna;intn; cout<<"請輸入學(xué)生類別:"<<endl; cout<<"1.中學(xué)生"<<"2.大學(xué)生"<<"3.研究生"<<endl; cin>>n; cout<<"請輸入學(xué)生的名字:"<<endl; cin>>na;if(n==1){for(vector<Student>::iteratorit=stu_m.begin();it<stu_m.end();){if(it->name==na){it=stu_m.erase(it);cout<<"刪除成功!"<<endl;}else{it++;} } }elseif(n==2){for(vector<U_student>::iteratorit=stu_u.begin();it<stu_u.end();){if(it->name==na){it=stu_u.erase(it);cout<<"刪除成功!"<<endl;}else{it++;} } }elseif(n==3){for(vector<Graduate>::iteratorit=stu_g.begin();it<stu_g.end();){if(it->name==na){it=stu_g.erase(it);cout<<"刪除成功!"<<endl;}else{it++;} } } cout
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 【正版授權(quán)】 IEC 63241-2-19:2025 EXV EN Electric motor-operated tools - Dust measurement procedure - Part 2-19: Particular requirements for hand-held jointers
- 黑龍江高三三模數(shù)學(xué)試卷
- 2025屆亳州市重點(diǎn)中學(xué)高二物理第二學(xué)期期末聯(lián)考試題含解析
- 2025年中國電池級金屬鋰行業(yè)市場發(fā)展前景及發(fā)展趨勢與投資戰(zhàn)略研究報告
- 中國橡膠自粘帶市場運(yùn)行調(diào)查報告
- 2025年中國軸用直爪卡簧鉗行業(yè)市場發(fā)展前景及發(fā)展趨勢與投資戰(zhàn)略研究報告
- 2024年免燒磚機(jī)項目資金申請報告代可行性研究報告
- 藥品網(wǎng)絡(luò)銷售監(jiān)督管理辦法
- 葫蘆島木材加工管理辦法
- 虹口區(qū)進(jìn)口水泵管理辦法
- 2025年湖北省中考語文試卷真題(含標(biāo)準(zhǔn)答案)
- 石油化工設(shè)備設(shè)計便查手冊
- 集卡車安全操作規(guī)程
- 高考英語詞匯3500電子版
- GMP認(rèn)證資料設(shè)備管理制度
- 赫茲接觸課件完整版
- 2022年新疆公務(wù)員考試行測真題及答案解析
- GB/T 40276-2021柔巾
- 腦癌-膠質(zhì)瘤NCCN患者指南中文版2021
- 生命教育(中職教師培訓(xùn))課件
- 漢密爾頓抑郁量表HAMD
評論
0/150
提交評論