1.学校人员信息管理系统#include<iostream>#include<string>#include<fstream>#include<stdlib.h>#inlcude<windows.h>Using namespace std;Int main();Static int T=0;//用于标记老师类对象的个数Static int S=0;//用于标记学生类对象的个数Class people{//people基类Public:Int num;Char name[30];Char sex[15];Char major_or_department[50];Char date[30];Int age;People(int n,char nam[30],char s[15],char o[50],char d[30],int a){Num=n;Strcpy(name,nam);Strcpy(sex,s);Strcpy(major_or_department,o);Strcpy(date,d);Age=a;}};Class teacher:virtual public peoplePublic:Teacher(int n=0,char nam[30]=””,char s[15]=””,char o[50]=””,char d[30]=””,int a=0,char j[50]=””,double sa=0):people(n,nam,s,o,d,a),salary(sa){strcpy(job,j);}Char job[50];Double salary;Friend istream &operator>>(istream&is,teacher&tea)//重载>>运算符函数声明{Is>>tea,num;Is.getline(,30,’\n’);//使其能够读入字符串中的空格Is>>tea.sex;Is>>tea.major_or_department;Is>>tea.date;Is>>tea.age;Is>>tea.job;Is>>tea.salary;Return is;//退出函数}friend ostream &operator<<( ostream &os,teacher &tea) //重载"<<"运算符函数声明{os<<tea.num<<'\n';os<<<<'\n';os<<tea.sex<<'\n';os<<tea.major_or_department<<'\n';os<<tea.date<<'\n';os<<tea.age<<'\n';os<<tea.job<<'\n';os<<tea.salary<<'\n';return os; //退出函数}Void AddDate(){system(“cls”);Cout<<”请输入教工号:”;Cin>>num;For(int k=1;k<11;k++)If(num==k)K=11;If(k==11){Cout<<”请输入10以内的教工号”<<endl;AddDate();//添加函数;}Cout<<”请输入教师姓名:”;Cin>>name;Cout<<”请输入教师性别:”;Cin>>sex;Cout<<”请输入教师出生时间:”;Cin>>date;Cout<<”请输入教师工作系别部门:”;Cin>>major_or_department;cout<<"请输入教师年龄:";cin>>age;cout<<"请输入教师职称(如教授/副教授/讲师):";cin>>job;cout<<"请输入教师工资:";cin>>salary;try //处理教师工资合法性{if (salary<0){throw salary;}}catch(double ){Cout<<”输入有误,请重新输入”<<endl;Main();}}void DisplayData()//如何实现{cout<<"教工号"<<" "<<"姓名"<<" "<<"性别"<<" "<<"工作部门"<<" "<<"出生时间"<<" "<<"年龄"<<" "<<"职称"<<" "<<"工资"<<endl;cout<<num<<"\t"<<name<<"\t"<<sex<<"\t"<<major_or_department<<"\t"<<date<<"\t"<< age<<"\t"<<job<<"\t"<<salary<<endl;}void save(ofstream &outf)//same question{outf<<"教工号"<<" "<<"姓名"<<" "<<"性别"<<" "<<"工作部门"<<" "<<"出生时间"<<" "<<"年龄"<<" "<<"职称"<<" "<<"工资"<<endl;outf<<num<<"\t"<<name<<"\t"<<sex<<"\t"<<major_or_department<<"\t"<<date<<"\t"<< age<<"\t"<<job<<"\t"<<salary<<endl;}Void load(ifstream&inf){Int>>num>>name>>sex>>major_or_department>>date>>age>>job>>salary;}}tea[10];Template<typename Q>Q Max(Q*x,int len){Q max=x[0];For(int i=1;I<len;i++)Max=max>x[i]?max:x[i];Return i;}void TAddData()//对教师类对象的添加功能函数{tea[T].AddData();for(int i=0;i<10;i++){If(i!=T&&tea[T].num==tea[i].num){Cout<<”输入教工号重复,请重复输入!”<<endl;Main();}}Cout<<”添加记录成功!”<<endl;Tea[T].DisplayData();T++;}Void TDeleteData()//对教师类对象的删除功能函数{Int n;If(T==0)Cout<<”没有可以删除的记录!”<<endl;Else{Cout<<”请输入10以内的教工号:”;cin>>n;for(int i=0;i<T;i++)if(tea[i].num==n){For(;i<T;i++)tea[i]=tea[i+1];T--;cout<<"成功删除记录!"<<endl;}}Void TUpdateData()//对教师类对象的修改功能函数{Int n;If(T==0)Cout<<”没有可以删除的记录!”<<endl;Else{Cout<<”请输入10以内的教工号:”;Cin>>n;For(int i=0;i<T,i++)If(tea[i].num==n){Cout<<”原有的记录:”<<endl;Tea[i].DisplayData();Cout<<”请输入新的记录:”<<endl;cout<<"请输入教师职称(如教授/副教授/讲师):";cin>>tea[i].job;cout<<"请输入教师工资:";cin>>tea[i].salary;cout<<"新的记录:"<<endl;tea[i].DisplayData();}}}void TSearchData_num()//按教工号查询教师类对象{int n;cout<<"请输入10以内的教工号:";cin>>n;for(int i=0;i<T;i++)if(tea[i].num==n){tea[i].DisplayData();i=T;}if(i==T){cout<<"查询的记录不存在,请重新输入!"<<endl;TSearchData_num();}}void TSearchData_nam()//按姓名查询教师类对象{char nam_s[30];cout<<"请输入教师名字:"<<endl;cin>>nam_s;for(int j=0;j<T;j++)if(strcmp(tea[j].name,nam_s)==0){tea[j].DisplayData();j=T;}if(j==T){cout<<"查询的记录不存在,请重新输入!"<<endl;TSearchData_nam();}}void TSearchData_sex()//按性别查询教师类对象{char sex_s[15];cout<<"请输入教师性别:"<<endl;cin>>sex_s;for(int p=0;p<T;p++)if(strcmp(tea[p].sex,sex_s)==0){tea[p].DisplayData();p=T;}if(p==T){cout<<"查询的记录不存在,请重新输入!"<<endl;TSearchData_sex();}}void TFindMaxData()//对教师类对象的最高工资查询功能函数{int nu;double t[10];for(int a=0;a<T;a++)t[a]=tea[a].salary;nu=Max(t,T);tea[nu-1].DisplayData();}Void TDisplayData()//对教师类对象按教工号升序排列打印功能函数{For(int i=1;i<11;i++){for(int c=0;c<T;c++){if(tea[c].num==i){tea[c].DisplayData();}}}}Void Tsave()//对教师类对象的保存功能函数{Ofstream outf(“c:\\teacher.dat",ios::out);for(int i=0;i<T;i++)tea[i].save(outf);outf.close();cout<<"成功保存记录!"<<endl;}void Tload()//对教师类对象的读取功能函数{ifstream inf("c:\\teacher_ext.dat",ios::out);for(int i=0;i<T;i++)tea[i].load(inf);inf.close();cout<<"成功读取记录!"<<endl;cout<<"所有教师记录:"<<endl;for(i=0;i<T;i++)tea[i].DisplayData();}Class student:virtual public people{Public:Student(int n=0,char nam[30]=””,char s[15] ="",char o[50]="",char d[15]="",int a=0,int c=0,int e=0,int m=0):people(n,nam,s,o,d,a),score_chinese(c),score_english(e),score_mathematices(m){} Int score_chinese;int score_english;int score_mathematices;friend istream &operator>>(istream &is,student &stu)//重载">>"运算符函数声明{Is>>stu.num;Is.getline(,30,'\n'); //使其能够读入字符串中的空格is>>stu.sex;is>>stu.major_or_department;is>>stu.date;is>>stu.age;is>>stu.score_chinese;is>>stu.score_english;is>>stu.score_mathematices;return is; //退出函数}Friend ostream&operator<<(ostream&os.student&stu)//重载”<<”运算符函数声明{ os<<stu.num<<'\n';os<<<<'\n';os<<stu.sex<<'\n';os<<stu.major_or_department<<'\n';os<<stu.date<<'\n';os<<stu.age<<'\n';os<<stu.score_chinese<<'\n';os<<stu.score_english<<'\n';os<<stu.score_mathematices<<'\n';return os; //退出函数}void AddData(){ system("cls");cout<<"请输入学号:";cin>>num;for(int k=1;k<11;k++)if(num==k)k=11;if(k==11){cout<<"请输入10以内的学号"<<endl;AddData();}cout<<"请输入学生姓名:";cin>>name;cout<<"请输入学生性别:";cin>>sex;cout<<"请输入学生专业:";cin>>major_or_department;cout<<"请输入学生出生时间:";cin>>date;cout<<"请输入学生年龄:";cin>>age;cout<<"请输入学生语英数三科成绩:";cin>>score_chinese;cin>>score_english;cin>>score_mathematices;}VoidDisplayData(){Cout<<"学号"<<" "<<"姓名"<<" "<<"性别"<<" "<<"专业"<<" "<<"出生时间"<<" "<<"年龄"<<" "<<"语文成绩"<<" "<<"英语成绩"<<" "<<"数学成绩"<<endl;cout<<num<<"\t"<<name<<"\t"<<sex<<"\t"<<major_or_department<<"\t"<<date<<"\t"<<a ge<<"\t"<<score_chinese<<"\t"<<score_english<<"\t"<<score_mathematices<<endl;}Void save(ofstream&outf){outf<<”学号”<<”“<<”姓名” <<" "<<"性别"<<" "<<"专业"<<" "<<"出生时间"<<" "<<"年龄"<<" "<<"语文成绩"<<" "<<"英语成绩"<<" "<<"数学成绩"<<endl;outf<<num<<"\t"<<name<<"\t"<<sex<<"\t"<<major_or_department<<"\t"<<date<<"\t"<<ag e<<"\t"<<score_chinese<<"\t"<<score_english<<"\t"<<score_mathematices<<endl;}void load(ifstream &inf){Inf>>num>>name>>sex>>major_or_department>>date>>age>>score_chinese>>score_engli sh>>score_mathematices;}}stu[10];void SAddData()//对学生类对象的添加功能函数{{stu[S].AddData();for(int i=0;i<10;i++){if(i!=S&&stu[S].num==stu[i].num){cout<<"输入学号重复,请重新输入!"<<endl;main();}}cout<<"添加记录成功!"<<endl;stu[S].DisplayData();S++;}}void SDeleteData()//对学生类对象的删除功能函数{i nt n;i f(S==0)cout<<"没有可删除的记录!"<<endl;e lse{cout<<"请输入10以内的学号:";cin>>n;for(int i=0;i<S;i++)if(stu[i].num==n)for(;i<S;i++)stu[i]=stu[i+1];S--;cout<<"成功删除记录!"<<endl;}}void SUpdateData()//对学生类对象的修改功能函数{ int n;i f(S==0)cout<<"没有可删除的记录!"<<endl;e lse{cout<<"请输入10以内的学号:";c in>>n;f or(int i=0;i<S;i++)if(stu[i].num==n){cout<<"原有的记录:"<<endl;stu[i].DisplayData();cout<<"请输入新的记录:"<<endl;cout<<"请输入语英数成绩:";cin>>stu[i].score_chinese;cin>>stu[i].score_english;cin>>stu[i].score_mathematices;cout<<"新的记录:"<<endl;stu[i].DisplayData();}}}void SSearchData_num()//按学号查询学生类对象{i nt n;c out<<"请输入10以内的学号:";c in>>n;f or(int i=0;i<S;i++)if(stu[i].num==n){stu[i].DisplayData();i=S;}i f(i==S){cout<<"查询的记录不存在,请重新输入!"<<endl;SSearchData_num();}}void SSearchData_nam()//按姓名查询学生类对象{c har nam_s[15];c out<<"请输入学生名字:"<<endl;c in>>nam_s;f or(int j=0;j<S;j++)if(stu[j].name==nam_s){ stu[j].DisplayData();j=S;}i f(j==S){cout<<"查询的记录不存在,请重新输入!"<<endl;SSearchData_nam();}}void SSearchData_sex()//按性别查询学生类对象{c har sex_s[15];c out<<"请输入学生性别:"<<endl;c in>>sex_s;f or(int p=0;p<S;p++)if(stu[p].sex==sex_s){stu[p].DisplayData();p=S;}i f(p==S){cout<<"查询的记录不存在,请重新输入!"<<endl;SSearchData_sex();}}void SFindMaxData()//对学生类对象的最高英语成绩查询功能函数{i nt nu;d ouble t[10];f or(int a=0;a<S;a++)t[a]=stu[a].score_english;n u=Max(t,S);s tu[nu-1].DisplayData();}void SDisplayData()//对学生类对象按学号升序排序打印功能函数{f or(int i=1;i<11;i++){for(int c=0;c<S;c++){if(stu[c].num==i){stu[c].DisplayData();}}}}void Ssave()//对学生类对象的保存功能函数{o fstream outf("c:\\student.dat",ios::out);f or(int i=0;i<S;i++)stu[i].save(outf);o utf.close();c out<<"成功保存记录!"<<endl;}void Sload()//对学生类对象的读取功能函数{i fstream inf("c:\\student_ext.dat",ios::out);f or(int i=0;i<S;i++)stu[i].load(inf);i nf.close();c out<<"成功读取记录!"<<endl;c out<<"所有学生记录:"<<endl;f or(i=0;i<S;i++)stu[i].DisplayData();}void Showmenu(){cout<<"* * * * * * * * * * * *欢迎进入人员信息管理系统* * * * * * * * * * * *"<<endl;cout<<"* * 1.添加数据**"<<endl;cout<<"* * 2.删除数据**"<<endl;cout<<"* * 3.修改数据**"<<endl;cout<<"* * 4.查询记录**"<<endl;cout<<"* * 5.英语成绩最高学生查询**"<<endl;cout<<"* * 6.工资最高教师查询**"<<endl;cout<<"* * 7.显示全部人员记录**"<<endl;cout<<"* * 8.保存数据**"<<endl;cout<<"* * 9.读取数据**"<<endl;cout<<"* * 10.退出系统**"<<endl;cout<<"* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **"<<endl;}void Menu(){cout<<"* * * * * * * * * *请输入操作对象* * * * * * * * * * * * * * *"<<endl;cout<<"* * 1.教师* *"<<endl;cout<<"* * 2.学生* *"<<endl;cout<<"* * 3.退出* *"<<endl;cout<<"* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **"<<endl;}void Menu1(){system("cls");cout<<"* * * * * * * * * * *请输入操作对象* * * * * * * * * * * * * * *"<<endl;cout<<"* * 1.按教工号/学号查询**"<<endl;cout<<"* * 2.按姓名查询**"<<endl;cout<<"* * 3.按性别查询**"<<endl;cout<<"* * 4.退出**"<<endl;cout<<"* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **"<<endl; }Void AddData()//添加功能函数{ system(“cls”);Int i=1;While(i){Int choice;Menu();Cin>>choice;Switch(choice){Case 1:TAddData();Break;Case 2:SAddData();Break;Case 3:i=0;system("cls");break;default:cout<<"输入有误,请重新输入!"<<endl;}}}void DeleteData()//删除功能函数{ system("cls");int i=1;while(i){int choice;Menu();cin>>choice;switch(choice){case 1:TDeleteData();break;case 2:SDeleteData();break;case 3:i=0;system("cls");break;default:cout<<"输入有误,请重新输入!"<<endl;}}}VoidUpdateData()//修改功能函数{ system(“cls”);int i=1;while(i){int choice;Menu();cin>>choice;switch(choice){case 1:TUpdateData();break;case 2:SUpdateData();break;case 3:i=0;system("cls");break;default:cout<<"输入有误,请重新输入!"<<endl;}}}void SearchData()//查询功能函数{ system("cls");int i=1;while(i){int choice;Menu();cin>>choice;switch(choice){case 1:{int choice1;Menu1();cin>>choice1;switch(choice1){case 1:TSearchData_num();break;case 2:TSearchData_nam();break;case 3:TSearchData_sex();break;case 4:i=0;system("cls");break;default:cout<<"输入有误,请重新输入!"<<endl;}}break;case 2:{int choice1;Menu1();cin>>choice1;switch(choice1){case 1:SSearchData_num();break;case 2:SSearchData_nam();break;case 3:SSearchData_sex();break;case 4:i=0;system("cls");break;default:cout<<"输入有误,请重新输入!"<<endl;}}break;case 3:i=0;system("cls");break;default:cout<<"输入有误,请重新输入!"<<endl;}}}void FindMaxDataS()//英语成绩最高学生查询函数{ system("cls");SFindMaxData();}void FindMaxDataT()//工资最高教师查询函数{ system("cls");TFindMaxData();}void DisplayData()//显示全部人员记录函数{ system("cls");SDisplayData();TDisplayData();}void save()//保存功能函数{ system("cls");int i=1;while(i){int choice;Menu();cin>>choice;switch(choice){case 1:Tsave();break;case 2:Ssave();break;case 3:i=0;break;default:cout<<"输入有误,请重新输入!"<<endl;}}}void load()//读取功能函数{ system("cls");int i=1;while(i){ int choice;Menu();cin>>choice;switch(choice){case 1:Tload();break;case 2:Sload();break;case 3:i=0;break;default:cout<<"输入有误,请重新输入!"<<endl;}}}int main(){int choice;while(1){Showmenu();cin>>choice;switch(choice){case 1://添加AddData();break;case 2://删除DeleteData();break;case 3://修改UpdateData();break;case 4://查询SearchData();break;case 5://英语成绩最高学生查询FindMaxDataS();break;case 6://工资最高教师查询FindMaxDataT();break;case 7://显示全部人员记录DisplayData();break;case 8://保存数据save();break;case 9://读取数据load();break;case 10:exit(1);default:cout<<"输入有误,请重新输入!"<<endl;}}return 0;}2.进行集合的并、差和交运算#include<iostream>using namespace std;const int MAX=100;class set{public:set();void input(int d);int length();int getd(int i);void disp();set operator+(set s1);set operator-(set s1);set operator*(set s1);set operator=(set s1); protected:int len;int s[MAX];};set::set(){len=0;}void set::input(int d){len=d;cout<<"输入集合元素"<<d<<"个:"; for(int i=0;i<d;i++)cin>>s[i];}int set::length(){int n=0;while(s[n]!='\0'){n++;}return n;}int set::getd(int i){return 0;}void set::disp(){for (int i=0;i<len;i++)cout<<s[i]<<" ";}set set::operator+(set s1) //并运算{for(int i=0;i<len;i++){for(int j=0;j<s1.len;j++) //在s1.s[]中选出不相同的{if(s[i]==s1.s[j]) //选出相同的元素删掉得到s1.s与s不同的元素{for (;j<s1.len;j++)s1.s[j]=s1.s[j+1];--s1.len;}}}for(int j=0;j<s1.len;j++) // 将s1.s[]中不相同的加在s[]后面{s[len]=s1.s[j];len++;}s[len+s1.len]='\0';return *this;}set set::operator-(set s1) //差运算{int t;for(int i=0; i<s1.len;i++){for(int j=0;j<len;j++){if(s1.s[i]==s[j]) //选出s与s1.s中相同的元素并且删除掉{t=j;for(;t<len;t++)s[t]=s[t+1];--len;}}}return *this;}set set::operator*(set s1) // 交运算{int m[MAX];int l=0;for(int i=0;i<s1.len;i++){for(int j=0;j<len;j++) // 选出相同的元素{if(s1.s[i]==s[j]){m[l]=s[j];l++;}}}for(i=0;i<l;i++)s[i]=m[i];s[l]='\0';len=l;return *this;}set set::operator=(set s1){for(int i=0;i<s1.length();i++)s[i]=s1.s[i];len=s1.len;return *this;}int main(){int n;set C;set A;cout<<"建立含有几个元素的集合:"; cin>>n;A.input(n);set D=A;set B;cout<<"建立含有几个元素的集合:"; cin>>n;B.input(n);cout<<endl;cout<<"两集合的并集(A+B)为:";C=A+B;C.disp();cout<<endl;A=D;cout<<"两集合的差集(A-B)为:"; C=A-B;C.disp();cout<<endl;A=D;cout<<"两集合的交集(A*B)为:"; C=A*B;C.disp();cout<<endl;return 0;}3. 九九乘法表#include<iostream>//修改后#include<iomanip>using namespace std;int main(){int i,j;cout<<"*"<<" ";for(i=1;i<=9;i++)cout<<i<<" ";cout<<endl;for(i=1;i<=9;i++){cout<<i<<" ";for(j=1;j<=i;j++){cout<<i*j<<" ";}cout<<endl;}return 0;}。