第一篇:c++课程设计:教务管理系统源代码
#include
string name;};class Student:public Person { public:
Student(string n,int num,string ss):Person(n),number(num),address(add),str1(ss){}
virtual void show();
void input_stu();
void display_stu();
void display_qu();
~Student(){} protected:
string str1;
int number;
string address;};void Student::show(){ cout<<“向老师提出的问题是:”;cin>>str1;}
void Student::display_qu(){ cout< void Student::input_stu(){ cin>>Student::name;cin>>Student::number;cin>>Student::address;} void Student::display_stu(){ add,string cout<<“姓名:”< Teacher(string n,string sub,string sdf):Person(n),subject(sub),str2(sdf){} virtual void show(); void input_t(); void display_t(); void display_an(); ~Teacher(){} protected: string subject; string str2;};void Teacher::display_an(){ cout< void Teacher::show(){ cout<<“我的回答是:”;cin>>str2;} void Teacher::input_t(){ cin>>Teacher::name;cin>>Teacher::subject;} void Teacher::display_t(){ cout<<“姓名:”< Admin(string n,int tel,string ssfs):Person(n),telphone(tel),str3(ssfs){} virtual void show(); void input_ad(); void display_ad(); void display_gg(); ~Admin(){} protected: int telphone; string str3;};void Admin::display_gg(){ cout<<“公告:”;cout< void Admin::show(){ cout<<“公告是:”;cin>>str3;} void Admin::input_ad(){ cin>>Admin::name;cin>>Admin::telphone;} void Admin::display_ad(){ cout<<“姓名是:”< int main(){ int z,h,m;z=0;h=0;m=0; Student stu(“guochun”,20150311,“qlu”,“sdss”); Teacher tea(“cuiyu”,“math”,“dsdf”); Admin ad(“steve jobs”,178641,“sdfs”); while(1) { int x; cout<<“*******************”< cout<<“1.学生”< cout<<“2.教师”< cout<<“3.管理员”< cout<<“*******************”< cout<<“选择你的身份”< cin>>x; if(x<=0||x>3) cout<<“输入错误!”< else { switch(x) { case 1: cout<<“请选择你要干什么”< case 1:stu.display_stu();break; case 2:stu.input_stu(); } cout<<“修改后的个人信息为:”< { stu.Student::show(); z=1;} break; } break; case 2: cout<<“请选择你要干什么”< cout<<“学生有问题提问”< ad.display_gg();} cout<<“___________________”< cout<<“发生错误!”;else { switch(q) { case 1:tea.display_t();break; case 2:tea.input_t(); cout<<“修改后的个人信息为:”< tea.display_t();break; case 3: { if(z==1) { cout<<“学生的问题是:”; stu.display_qu(); tea.Teacher::show(); h=1; } } break; } } break; case 3: cout<<“请选择你要干什么”< cout<<“___________________”< cout<<“1.显示个人信息”< cout<<“发生错误!”; else { switch(l) { case 1:ad.display_ad();break; case 2:ad.input_ad(); cout<<“修改后的个人信息为:”< ad.display_ad();break; case 3: { ad.Admin::show(); m=1; } break; } } break; } } } return 0;} #include void menu(University uni);//菜单函数声明 class Student//学生类 { public: string name;int age;string sex;int number;string major; public: void disp_stu(); friend void file_in(University &uni); friend void file_out(University uni);};void Student::disp_stu(){ } class Institute//学院类 { public: string name;cout<<“学生姓名:”< public: void add_stu(); //添加学生 bool delete_stu(int i); // 删除学生 bool modefy_stu(int i); //修改学生信息 void disp_ins_1(); // 显示本院学生信息 friend void file_in(University &uni); friend void file_out(University uni);};void Institute::add_stu(){ } Student *p=new Student;cout<<“学生名字:”;cin>>(*p).name;cout<<“学生年龄:”;cin>>(*p).age;cout<<“学生性别:”;cin>>(*p).sex;cout<<“学生学号:”;cin>>(*p).number;cout<<“学生专业:”;cin>>(*p).major;head.Add(p);//在链表末尾增加一个节点 bool Institute::delete_stu(int i){ } head.Remove(i);//删除链表指定位置节点 return true;bool Institute::modefy_stu(int i){ Student *p=new Student;cout<<“学生名字:”;cin>>(*p).name;cout<<“学生年龄:”;cin>>(*p).age;cout<<“学生性别:”;cin>>(*p).sex;cout<<“学生学号:”;cin>>(*p).number;cout<<“学生专业:”;cin>>(*p).major;head.Remove(i);//删除链表指定位置节点 head.Insert(i,p);//在链表指定位置插入一个新节点 return true;} void Institute::disp_ins_1(){ } class University//学校类 { public: string name;int age;string addr;List void design_stu();//学生信息设置 int i;Node cout<<“学院名字:”< } cout<<“-------”<pData->disp_stu();q=q->pNext; void add_ins(); //添加学院 bool delete_ins(int n); // 删除学院 void design_cqut(); //设置学校信息 bool modefy_cqut(); //修改学校信息 void disp_cqut(); //显示学校信息 void design_ins(); //学院信息设置 bool modefy_ins(int n); //修改学院 void disp_ins(); //显示学院信息 void search_menu();void search_name(string n);//姓名 void search(string n);//性别//函数重载 void search(int n);//学号 bool search_age(int n);//年龄 friend void file_in(University &uni);};friend void file_out(University uni); void University::design_stu(){ int i,m,j;int n;cout<<“ ★★★★★★学生信息设置★★★★★★ ”< { disp_ins(); cout< cout<<“输入学生所在学院序号:”< cin>>m;system(“cls”);//清屏 head.pCurrent=head.pHead;//当前指针指向双向链表头指针 for(j=1;j { } } head.pCurrent=head.pCurrent->pNext;//当前指针指后移 cout<<“输入要添加的学生信息:”;head.pCurrent->pData->add_stu();cout<<“按任意键返回上一级菜单:”< disp_ins(); cout< cout<<“输入学生所在学院序号:”< cin>>m;system(“cls”);//清屏 head.pCurrent=head.pHead;//当前指针指向双向链表头指针 for(j=1;j { head.pCurrent=head.pCurrent->pNext;//当前指针指后移 } } head.pCurrent->pData->disp_ins_1();cout< { disp_ins(); cout< cout<<“输入学生所在学院序号:”< cin>>m;system(“cls”);//清屏 head.pCurrent=head.pHead;//当前指针指向双向链表头指针 for(j=1;j { } } head.pCurrent=head.pCurrent->pNext;//当前指针指后移 head.pCurrent->pData->disp_ins_1();cout< } cin>>n;head.pCurrent->pData->modefy_stu(n);cout<<“按任意键返回上一级菜单:”< void University::add_ins(){ } bool University::delete_ins(int n){ } bool University::modefy_ins(int n){ Institute *p=new Institute;cout<<“学院名字:”;cin>>(*p).name;head.Remove(n);//删除链表指定位置节点 head.Insert(n,p);//在指定位置插入节点信息 return true;head.Remove(n);//删除链表指定位置节点 return true;Institute *p=new Institute;cout<<“学院名字:”;cin>>(*p).name;head.Add(p);//在链表末尾增加一个节点 } void University::disp_ins(){ int i;Node for(i=1;i<=head.size;i++){ cout<pData->name< } void University::design_ins(){ int i;int j;cout<<“ ★★★★★★学院信息设置★★★★★★ ”< cout< { } disp_ins();cout<<“按任意键返回上一级菜单:”< disp_ins(); add_ins(); cout<<“按任意键返回上一级菜单:”< getch();system(“cls”);//清屏 design_ins(); break;} case 3: { } disp_ins();cout<<“输入删除学院序号:”;cin>>j;delete_ins(j);cout<<“按任意键返回上一级菜单:”< disp_ins();cout<<“输入修改学院序号:”;cin>>j;modefy_ins(j);cout<<“按任意键返回上一级菜单:”< } case 5:menu(*this);break;} } bool University::modefy_cqut(){ cout<<“学校名字:”;cin>>name;cout<<“创建年代:”;cin>>age;cout<<“学校地址:”;cin>>addr;return true;} void University::design_cqut(){ int i; University uni;cout<<“ ★★★★★★学校信息设置★★★★★★ cout< switch(i){ case 1: { disp_cqut(); cout<<”按任意键返回上一级菜单:“< getch();system(”cls“);//清屏 design_cqut(); break; } case 2: { modefy_cqut(); cout<<”按任意键返回上一级菜单:“< getch();system(”cls“);//清屏 design_cqut();break;”< } } } case 3:menu(uni);break; void University::disp_cqut(){ cout<<“学校有关信息为:”< } void University::search_name(string n){ int i,j,m=0;head.pCurrent=head.pHead;//当前指针指向学院节点头指针 for(i=0;i for(j=0;j { if(n==head.pCurrent->pData->head.pCurrent->pData->name) { } head.pCurrent->pData->head.pCurrent->pData->disp_stu();m++;head.pCurrent->pData->head.pCurrent=head.pCurrent->pData->head.pCurrent->pNext;//学生当前指针后移 } bool University::search_age(int n){ int i,j,m=0;head.pCurrent=head.pHead;for(i=0;i } cout<<“有”< } head.pCurrent->pData->head.pCurrent=head.pCurrent->pData->head.pHead;for(j=0;j } head.pCurrent->pData->head.pCurrent->pData->disp_stu();m++;head.pCurrent->pData->head.pCurrent=head.pCurrent->pData->head.pCurrent->pNext;} head.pCurrent=head.pCurrent->pNext;} cout<<“有”< void University::search(string n){ } int i,j,m=0;head.pCurrent=head.pHead;for(i=0;i for(j=0;j if(n==head.pCurrent->pData->head.pCurrent->pData->sex){ head.pCurrent->pData->head.pCurrent->pData->disp_stu();} m++; head.pCurrent->pData->head.pCurrent=head.pCurrent->pData->head.pCurrent->pNext; } cout<<“有”< int i,j,m=0;head.pCurrent=head.pHead;for(i=0;i head.pCurrent->pData->head.pCurrent=head.pCurrent->pData->head.pHead; for(j=0;j { if(n==head.pCurrent->pData->head.pCurrent->pData->number) { head.pCurrent->pData->head.pCurrent->pData->disp_stu(); m++; } head.pCurrent->pData->head.pCurrent=head.pCurrent->pData->head.pCurrent->pNext; } head.pCurrent=head.pCurrent->pNext;} cout<<“有”< /****************************************信息查询菜***********************************************/ void University::search_menu(){ int i;cout<<“ ★★★★★信息查询显示★★★★★”< switch(i){ case 1: { 单 disp_ins(); cout<<“按任意键返回上一级菜单:”< { } head.pCurrent=head.pHead;//当前指针指向学院节点头指针 for(i=0;i } head.pCurrent->pData->disp_ins_1();head.pCurrent=head.pCurrent->pNext;cout<<“按任意键返回上一级菜单:”< } int j;disp_ins();cout<<“请输入学生所在学院序号:”;cin>>i;system(“cls”);//清屏 head.pCurrent=head.pHead;for(j=1;jpNext;head.pCurrent->pData->disp_ins_1();cout<<“按任意键返回上一级菜单:”< case 4: { string n;cout<<“输入要查询的姓名:”;cin>>n;system(“cls”);//清屏 search_name(n); } cout<<“按任意键返回上一级菜单:”< { } int n1;cout<<“输入要查询的年龄:”;cin>>n1;search_age(n1);cout<<“按任意键返回上一级菜单:”< system(“cls”);//清屏 case 6: { } string n;cout<<“输入要查询的性别:”;cin>>n;system(“cls”);//清屏 search(n);cout<<“按任意键返回上一级菜单:”< } int n;cout<<“输入要查询的学号:”;cin>>n;system(“cls”);//清屏 search(n);cout<<“按任意键返回上一级菜单:”< menu(*this); } } } break;/**********************************************************************/ { int i,j;ifstream inf(“cqutData.txt”,ios::in);inf>>uni.name;inf>>uni.age;inf>>uni.addr;inf>>uni.head.size;//学院个数 for(i=0;i 导出文件数据void file_in(University &uni) Node else uni.head.pEnd->pNext=m;//把节点m赋给下一个学院信息节点 m->pPrev=uni.head.pEnd;//节点m指向学院信息的尾节点 uni.head.pCurrent=uni.head.pEnd=m;//学院信息的尾节点始终指向m节点 inf>>uni.head.pCurrent->pData->head.size;//学生个数 for(j=0;j Student *q=new Student;inf>>q->name;inf>>q->age;inf>>q->sex;inf>>q->number;inf>>q->major; Node n->pPrev=uni.head.pCurrent->pData->head.pEnd; uni.head.pCurrent->pData->head.pCurrent=uni.head.pCurrent->pData->head.pEnd=n;//学生信息的尾节点始终指向n节点 } } } /************************************************************************************/ void file_out(University uni){ ofstream ouf(“cqutData.txt”,ios::out);int i,j;ouf< 导入文件数据ouf< uni.head.pCurrent=uni.head.pHead;//当前指针指向学院节点头指针 for(i=0;i ouf< ouf< uni.head.pCurrent->pData->head.pCurrent=uni.head.pCurrent->pData->head.pHead;//当前指针指向学生节点头指针 for(j=0;j ouf< uni.head.pCurrent->pData->head.pCurrent=uni.head.pCurrent->pData->head.pCurrent->pNext;//学生当前指针后移 } } } uni.head.pCurrent=uni.head.pCurrent->pNext;//学院当前指针后移 /************************退出系统菜单****************************/ void exit(University uni){ } int i;cout<<“是否保存修改内容:”< { } file_out(uni);exit(0);break;case 2:{exit(0);break;} case 3: { menu(uni);break;} case 4: { file_out(uni); } } menu(uni);break; /***************************************************************************************/ void menu(University uni){ system(“cls”);/*清屏*/ int i;cout< 主菜单 cout<<“★★★★★★★★★★★★★主菜单★★★★★★★★★★★★★”< cout< cout< cout< } int main(){ University u; } file_in(u);menu(u);return 0;switch(i){ case 1:uni.design_cqut();break;case 2:uni.design_ins();break;case 3:uni.design_stu();break; case 4:uni.search_menu();break; case 5:exit(uni);break;} 教职工信息管理系统源码 #include #define maxsize 100 fstream iofile;//文件指针 class Time //时间类 { public: int year; int month; int day;}; class Telem //个人信息 { public: char name[20]; char sex[10]; Time birthtime;//组合Time类 char num[20]; char wage[20]; Time worktime; int year; char department[20]; friend istream& operator>>(istream& input,Telem& T); friend ostream& operator<<(ostream& output,Telem& T); friend int operator-(Time & t1,Time & t2);}; class People:virtual public Telem //雇员类 { public: People(); virtual void AddF()=0;//添加 virtual void Addall()=0; virtual void Add()=0; virtual void Display();//输出数组的内容 virtual void Displaypart(char p[]); virtual void Findname(char n[]); virtual void Findyear(int); virtual void Del(char n[])=0; virtual void Del(int);protected: Telem data[maxsize]; Time now; int length;}; class Teacher:virtual public People //派生虚基类 { public: virtual void AddF(); virtual void Addall(); virtual void Add(); virtual void Display(); virtual void Del(int i); virtual void Del(char n[]);}; class worker:virtual public People //派生虚基类 { public: virtual void AddF(); virtual void Addall(); virtual void Add(); virtual void Display(); virtual void Del(int i); virtual void Del(char n[]);}; People::People()//系统自动生成的构造函数 { length=0; now.year=2010; now.month=7; now.day=6;} void People::Display()//引用 { int i; for(i=0;i cout< void People::Displaypart(char p[])//引用数组 { int i,c; for(i=0;i if(strcmp(data[i].wage,p)==0) { cout<<“输出选择姓名1 性别2 编号3 工资4 出生日期5 工作时间6 年龄7 系别8 退出选择9”< while(cin>>c) { switch(c) { case 1: cout<<“姓名:”< case 2: cout<<“性别:”< case 3: cout<<“编号:”< case 4: cout<<“工资:”< case 5: cout<<“出生日期:”< case 6: cout<<“工作时间:”< case 7: cout<<“年龄:”< case 8: cout<<“系别:”< case 9: goto loop; default:cout<<“操作错误......”< } } loop:; } } void People::Findname(char n[])//引用 { int i; for(i=0;i if(strcmp(data[i].name,n)==0)//对象引用 cout< void People::Findyear(int y){ int i; for(i=0;i if(data[i].year==y) cout< void People::Del(int i){ int j; if(i<1||i>length) cout<<“不存在第”< for(j=i;j data[j-1]=data[j]; length--;} void worker::AddF(){ int flag=0; iofile.open(“worker_information.txt”,ios::in|ios::binary);//文件的打开与关闭 while(iofile.seekg(ios::cur)) { iofile.seekg(length*sizeof(data[length]),ios::beg); iofile.read((char*)&data[length],sizeof(data[length]));//文件的随机访问 length++; if(length==maxsize) { flag=1; goto loop; } } People::Del(length); cout<<“添加人员信息成功......”< loop: if(1==flag) cout<<“人员信息储存空间已满......”< iofile.close();} void worker::Addall(){ char ans; int flag=0; iofile.open(“worker_information.txt”,ios::out|ios::binary); do { cin>>data[length]; data[length].year=now-data[length].birthtime; iofile.write((char*)&data[length],sizeof(data[length])); cout<<“添加人员信息成功......”< length++; if(length==maxsize) { flag=1; goto loop; } cout<<“contine(Y|N)?”; cin>>ans; }while('y'==ans||'Y'==ans);loop: if(1==flag) cout<<“人员信息储存空间已满......”< iofile.close();} void worker::Add(){ int flag=0; iofile.open(“worker_information.txt”,ios::app|ios::out|ios::binary); if(length==maxsize) { flag=1; goto loop; } cin>>data[length]; data[length].year=now-data[length].birthtime; iofile.write((char*)&data[length],sizeof(data[length])); cout<<“添加人员信息成功......”< length++; loop: if(1==flag) cout<<“人员信息储存空间已满......”< iofile.close();} void worker::Display(){ cout<<“ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆工人信息 ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆”< if(0==length) cout<<“无......”< int i; for(i=0;i cout< int i,j,k; for(i=0;i if(strcmp(data[i].name,n)==0){ k=i+1;break;} if(k<1) cout<<“不存在姓名”< for(j=k;j data[j-1]=data[j]; length--; cout<<“删除人员信息成功......”< void worker::Del(int i){ int j; if(i<1||i>length) cout<<“不存在第”< for(j=i;j data[j-1]=data[j]; length--; cout<<“删除成功......”< } void Teacher::AddF(){ int flag=0; iofile.open(“Teacher_information.txt”,ios::in|ios::binary); while(iofile.seekg(sizeof(data[length]),ios::cur)) { if(iofile.seekg(length*sizeof(data[length]),ios::beg)) iofile.read((char*)&data[length],sizeof(data[length])); else break; length++; if(length==maxsize) { flag=1; goto loop; } } People::Del(length); cout<<“添加人员信息成功......”< if(1==flag) cout<<“人员信息储存空间已满......”< iofile.close();} void Teacher::Addall(){ char ans; int flag=0; iofile.open(“Teacher_information.txt”,ios::in|ios::out|ios::binary); do { cin>>data[length]; data[length].year=now-data[length].birthtime; iofile.write((char*)&data[length],sizeof(data[length])); cout<<“添加人员信息成功......”< length++; if(length==maxsize) { flag=1; goto loop; } cout<<“contine(Y|N)?”; cin>>ans; }while('y'==ans||'Y'==ans);loop: if(1==flag) cout<<“人员信息储存空间已满......”< iofile.close();} void Teacher::Add(){ int flag=0; iofile.open(“Teacher_information.txt”,ios::app|ios::out|ios::binary); if(length==maxsize) { flag=1; goto loop; } cin>>data[length]; data[length].year=now-data[length].birthtime; iofile.write((char*)&data[length],sizeof(data[length])); cout<<“添加人员信息成功......”< length++;loop: if(1==flag) cout<<“人员信息储存空间已满......”< iofile.close();} void Teacher::Display(){ cout<<“ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆教师信息 ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆”< if(0==length) cout<<“无......”< int i; for(i=0;i cout< void Teacher::Del(char n[]){ int i,j,k; for(i=0;i if(strcmp(data[i].name,n)==0) { k=i+1;break; } if(k<1)cout<<“不存在姓名”< for(j=k;j data[j-1]=data[j]; length--; cout<<“删除人员信息成功......”< void Teacher::Del(int i){ int j; if(i<1||i>length) cout<<“不存在第”< for(j=i;j data[j-1]=data[j]; length--; cout<<“删除成功......”< istream& operator>>(istream& input,Telem& T){ int y,m,d; cout<<“请输入姓名(以*结尾):”< input.getline(T.name,20,'*'); cout<<“请输入性别(以*结尾 男或女):”< input.getline(T.sex,10,'*'); cout<<“编号(以*结尾):”< input.getline(T.num,20,'*'); cout<<“工资(以*结尾):”< input.getline(T.wage,20,'*'); cout<<“请输入出生日期:”< input>>y>>m>>d; T.birthtime.year=(y>=1900&&y<=2100)?y:1900; T.birthtime.month=(m>=1&&m<=12)?m:1; T.birthtime.day=(d>=1&&d<=31)?d:1; cout<<“请输入系别(以*结尾):”< input.getline(T.department,20,'*'); cout<<“参加工作时间:”< input>>y>>m>>d; T.worktime.year=(y>=1900&&y<=2100)?y:1900; T.worktime.month=(m>=1&&m<=12)?m:1; T.worktime.day=(d>=1&&d<=31)?d:1; return input;} ostream& operator<<(ostream& output,Telem& T){ cout<<“姓名:”; output< cout<<“性别:”; output< cout<<“编号:”; output< cout<<“工资:”; output< cout<<“出生日期:”; output< cout<<“系别:”; output< cout<<“参加工作时间:”; output< cout<<“年龄:”; output< return output;} int operator-(Time & t1,Time & t2){ return t1.year-t2.year;} void Showmenu(){ cout< cout<<“ 欢 迎 进 入 教 职 工 信 息 管 理 系 统”< cout<<“ 2010 年7月7日发布”<<“ 版权所有: swa”< cout<<“ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★人员信息管理系统★ ☆ ★ ☆ ★ ☆ ★ ☆ ★”<第二篇:C++课程设计(教务管理系统)
第三篇:C++课程设计 教职工信息管理系统源代码